zoukankan      html  css  js  c++  java
  • ShellExecute用法 以及静态文本超链接

    打开一个文件 :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:koma0769@vip.qq.com", 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改掉

    1. class CSampleDlg : public CDialog   
    2. {   
    3. // Construction   
    4. public:   
    5.      CSampleDlg(CWnd* pParent = NULL);   // standard constructor   
    6.   
    7.     // Implementation   
    8. protected:   
    9.     HICON m_hIcon;   
    10.        
    11.     //用于保存静态文本框的屏幕坐标   
    12.      RECT m_pRectLink;     
    13.      ......   
    14. }  
    15. BOOL CSampleDlg::OnInitDialog()   
    16. {   
    17.      CDialog::OnInitDialog();   
    18.   
    19.     // Add "About..." menu item to system menu.   
    20.   
    21.     // IDM_ABOUTBOX must be in the system command range.   
    22.      ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);   
    23.      ASSERT(IDM_ABOUTBOX < 0xF000);   
    24.   
    25.      CMenu* pSysMenu = GetSystemMenu(FALSE);   
    26.     if (pSysMenu != NULL)   
    27.      {   
    28.          CString strAboutMenu;   
    29.          strAboutMenu.LoadString(IDS_ABOUTBOX);   
    30.         if (!strAboutMenu.IsEmpty())   
    31.          {   
    32.              pSysMenu->AppendMenu(MF_SEPARATOR);   
    33.              pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);   
    34.          }   
    35.      }   
    36.   
    37.     // TODO: Add extra initialization here   
    38.   
    39.     //将静态文本的屏幕坐标存放在m_pRectLink中   
    40.      GetDlgItem(IDC_LINK) -> GetWindowRect(&m_pRectLink);   
    41.     //将屏幕坐标转换为客户坐标   
    42.      ScreenToClient(&m_pRectLink);   
    43.   
    44.     return TRUE;  // return TRUE   unless you set the focus to a control   
    45. }  

    3、添加Windows消息WM_MOUSEMOVE和消息处理函数,代码如下:

    1. void CSampleDlg::OnMouseMove(UINT nFlags, CPoint point)   
    2. {   
    3.     // TODO: Add your message handler code here and/or call default   
    4.     //下面设置鼠标在静态文本区时,将光标设成小手状   
    5.     if (point.x > m_pRectLink.left && point.x < m_pRectLink.right && point.y > m_pRectLink.top && point.y < m_pRectLink.bottom )   
    6.     //此处添加判断坐标算法   
    7.      {   
    8.         HCURSOR hCursor;   
    9.          hCursor = AfxGetApp() -> LoadCursor(IDC_HAND);   
    10.   
    11.         //将鼠标设为小手状      并没有成功 原因待解
    12.          SetCursor(hCursor);   
    13.      }   
    14.      CDialog::OnMouseMove(nFlags, point);   
    15. }  

    4、添加Windows消息WM_LBUTTONDOWN  和消息处理函数,代码如下:

     

    1. void CSampleDlg::OnLButtonDown(UINT nFlags, CPoint point)   
    2. {   
    3.     // TODO: Add your message handler code here and/or call default   
    4.     //此处添加判断坐标算法   
    5.     if (point.x > m_pRectLink.left && point.x < m_pRectLink.right && point.y > m_pRectLink.top && point.y < m_pRectLink.bottom)   
    6.      {   
    7.         //鼠标左键按下   
    8.         if (nFlags == MK_LBUTTON)      
    9.          {   
    10.             //为改善鼠标效果,此处加入以上变换鼠标形状的代码   
    11.              ShellExecute(0, NULL, "http://hi.baidu.com/wangguang246", NULL,NULL, SW_NORMAL);   
    12.                
    13.             //也可以添加电子邮件的链接   
    14.              ShellExecute(0, NULL, "mailto:koma0769@vip.qq.com", NULL,NULL, SW_NORMAL);   
    15.          }   
    16.      }   
    17.        
    18.      CDialog::OnLButtonDown(nFlags, point);   
    19. }  
  • 相关阅读:
    Redis 外网无法访问
    设计模式单例模式
    网易笔试问答(20210328)新生代转移到老年代的情况
    网易笔试(20210327)最长摇摆子数组长度
    网易笔试(20210327)吉利数(子数组中数组和为6的倍数的最大子数组和)
    360笔试(20210328)射气球
    解决TFS 错误:[TF15013 请求的 Team Foundation Server 未向代理服务器注册]
    TFS 常用命令
    生成安全的用于加密的随机数
    一种新的验证码(改进版)
  • 原文地址:https://www.cnblogs.com/lidabo/p/3060512.html
Copyright © 2011-2022 走看看