windows終端程序中指定IE瀏覽器打開url鏈接

方案一:

ShellExecute打開新的url鏈接

SHSTDAPI_(HINSTANCE) ShellExecuteA(_In_opt_ HWND hwnd, _In_opt_ LPCSTR lpOperation, _In_ LPCSTR lpFile, _In_opt_ LPCSTR lpParameters,
    _In_opt_ LPCSTR lpDirectory, _In_ INT nShowCmd);
SHSTDAPI_(HINSTANCE) ShellExecuteW(_In_opt_ HWND hwnd, _In_opt_ LPCWSTR lpOperation, _In_ LPCWSTR lpFile, _In_opt_ LPCWSTR lpParameters,
    _In_opt_ LPCWSTR lpDirectory, _In_ INT nShowCmd);
#ifdef UNICODE
#define ShellExecute  ShellExecuteW
#else
#define ShellExecute  ShellExecuteA
#endif // !UNICODE

unicode編碼,url參數需要轉換爲wchar類型
例如:

std::string str = "https://www.baidu.com"
WCHAR *url = new WCHAR[str .length() + 1];

ShellExecute方法打開鏈接url

ShellExecute(NULL,   "open",  "IEXPLORE",  url,  NULL,   SW_SHOWNORMAL);	//在新的IE瀏覽器窗口中打開
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章