打开一个文件 :ShellExecute(NULL, NULL, "c://mfc类库详解.chm", NULL, NULL, SW_SHOWNORMAL);
打开一个文件夹: ShellExecute(NULL, NULL, "c://", NULL, NULL, SW_SHOWNORMAL);
在资源管理器中打开: ShellExecute(NULL, "explore", "c://", NULL, NULL, SW_SHOWNORMAL);
搜索一个文件夹 : ShellExecute(NULL, "find", "c://", NULL, NULL, SW_SHOWNORMAL);
点击发邮件 : ShellExecute(0, NULL, "mailto:[email protected]", NULL,NULL, SW_NORMAL);
QQ某人: ShellExecute(NULL,"open","tencent://Message/?Uin=345022596" ,NULL,NULL,NULL);
打开一个网址 :
WinExec("C://Program Files//Internet Explorer//IEXPLORE.exe http://www.baidu.com/", SW_SHOW);
ShellExecute(0, "open", "http://www.baidu.com", NULL,NULL, SW_NORMAL);
winexec 针对 可执行文件 shellexecute 针对 windows中的所有文件 他会找到windows登记了的对应程序打开对应文件
1、添加成员变量m_RectLink,用来保存文本框的坐标,添加两个静态文本控件,将默认ID改掉:
- class CSampleDlg : public CDialog
- {
-
- public:
- CSampleDlg(CWnd* pParent = NULL);
-
-
- protected:
- HICON m_hIcon;
-
-
- RECT m_pRectLink;
- ......
- }
- BOOL CSampleDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
-
-
-
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
-
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
-
-
-
-
- GetDlgItem(IDC_LINK) -> GetWindowRect(&m_pRectLink);
-
- ScreenToClient(&m_pRectLink);
-
- return TRUE;
- }
3、添加Windows消息WM_MOUSEMOVE和消息处理函数,代码如下:
- void CSampleDlg::OnMouseMove(UINT nFlags, CPoint point)
- {
-
-
- if (point.x > m_pRectLink.left && point.x < m_pRectLink.right && point.y > m_pRectLink.top && point.y < m_pRectLink.bottom )
-
- {
- HCURSOR hCursor;
- hCursor = AfxGetApp() -> LoadCursor(IDC_HAND);
-
- 并没有成功 原因待解
- SetCursor(hCursor);
- }
- CDialog::OnMouseMove(nFlags, point);
- }
4、添加Windows消息WM_LBUTTONDOWN 和消息处理函数,代码如下:
- void CSampleDlg::OnLButtonDown(UINT nFlags, CPoint point)
- {
-
-
- if (point.x > m_pRectLink.left && point.x < m_pRectLink.right && point.y > m_pRectLink.top && point.y < m_pRectLink.bottom)
- {
-
- if (nFlags == MK_LBUTTON)
- {
-
- ShellExecute(0, NULL, "http://hi.baidu.com/wangguang246", NULL,NULL, SW_NORMAL);
-
-
- ShellExecute(0, NULL, "mailto:[email protected]", NULL,NULL, SW_NORMAL);
- }
- }
-
- CDialog::OnLButtonDown(nFlags, point);
- }