?? 函數shellexecute的多種用法 .txt
字號:
在一個網站看資料時,發現一個關于WINDOWS API函數的學習資料,翻譯下來認初學者更快的了解這個API的使用。
ShellExecute的功能是運行一個外部程序(或者是打開一個已注冊的文件、打開一個目錄、打印一個文件等等),并對外部程序有一定的控制。
有幾個API函數都可以實現這些功能,但是在大多數情況下ShellExecute是更多的被使用的,同時它并不是太復雜。下面舉例說明它的用法。
開始一個新的應用程序
ShellExecute(Handle, 'open', PChar('c:\test\app.exe'), nil, nil, SW_SHOW);
打開記事本,并打開一個文件(系統能識別記事本應用程序的路徑,因此我們不必使用絕對路徑)
ShellExecute(Handle, 'open', PChar('notepad'), PChar('c:\test\readme.txt'), nil, SW_SHOW);
打印一個文檔
ShellExecute(Handle, 'print', PChar('c:\test\test.doc'), nil, nil, SW_SHOW);
注意:可能你會看到word暫時的被打開,但它會自動關閉。
打開一個HTML頁面
ShellExecute(Handle, 'open', PChar('http://www.festra.com/'), nil, nil, SW_SHOW);
你能通過一個已經注冊的文件類型來打開應用程序
ShellExecute(Handle, 'open', PChar('c:\test\readme.txt'), nil, nil, SW_SHOW);
用windows Explorer 打開一個目錄
ShellExecute(Handle, 'explore', PChar('c:\windows)', nil, nil, SW_SHOW);
運行一個DOS命令并立即返回
ShellExecute(Handle, 'open', PChar('command.com'), PChar('/c copy file1.txt file2.txt'), nil, SW_SHOW);
運行一個DOS命令并保持DOS窗口存在
ShellExecute(Handle, 'open', PChar('command.com'), PChar('/k dir'), nil, SW_SHOW);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -