用C ,呼叫瀏覽器開啟乙個網頁

2021-09-09 00:18:14 字數 2621 閱讀 3062

呼叫外部命令

如果用預設瀏覽器,就呼叫shellexecute(null, _t("open"), _t("explorer.exe"), _t(""), null, sw_show);

如果用ie開啟,就呼叫shellexecute(null, _t("open"), _t("iexplore.exe"), _t(""), null, sw_show);

//另外網上還有這樣的詳解
可以使用api函式shellexecute

有三個 windows api 函式可以執行可執行檔winexec、shellexecute和createprocess。

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

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

函式原型:

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

引數說明:

hwnd 視窗的名稱 (不知道這樣解釋對不對)

lpoperation 進行的操作,如"open","print","explore"分別對應 "開啟","列印","瀏覽", 也可以為空(""),此時表示進行預設的操作。

lpfile 要操作的檔案。

lpparameters 如果lpfile指定的是乙個可執行檔則表示引數

lpdirectory 操作進行的目錄

nshowcmd 新的應用程式的執行方式。其可用的值如下:

sw_hide 隱藏

sw_maximize 最大化

sw_minimize 最小化,並把z order順序在此視窗之後(即視窗下一層)的視窗啟動

sw_restore 啟動視窗並還原為初始化大小

sw_show 以當前大小和狀態啟動視窗

sw_showdefault 以預設方式執行

sw_showmaximized 啟動視窗並最大化

sw_showminimized 啟動視窗並最小化

sw_showminnoactive 最小化但不改變當前啟動的視窗

sw_showna 以當前狀態顯示視窗但不改變當前啟動的視窗

sw_shownoactivate 以初始化大小顯示視窗但不改變當前啟動的視窗

sw_shownormal 啟動並顯示視窗,如果是最大(小)化,視窗將會還原。第一次執行程式 時應該使用這個值

範例一:開啟 **

view plaincopy to clipboardprint?

shellexecute(handle, "open", "",nil,nil, sw_shownormal);

如果將filename引數設定為"mailto:"協議格式,那麼該函式將啟動預設的郵件使用者端程式,

如 microsoft outlook(也包括microsoft outlook express)或 netscape messanger。

shellexecute(handle, "open"," mailto:[email protected]", nil, nil, sw_shownormal);

開啟寫新郵件視窗,並自動填入收件人位置。

以下在介紹一些不一樣的用法:

開始乙個新的應用程式

開啟記事本,並開啟乙個檔案(系統能識別記事本應用程式的路徑,因此我們不必使用絕對路徑)

view plaincopy to clipboardprint?

shellexecute(handle, "open", "notepad", "c:\test\readme.txt", nil, sw_show);

列印乙個文件

shellexecute(handle, "print", "c:\test\test.doc", nil, nil, sw_show);

注意:可能你會看到word暫時的被開啟,但它會自動關閉。

開啟乙個html頁面

shellexecute(handle, "open", "", nil, nil, sw_show);

[/codes]

你能通過乙個已經註冊的檔案型別來開啟應用程式

shellexecute(handle, "open", "c:\test\readme.txt", nil, nil, sw_show);

用windows explorer 開啟乙個目錄

shellexecute(handle, "explore", "c:\windows)", nil, nil, sw_show);

執行乙個dos命令並立即返回

shellexecute(handle, "open", "command.com", "/c copy file1.txt file2.txt", nil, sw_show);

執行乙個dos命令並保持dos視窗存在

shellexecute(handle, "open", "command.com", "/k dir", nil, sw_show);

用C ,呼叫瀏覽器開啟乙個網頁

呼叫外部命令 如果用預設瀏覽器,就呼叫shellexecute null,t open t explorer.exe t null,sw show 如果用ie開啟,就呼叫shellexecute null,t open t iexplore.exe t null,sw show 另外網上還有這樣的詳...

用C ,呼叫瀏覽器開啟乙個網頁

呼叫外部命令 如果用預設瀏覽器,就呼叫shellexecute null,t open t explorer.exe t null,sw show 如果用ie開啟,就呼叫shellexecute null,t open t iexplore.exe t null,sw show 另外網上還有這樣的詳...

呼叫Android自帶瀏覽器開啟網頁

在android程式中我們可以通過傳送隱式intent來啟動系統預設的瀏覽器。如果手機本身安裝了多個瀏覽器而又沒有設定預設瀏覽器的話,系統將讓使用者選擇使用哪個瀏覽器來開啟連線。uri uri uri.parse intent intent new intent intent.action view...