windows 클 라 이언 트 개발 - ShellExecute 함수 로 브 라 우 저 열기

3673 단어 windowsshellexecute
Google 클 라 이언 트 에 서 는 링크 가 자주 있 습 니 다. 클릭 한 후에 브 라 우 저 를 통 해 이 링크 를 탐색 하고 싶 습 니 다.
우 리 는 ShellExecute 함 수 를 통 해 이 루어 졌 다.
ShellExecute 의 기능 은 외부 프로그램 을 실행 하거나 등 록 된 파일 을 열 거나 디 렉 터 리 를 열 거나 파일 을 인쇄 하 는 등 외부 프로그램 을 제어 하 는 것 입 니 다.
이 함 수 를 사용 하려 면 헤더 파일 을 가 져 와 야 합 니 다:
#include <shellapi.h>

함수 원형 보기:
ShellExecute(
hWnd: HWND; {指定父窗口句柄}
Operation: PChar; {指定动作, 譬如: open、runas、print、edit、explore、find[2] }
FileName: PChar; {指定要打开的文件或程序}
Parameters: PChar; {给要打开的程序指定参数; 如果打开的是文件这里应该是 nil}
Directory: PChar; {缺省目录}
ShowCmd: Integer {打开选项}
)

ShellExecute 를 통 해 windows 시스템 이 자체 적 으로 가지 고 있 는 수첩, 계산기 등 을 열 수 있 습 니 다.
우리 에 게 필요 한 것 은 www. baidu. com 과 같은 링크 를 여 는 것 이다.
더 나 아가, 우 리 는 어떻게 브 라 우 저 를 지정 하여 www. baidu. com 을 엽 니까?
이 함수 의 매개 변 수 를 다시 한 번 설명해 야 합 니 다: lpFile [in] Type: LPCTSTR 지정 한 verb 를 실행 할 file or object 를 지정 하 는 null - terminated string 에 pointer 를 지정 합 니 다. Shell namespace object 를 지정 하려 면 fully qualified parse name 을 전달 합 니 다. Note that not all verbs are supported on all objects. 예 를 들 어, not all document types support the “print” verb. If a relative path is used for the lpDirectory parameter do not use a relative path for lpFile.
lpParameters [in, optional] Type: LPCTSTR If lpFile specifies an executable file, this parameter is a pointer to a null-terminated string that specifies the parameters to be passed to the application. The format of this string is determined by the verb that is to be invoked. If lpFile specifies a document file, lpParameters should be NULL.
lpDirectory [in, optional] Type: LPCTSTR A pointer to a null-terminated string that specifies the default (working) directory for the action. If this value is NULL, the current working directory is used. If a relative path is provided at lpFile, do not use a relative path for lpDirectory.
그래서 우 리 는 이렇게 사용 할 수 있다.
#include<iostream>
#include<Windows.h>
#include<shellapi.h>
int main()
{
    //使用IE浏览器打开www.baidu.com
    ShellExecute(NULL, L"open", L"iexplore.exe", L"www.baidu.com", NULL, SW_MAXIMIZE);

    //使用搜狗浏览器打开www.baidu.com
    ShellExecute(NULL, L"open", L"SogouExplorer.exe", L"www.baidu.com", NULL, SW_MAXIMIZE);

   //使用默认浏览器打开www.baidu.com,我用的是chrome
    ShellExecute(NULL, L"Open", L"www.baidu.com", 0, 0, SW_SHOWNORMAL);

    return 0;
}

좋은 웹페이지 즐겨찾기