ShellExecute(NULL,_T("open"),_T("cmd.exe"),_T("ipconfig /all"),NULL,SW_SHOWNORMAL);
Sleep(500);
CWnd* pWnd=CWnd::FindWindow(_T("ConsoleWindowClass"),NULL);
if(NULL != pWnd)
{
::SetWindowPos(pWnd->GetSafeHwnd(),HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
今天做一個功能模塊,使用ffmpeg將網絡視頻流截圖,每秒截取一張jpeg圖片:
頭文件:
#include <shellapi.h>
- ShellExecute(NULL,_T("open"),_T("cmd.exe"),_T("/c C:\\gifMake\\ffmpeg.exe -i rtmp://s2pchzxmtymn2k.cloudfront.net/cfx/st/mp4:sintel.mp4 -f image2 -r 1 -t 10 -s 220*220 C:\\gifMake\\i%d.jpeg"),NULL,SW_HIDE);
ShellExecute(NULL,_T("open"),_T("cmd.exe"),_T("/c C:\\gifMake\\ffmpeg.exe -i rtmp://s2pchzxmtymn2k.cloudfront.net/cfx/st/mp4:sintel.mp4 -f image2 -r 1 -t 10 -s 220*220 C:\\gifMake\\i%d.jpeg"),NULL,SW_HIDE);
再用convert工具將圖片轉換成一張gif圖片:
- ShellExecute(NULL,_T("open"),_T("cmd.exe"),_T("/c C:\\gifMake\\convert.exe -delay 100 C:\\gifMake\\i1.jpeg C:\\gifMake\\i2.jpeg C:\\gifMake\\i3.jpeg C:\\gifMake\\i4.jpeg C:\\gifMake\\i5.jpeg C:\\gifMake\\i6.jpeg C:\\gifMake\\i7.jpeg C:\\gifMake\\i8.jpeg -loop 5 C:\\gifMake\\i.gif"),NULL,SW_HIDE);
ShellExecute(NULL,_T("open"),_T("cmd.exe"),_T("/c C:\\gifMake\\convert.exe -delay 100 C:\\gifMake\\i1.jpeg C:\\gifMake\\i2.jpeg C:\\gifMake\\i3.jpeg C:\\gifMake\\i4.jpeg C:\\gifMake\\i5.jpeg C:\\gifMake\\i6.jpeg C:\\gifMake\\i7.jpeg C:\\gifMake\\i8.jpeg -loop 5 C:\\gifMake\\i.gif"),NULL,SW_HIDE);
最後將之前生成的jpeg圖片刪除:
- ShellExecute(NULL,_T("open"),_T("cmd.exe"),_T("/c del C:\\gifMake\\*.jpeg"),NULL,SW_HIDE);
ShellExecute(NULL,_T("open"),_T("cmd.exe"),_T("/c del C:\\gifMake\\*.jpeg"),NULL,SW_HIDE);
以上這樣會出現一個問題,
三條cmd命令幾乎同時進行,而第一個cmd命令截圖需要花費一些時間,導致第二條cmd命令不能順利進行,所以嘗試在第一條cmd後面進行sleep(5000),但是問題又出現了,這5秒鐘會使得程序死了5秒,因此考慮到用線程去執行cmd,麻煩!
突然有想到是不是可以像bat文件那樣上面三個cmd命令能夠順序執行,試了多次都失敗了,因爲不知道該怎麼寫。
通過網上查資料,百度上名爲734121932韓的哥們提出可以使用“&”符號進行兩條cmd命令的連接,才使得我的想法實現,謝謝這位仁兄。
ShellExecute(NULL,_T("open"),_T("cmd.exe"),_T("/c C:\\gifMake\\ffmpeg.exe -i rtmp://s2pchzxmtymn2k.cloudfront.net/cfx/st/mp4:sintel.mp4 -f image2 -r 1 -t 10 -s 220*220 C:\\gifMake\\i%d.jpeg & C:\\gifMake\\convert.exe -delay 100 C:\\gifMake\\i1.jpeg C:\\gifMake\\i2.jpeg C:\\gifMake\\i3.jpeg C:\\gifMake\\i4.jpeg C:\\gifMake\\i5.jpeg C:\\gifMake\\i6.jpeg C:\\gifMake\\i7.jpeg C:\\gifMake\\i8.jpeg -loop 5 C:\\gifMake\\i.gif & del C:\\gifMake\\*.jpeg"),NULL,SW_HIDE);
這條命令則成功的實現了我的操作。