如何隱藏system函式的視窗

2021-08-25 07:09:30 字數 1732 閱讀 5090

原]如何隱藏system函式的視窗

| 刪除

最先想到的是system函式,因為可以通過system(const char*)函式啟動另外乙個程式,其實這麼解決已經很好了,但是有乙個小問題,就是每次執行system函式的時候,都會彈出dos視窗(命令列嘛~~~),有沒有什麼方法能夠讓我呼叫的程式在後台執行呢?

1. winexec(lpcstr, uint)函式

其第乙個引數相當於system函式的引數,第二個引數可以設定視窗是否顯示,sw_hide這個巨集表示隱藏視窗,例如:

winexec(cmd.c_str(),sw_hide);//cmd(string型別)中為我們要呼叫的程式名及其引數, 如 「dir *.exe 」

但是這個有乙個問題,這個函式建立完這個程序後就返回了,也就是說它返回後,該程序不一定已經結束,這個就有點和system不一樣了,在這裡我無法使用這個函式了~~~

2.shellexecuteex(shellexecuteinfo*)函式

其引數是乙個結構體,具體作用還是類似於system的引數,使用例子:

shellexecuteinfo shexecinfo = ;

shexecinfo.cbsize = sizeof(shellexecuteinfo);

shexecinfo.fmask = see_mask_nocloseprocess;

shexecinfo.hwnd = null;

shexecinfo.lpverb = null;

shexecinfo.lpfile = cmd.c_str();//呼叫的程式名

shexecinfo.lpparameters = par.c_str();//呼叫程式的命令列引數

shexecinfo.lpdirectory = null;

shexecinfo.nshow = sw_hide;//視窗狀態為隱藏

shellexecuteex(&shexecinfo);

但是這個還是有問題,同1中一樣,無法確定該程序是否結束~~~

waitforsingleobject(handle,dword)函式

例子:在2的**下加一行:waitforsingleobject(shexecinfo.hprocess,infinite);等到該程序結束

因此,我們完全可以把上述**片段封裝成乙個小的函式,來代替system函式

void mysystem(const string& cmd, const string& par, int nshow) ;

shexecinfo.cbsize = sizeof(shellexecuteinfo);

shexecinfo.fmask = see_mask_nocloseprocess;

shexecinfo.hwnd = null;

shexecinfo.lpverb = null;

shexecinfo.lpfile = cmd.c_str();//呼叫的程式名

shexecinfo.lpparameters = par.c_str();//呼叫程式的命令列引數

shexecinfo.lpdirectory = null;

shexecinfo.nshow = sw_hide;//視窗狀態為隱藏

shellexecuteex(&shexecinfo);

waitforsingleobject(shexecinfo.hprocess,infinite);等到該程序結束

} 開啟**

取消 來自:

windows 下隱藏 system 函式彈窗

下面的程式是解決windows 下面呼叫 system 函式的時候,會有視窗彈出的問題 include brief 普通字元轉寬字元 param lpcszstr 普通字元 param lpwszstr 轉換後的寬字元 param dwsize 儲存寬字元的緩衝區大小 return bool mby...

system函式與Sleep函式 視窗頁面設計

system函式位於標頭檔案stdlib.h中。常見的函式 system pause 可以使螢幕凍結。system cls 可以實現清屏操作。呼叫color函式可以改變控制台的前景色和背景,具體引數在下面說明。system color 0a 其中color後面的0是背景色代號 就是原來的視窗顏色 a...

呼叫System命令時隱藏控制台視窗

第一種 shellexecute函式原型及引數含義如下 shellexecute hwnd hwnd,父視窗控制代碼 lpcstr lpoperation,操作型別 lpcstr lpfile,要進行操作的檔案或路徑 lpcstr lpparameters,當lpoperation為 explore...