windows程序的建立方法

2022-09-06 20:06:12 字數 3063 閱讀 1861

1.winexec(lpcstr lpcmdline,uint ucmdshow)

>>引數:

lpcmdline:指定程式的相對路徑或絕對路徑,命令列引數

ucmdshow:指定視窗的顯示方式

>>視窗的顯示方式:

sw_show:顯示視窗

sw_maximize:最大化視窗

sw_minimize:最小化視窗

sw_normal:正常顯示視窗

sw_hide:隱藏視窗

>>例子

uint result = winexec("notepad",sw_show); //開啟記事本程式

if(result < 32)

2.shellexecute()、shellexecuteex()

>>shellexecute函式原形:

hinstance shellexecute(hwnd hwnd , lpctstr lpoperation , lpctstr lpfile , lpctstr lpparameters , lpctstr lpdirectory , int nshowcmd );

>>引數:

hwnd:指定父視窗控制代碼

lpoperation:指定操作方式,"open","pr.int","explore"分別表示開啟,列印,搜尋,如果為null則預設是開啟方式

lpfile:指定檔案或程式名

lpparameters:傳遞的引數

lpdirectory:預設目錄

nshowcmd:顯示方式

函式返回值如果大於32則表示執行成功,否則失敗

>>例子:

wchar_t* operation = l"open"; 

wchar_t* file = l"notepad"; 

wchar_t* para = l"c:\\a.txt"; 

wchar_t* dirc = l""; 

hinstance result = shellexecute(null , operation , file , para , dirc , sw_show);

>>shellexecuteex函式原形:

bool winapi shellexecuteex( lpshellexecuteinfo lpexecinfo );

>>引數:

lpexecinfo:這個引數是shellexecuteinfo

結構體的位址,shellexecuteinfo結構體定義了啟動程式所需要的所有資訊

結構體的定義:

typedef struct _shellexecuteinfo

dummyunionname;

handle hprocess;                        //用於進行return操作的成員

}shellexecuteinfo , *lpshellexecuteinfo;

該函式返回值為布林值,當返回true表示執行成功,返回false表示執行失敗;

>>例子

3.createprocess()

使用createprocess()函式是最正規、最強大的程序建立方法

>>函式原形:

lpsecurity_attributes lpthreadattributes , bool binherithandles , dword dwcreationflags , lpvoid lpenvironment , 

lpctstr lpcurrentdirectory , lpstartupinfo lpstartuoinfo , lpprocess_infomation lpprocessinfomation );

>>引數:

lpcommandline                //要傳遞給可執行程式的引數

lpprocessattributes            //程序安全性,預設為null

lpthreadattributes             //執行緒安全性,預設為null

binherithandles                 //控制代碼是否可以被新程序繼承

dwcreationflags                 //新程序的優先順序以及其他建立標誌

lpenvironment                     //新程序使用的環境變數

lpcurrentdirectory                //新程序使用的當前目錄

lpstartuoinfo                       //指定新程序視窗位置,大小等資訊

lpprocessinfomation            //傳出引數,返回程序資訊

>>例子:

startupinfo si = ; 

si.cb = sizeof(si); 

si.dwflags = startf_useshowwindow; 

si.wshowwindow = sw_show; 

process_information pi ; 

bool flag = createprocess(l"c:\\windows\\notepad.exe" , null , null , null , false , create_new_console , null , null , &si , &pi);

4.system()

system函式用於在c語言環境下執行各種控制台命令,也可以用它建立乙個程序

>>函式原形:

int system( const char* command );

其中只有乙個引數,就是要執行的控制台命令字串,返回值是控制台執行後的返回值。使用它需要包含process.h標頭檔案

>>例子:

int result = system("start notepad");

windows下安全的建立子程序

include int main process information pi tchar szcommandline text c o yes seterrormode sem nogpfaulterrorbox bool bcreateret createprocess null,szcomma...

windows程序通訊方法總結

匿名管道是單機上實現子程序標準i o重定向的有效方法,它不能在網上使用,也不能用於兩個不相關的程序之間。無網路剪貼簿是乙個非常鬆散的交換媒介,可以支援任何資料格式,每一格式由一無符號整數標識,對標準 預定義 剪貼簿格式,該值是win32 api定義的常量 對非標準格式可以使用register cli...

windows下消滅殘留程序的方法

有時候自己寫的程式,雖然對話方塊關閉了,但是對話方塊的一些成員變數並沒有釋放掉 這些成員變數往往是一些指標,在對話方塊的建構函式裡構造,在對話方塊的析構函式裡釋放 如果陰差陽錯沒釋放掉,就造成程序不能退出。解決這個問題 的辦法,既要 預防 也要 治標 所謂預防,就是在對話方塊的宣告檔案裡,盡量把成員...