ShellExecuteçåè½æ¯è¿è¡ä¸ä¸ªå¤é¨ç¨åºï¼æè
æ¯æå¼ä¸ä¸ªå·²æ³¨åçæ件ãæå¼ä¸ä¸ªç®å½ãæå°ä¸ä¸ªæ件ççï¼ï¼å¹¶å¯¹å¤é¨ç¨åºæä¸å®çæ§å¶ã
ä¸ãShellExecute常ç¨æ¹æ³
æå 个APIå½æ°é½å¯ä»¥å®ç°è¿äºåè½ï¼ä½æ¯å¨å¤§å¤æ°æ
åµä¸ShellExecuteæ¯æ´å¤ç被使ç¨çï¼åæ¶å®å¹¶ä¸æ¯å¤ªå¤æãä¸é¢ä¸¾ä¾è¯´æå®çç¨æ³ã
1.å¼å§ä¸ä¸ªæ°çåºç¨ç¨åº
ShellExecute(Handle, 'open', PChar('c:\test\app.exe'), nil, nil, SW_SHOW);
2.æå¼è®°äºæ¬ï¼å¹¶æå¼ä¸ä¸ªæ件(ç³»ç»è½è¯å«è®°äºæ¬åºç¨ç¨åºçè·¯å¾ï¼å æ¤æ们ä¸å¿
使ç¨ç»å¯¹è·¯å¾ï¼
ShellExecute(Handle, 'open', PChar('notepad'), PChar('c:\test\readme.txt'), nil, SW_SHOW);
3.æå°ä¸ä¸ªææ¡£
ShellExecute(Handle, 'print', PChar('c:\test\test.doc'), nil, nil, SW_SHOW);
注æï¼å¯è½ä¼çå°wordææ¶ç被æå¼ï¼ä½å®ä¼èªå¨å
³éã
4.æå¼ä¸ä¸ªHTML页é¢
ShellExecute(Handle, 'open', PChar('
http://xxx.xxxxxx.xxx/'), nil, nil, SW_SHOW);
5.è½éè¿ä¸ä¸ªå·²ç»æ³¨åçæ件类åæ¥æå¼åºç¨ç¨åº
ShellExecute(Handle, 'open', PChar('c:\test\readme.txt'), nil, nil, SW_SHOW);
6.ç¨windows Explorer æå¼ä¸ä¸ªç®å½
ShellExecute(Handle, 'explore', PChar('c:\windows)', nil, nil, SW_SHOW);
7.è°ç¨èµæºç®¡çå¨
ShellExecute(0,'explore',0,filename,0,1); //æ¤å¤çFILENAME为驱å¨å¨ï¼å¦C:\
8.è¿è¡ä¸ä¸ªDOSå½ä»¤å¹¶ç«å³è¿å
ShellExecute(Handle, 'open', PChar('command.com'), PChar('/c copy file1.txt file2.txt'), nil, SW_SHOW);
9.è¿è¡ä¸ä¸ªDOSå½ä»¤å¹¶ä¿æDOSçªå£åå¨
ShellExecute(Handle, 'open', PChar('command.com'), PChar('/k dir'), nil, SW_SHOW);
10.åemail
v_mailto:='mailto:'+filename; //filename为EMAILå°å
v_mailto:=v_mailto+'?subject='+docname; // docname为æ é¢
shellexecute(0,'open',v_mailto,0,0,1);
äºãShellExecute详解
ShellExecuteå½æ°ç¨äºæå¼æè
æå°ä¸ä¸ªæå®çæ件ãæå®çæ件å¿
é¡»æ¯å¯æ§è¡æ件æè
ææ¡£æ件ã
HINSTANCE ShellExecute(
HWND hwnd, // handle to parent window
LPCTSTR lpOperation, // pointer to string that specifies operation to perform
LPCTSTR lpFile, // pointer to filename or folder name string
LPCTSTR lpParameters, // pointer to string that specifies executable-file parameters
LPCTSTR lpDirectory, // pointer to string that specifies default directory
INT nShowCmd // whether file is shown when opened
)
* Paramsï¼åæ°è§£éï¼
Hwnd
æå®ç¶çªå£å¥æãè¿ä¸ªçªå£æ¥æ¶å·¥ç¨äº§ççæææ¶æ¯ãä¾å¦ï¼ä¸ä¸ªå·¥ç¨å¯ä»¥éè¿æ¶æ¯æ¡æ¥åé误ã
lpOperation
以ä¸ä¸ªä»¥nullç»æçå符串æè¿°æä½çæ§è¡ã以ä¸çæä½å符串æ¯ææçï¼
è¡å· åæ° å«ä¹
1 âopenâ å½æ°æå¼ç±lpFileæå®çæ件ãè¿ä¸ªæ件å¿
é¡»æ¯å¯æ§è¡æ件æè
ææ¡£æ件ãæ件夹å¿
é¡»æ¯å¯æå¼çæ件夹ã
2 âprintâ å½æ°æå°ç±lpFileæå®çæ件ãè¿ä¸ªæ件åºè¯¥æ¯ææ¡£æ件ãå¦ææå®çæ件æ¯å¯æ§è¡æ件ï¼å½æ°å°ä»¥opençæ¹å¼æå¼è¿ä¸ªæ件ã
3 âexploreâ å½æ°å°æç´¢ç±lpFileæå®çæ件夹ã
lpOperation
åæ°å¦æ为nullï¼å½æ°å°ä»¥opençæ¹å¼æå¼ç±lpFileæå®çæ件ã
lpFile
以ä¸ä¸ªnullç»æçå符串æè¿°æå¼æè
æå°æå®çæ件ï¼æè
æå¼æè
æç´¢æå®ç
æ件夹ãå½æ°å¯ä»¥æå¼ä¸ä¸ªæå®çæ件æè
æ件夹ï¼ä¹å¯ä»¥æå°ä¸ä¸ªææ¡£æ件ã
lpParameters
å¦ælpFileæå®çæ¯ä¸ä¸ªå¯æ§è¡æ件ï¼lpParameters以ä¸ä¸ªä»¥nullç»æçå符串æå®è¯¥æ§è¡æä»¶ä¼ ç»åºç¨è½¯ä»¶çåæ°ã
è¡å· åæ° å«ä¹
1 SW_HIDE éèè¿ä¸ªçªä½ï¼å¹¶æ¿æ´»å
¶ä»çªä½ã
2 SW_MAXIMIZE æ大åæå®ççªä½ã
3 SW_MINIMIZE æå°åæå®ççªä½ï¼å¹¶æ顺åºæ¿æ´»æä¸å±ççªä½ã
4 SW_RESTORE æ¿æ´»å¹¶æ¾ç¤ºçªä½ãå¦æçªä½ä¸ºæå°åæè
æ大åï¼çªä½æ¢å¤å°åå§å¤§å°åä½ç½®ãåºç¨ç¨åºå½æ¢å¤ä¸ä¸ªæå°åççªä½æ¶å°æå®æ è®°ã
5 SW_SHOW 以å½åç大å°åä½ç½®æ¿æ´»å¹¶æ¾ç¤ºçªä½ã
6 SW_SHOWDEFAULT
7 SW_SHOWMAXIMIZED æ¿æ´»å¹¶æ大åæ¾ç¤ºçªä½ã
8 SW_SHOWMINIMIZED æ¿æ´»å¹¶æå°åç°å®çªä½ã
9 SW_SHOWMINNOACTIVE æå°åçªä½ï¼ä¿æå
¶æ¿æ´»ç¶æã
10 SW_SHOWNA 以å½åç¶ææ¾ç¤ºçªä½ï¼ä¿æå
¶æ¿æ´»ç¶æã
11 SW_SHOWNOACTIVATE 以å½åç大å°åä½ç½®æ¾ç¤ºçªä½ï¼å¹¶ä¿æå
¶æ¿æ´»ç¶æã
12 SW_SHOWNORMAL æ¿æ´»å¹¶æ¾ç¤ºä¸ä¸ªçªä½ãå¦æçªä½ä¸ºæ大åæè
æå°åï¼çªä½æ¢å¤å°åå§ç大å°åä½ç½®ãå½çªä½ç¬¬ä¸æ¬¡æ¾ç¤ºçæ¶åï¼åºç¨ç¨åºè®°å½æ è®°ã
å¦ælpFieldæå®çæ¯ä¸ä¸ªææ¡£æ件ï¼lpParametersåºè¯¥ä¸ºnullã
lpDirectory
以ä¸ä¸ªä»¥nullç»æçå符串æå®æ件å¼å§è¿è¡çé»è®¤ç®å½ã
nShowCmd
å¦ælpFieldæå®äºä¸ä¸ªå¯æ§è¡æ件ï¼nShowCmdæå®è¿ä¸ªæ件å¨è¢«æå¼æ¶å¦ä½æ¾ç¤ºãè¿ä¸ªåæ°å¯ä»¥æ¯ä»¥ä¸å¼ä¸çä»»ä½ä¸ä¸ªï¼
å¦ælpFieldæå®çæ¯ææ¡£æ件ï¼nShowCmdåºè¯¥ä¸º0ã
* return Valuesï¼è¿åå¼ï¼
å¦æå½æ°æ§è¡æåï¼è¿åå¼æ¯å·²ç»è¿è¡çå·¥ç¨çå®ä¾å¥æï¼æè
å¨ææ°æ®äº¤æ¢æå¡å¨åºç¨ç¨åºçå¥æã
ï¼å
·ä½è¿åå¼å表ä»ç¥ï¼è¯·åèDelphiå¨çº¿å¸®å©ï¼
* Remarksï¼æ³¨éï¼
被lpFileåæ°æå®çæ件å¿
é¡»æ¯ä¸ä¸ªå¯æ§è¡æ件æè
ææ¡£æ件ãå¦ææ件æ¯ä¸ä¸ªææ¡£æ件ï¼ShellExecuteå½æ°å°æ ¹æ®lpOperationåæ°å³å®æå¼æè
æå°è¿ä¸ªæ件ãå¦ææ¯å¯æ§è¡æ件ï¼ShellExecuteå½æ°å°æå¼å®ï¼å³ä½¿lpOperationåæ°è¢«æå®ä¸ºprintingã
å¯ä»¥ä½¿ç¨ShellExecuteæå¼æ´»çæç´¢ä¸ä¸ªæ件夹ãå¯ä»¥ä½¿ç¨ä»¥ä¸ä»»æä¸ç§æ¹å¼æå¼ä¸ä¸ªæ件夹ï¼
ShellExecute(handle, NULL, path_to_folder, NULL, NULL, SW_SHOWNORMAL);
æè
ShellExecute(handle, "open", path_to_folder, NULL, NULL, SW_SHOWNORMAL);
使ç¨ä¸é¢çè°ç¨æç´¢æ件夹ï¼
ShellExecute(handle, "explore", path_to_folder, NULL, NULL, SW_SHOWNORMAL)
å¦ælpOperationåæ°ä¸ºnullï¼å½æ°å°æå¼ç±lpFileæå®çæ件ãå¦ælpOperationåæ°ä¸ºâopenâæè
âexploreâï¼å½æ°å°å¼ºå¶æå¼çªä½æè
èµæºç®¡çå¨ã
注ï¼å¨æ°çªå£æå¼ç½é¡µçåæ³
ShellExecute(self.Handle, PChar('open'), PChar('explorer'), PChar(URL), nil, SW_MAXIMIZE);