ShellExecute用法 彈出ie視窗用

2021-06-09 00:57:34 字數 3652 閱讀 9212

shellexecute的功能是執行乙個外部程式(或者是開啟乙個已註冊的檔案、開啟乙個目錄、列印乙個檔案等等),並對外部程式有一定的控制。

有幾個api函式都可以實現這些功能,但是在大多數情況下shellexecute是更多的被使用的,同時它並不是太複雜。

shellexecute函式原型及引數含義如下:

shellexecute(

hwnd hwnd, //父視窗控制代碼 (如:null,handle等)

lpcstr lpoperation, //操作型別 (如:"open")*要加英文雙引號

lpcstr lpfile, //要進行操作的檔案或路徑

lpcstr lpparameters, //當lpoperation為「explore」時指定要傳遞的引數,通常設為null

lpcstr lpdirectory, //指定預設目錄,通常設為null

int nshowcmd //檔案開啟的方式,以通常方式還是最大化或最小化顯示,一般為sw_shownormal

) 例子如下:

//呼叫計算器

shellexecute(null,"open","calc.exe",null,null,sw_shownormal);

//呼叫記事本

shellexecute(null,"open","notepad.exe",null,null,sw_shownormal);

●operation:用於指定要進行的操作。其中「open」操作表示執行由filename引數指定的程式,或開啟由filename引數指定的檔案或資料夾;「print」操作表示列印由filename引數指定的檔案;「explore」操作表示瀏覽由filename引數指定的資料夾。當引數設為nil時,表示執行預設操作「open」。

●filename:用於指定要開啟的檔名、要執行的程式檔名或要瀏覽的資料夾名。

●parameters:若filename引數是乙個可執行程式,則此引數指定命令列引數,否則此引數應為nil或pchar(0)。

●directory:用於指定預設目錄。

●showcmd:若filename引數是乙個可執行程式,則此引數指定程式視窗的初始顯示方式,否則此引數應設定為0。

若shellexecute函式呼叫成功,則返回值為被執行程式的例項控制代碼。若返回值小於32,則表示出現錯誤。

上述僅僅是shellexecute函式的標準用法,下面將介紹它的特殊用法。

2.特殊用法

如果將filename引數設定為「http:」協議格式,那麼該函式將開啟預設瀏覽器並鏈結到指定的url位址。若使用者機器中安裝了多個瀏覽器,則該函式將根據windows 9x/nt登錄檔中http協議處理程式(protocols handler)的設定確定啟動哪個瀏覽器。

如:shellexecute(handle, "open", "http://

www.neu.edu.cn", null, null,sw_shownormal);

如:shellexecute(handle, "open", http://,

www.neu.edu.cn/default.htm',null,null

sw_shownormal);

如果將filename引數設定為「mailto:」協議格式,那麼該函式將啟動預設郵件客戶程式,如microsoft outlook(也包括microsoft outlook express)或netscape messanger。若使用者機器中安裝了多個郵件客戶程式,則該函式將根據windows 9x/nt登錄檔中mailto協議處理程式的設定確定啟動哪個郵件客戶程式。

格式一:mailto:

如:shellexecute(handle,"open", "mailto:", null, null, sw_shownormal);開啟新郵件視窗。

如:shellexecute(handle, "open"," mailto:[email protected]", null, null, sw_shownormal);開啟新郵件視窗,並自動填入收件人位址。若指定多個收件人位址,則收件人位址之間必須用分號或逗號分隔開(下同)。

如:shellexecute(handle, 『open』, 『 mailto:[email protected]?subject=hello&body=this is a test』, nil, nil, sw_shownormal);開啟新郵件視窗,並自動填入收件人位址、郵件主題和郵件正文。若郵件正文包括多行文字,則必須在每行文字之間加入換行轉義字元%0a。

例子(delphi):

在乙個應用程式呼叫c:\project1.exe;

shellexecute(handle, 'open','c:\project1.exe','字串內容',nil, sw_shownormal);

在project1.exe裡可以呼叫:

procedure tform1.formcreate(sender: tobject);

var i:integer;

begin

for i:=1 to paramcount do

if paramstr(i)<>'' then showmessage(paramstr(i));

end;

最後的那個引數,為視窗指定可視性方面的乙個命令。

請用下述任何乙個常數

sw_hide 隱藏視窗,活動狀態給另乙個視窗

sw_minimize 最小化視窗,活動狀態給另乙個視窗

sw_restore 用原來的大小和位置顯示乙個視窗,同時令其進入活動狀態

sw_show 用當前的大小和位置顯示乙個視窗,同時令其進入活動狀態

sw_showmaximized 最大化視窗,並將其啟用

sw_showminimized 最小化視窗,並將其啟用

sw_showminnoactive 最小化乙個視窗,同時不改變活動視窗

sw_showna 用當前的大小和位置顯示乙個視窗,不改變活動視窗

sw_shownoactivate 用最近的大小和位置顯示乙個視窗,同時不改變活動視窗

sw_shownormal 與sw_restore相同

007f3454 68 38527f00 push .007f5238 ; ascii "shell32.dll"

007f3459 ff15 c83e8000 call dword ptr ds:[<&kernel32.loadlibrarya>] ;

007f345f 68 44527f00 push .007f5244 ; ascii "shellexecutea"

007f3464 50 push eax

007f3465 ff15 9c398000 call dword ptr ds:[<&kernel32.getprocaddress>] ;007f346b 6a 01 push 1

007f346d 6a 00 push 0

007f346f 6a 00 push 0

007f3471 68 b4527f00 push 007f52b4 ; ascii "x5gg.3322.org"

007f3476 68 52527f00 push 007f5252 ; ascii "open"

007f347b 6a 00 push 0

007f347d ffd0 call eax

ShellExecute用法種種

q 如何開啟乙個應用程式?shellexecute this m hwnd,open calc.exe sw show 或 shellexecute this m hwnd,open notepad.exe c mylog.log sw show 正如您所看到的,我並沒有傳遞程式的完整路徑。q 如何...

Delphi中ShellExecute的妙用

shellexecute的功能是執行乙個外部程式 或者是開啟乙個已註冊的檔案 開啟乙個目錄 列印乙個檔案等等 並對外部程式有一定的控制。有幾個api函式都可以實現這些功能,但是在大多數情況下shellexecute是更多的被使用的,同時它並不是太複雜。下面舉例說明它的用法。開啟記事本,並開啟乙個檔案...

Delphi中ShellExecute的妙用

shellexecute的功能是執行乙個外部程式 或者是開啟乙個已註冊的檔案 開啟乙個目錄 列印乙個檔案等等 並對外部程式有一定的控制。有幾個api函式都可以實現這些功能,但是在大多數情況下shellexecute是更多的被使用的,同時它並不是太複雜。下面舉例說明它的用法。開始乙個新的應用程式 開啟...