windows客户端开发--通过ShellExecute函数打开浏览器
来源:互联网 发布:画框图软件 编辑:程序博客网 时间:2024/06/08 01:29
在我们的客户端中常常会有一些link,点击后希望通过浏览器导航到该链接。
我们是通过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
A pointer to a null-terminated string that specifies the file or object on which to execute the specified verb. To specify a Shell namespace object, pass the fully qualified parse name. Note that not all verbs are supported on all objects. For example, 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;}
- windows客户端开发--通过ShellExecute函数打开浏览器
- 使用ShellExecute函数打开IE浏览器下的新窗口
- ShellExecute:用默认的浏览器打开网页
- ShellExecute指定IE浏览器打开网页
- 如果通过ShellExecute打开一个连接
- ShellExecute函数打开文件的方法
- Mac/Linux/Windows通过命令调用浏览器打开某网页
- 用默认浏览器打开一个链接(ShellExecute)
- VC 使用IE、火狐或默认浏览器打开网页ShellExecute
- VC 使用IE、火狐或默认浏览器打开网页ShellExecute
- windows API 函数 ShellExecute 的多种用法
- windows API 函数 ShellExecute 的多种用法
- windows API 函数 ShellExecute 的多种用法
- windows API 函数 ShellExecute 的多种用法
- windows API 函数 ShellExecute 的多种用法
- 【C语言】(windows.h)ShellExecute函数
- vc通过shellexecute打开指定文件夹及文件
- ShellExecute函数
- 第一博客,行走在编程道路上的菜鸟
- HDU 4614 Vases and Flowers(线段树+2分)
- [BZOJ 2180]最小直径生成树
- 排序算法(五)——简单选择排序
- 编程之路
- windows客户端开发--通过ShellExecute函数打开浏览器
- U-boot启动流程分析 Start.s 汇编文件
- JDBC 简单入门
- cento7 crontab
- jquery validate使用Demo实例说明
- Activity、Window、View的关系
- 偶尔回顾一下C99先于C11(末)
- 10002---全文检索引擎Solr系列——入门篇
- QT学习笔记——容器类总结