Visual Studio 2008 (formely code-named ‘Orcas’) has several important updates for VC++ and MFC. Among them the possibility to create syslink controls, command or split buttons and network address controls. In this post I will show how you can work with the syslink control. The control provides a way to embed hypertext links in a window. It is actually a window that renders marked-up text just as hyperlinks in a web browser. Multiple links can be put in a single control, and are accessed by a zero-based index.

Currently it supports the anchor tag (<A>) with the HREF and ID attributes. HREF is used to specify a URL of any protocol (http, ftp, mailto, etc.). On the other hand ID specifies an unique name within the control, associated with an individual link.

The content is available in the toolbar, so you can simply drag and drop syslink controls onto you dialog template.

You can specify the text, including the anchor tag from the properties page, or you can use the SetWindowText function to set it at run-time.

  1. GetDlgItem(IDC_SYSLINK1)->SetWindowText(   L"Visit my web site”   L” and check my blog.”);

You have to handle the NM_CLICK notification, check which link was clicked and take the appropriate action:

BEGIN_MESSAGE_MAP(CMFCDemoDlg,CDialog)         ON_NOTIFY(NM_CLICK, IDC_SYSLINK1,&CMFCDemoDlg::OnNMClickSyslink1) END_MESSAGE_MAP()   
voidCMFCDemoDlg::OnNMClickSyslink1(NMHDR *pNMHDR, LRESULT *pResult){         PNMLINK pNMLink =(PNMLINK) pNMHDR;  
        if(wcscmp(pNMLink->item.szUrl, WEB_SITE)==0)         {                 ShellExecuteW(NULL, L"open", pNMLink->item.szUrl, NULL, NULL, SW_SHOWNORMAL);         }         elseif(wcscmp(pNMLink->item.szUrl, BLOG_LINK)==0)         {                 ShellExecuteW(NULL, L"open", pNMLink->item.szUrl, NULL, NULL, SW_SHOWNORMAL);         }  
        *pResult =0;}

In MFC 9.0 (version that will ship with Visual Studio 2008) class CLinkCtrl is a wrapper over the Windows API for working with the syslink control.

You can associate an instance of CLinkCtrl with a syslink control through the DDX mechanism:

voidCMFCDemoDlg::DoDataExchange(CDataExchange* pDX){         CDialog::DoDataExchange(pDX);         DDX_Control(pDX, IDC_SYSLINK2, Link2);}

In my demo application that you can download from here I used a second syslink with an ID attribute. Each time the link is clicked it increments a counter, which is shown. For that I created two helper functions first, one to generate part of the text and the second to set the text to the link control:

CStringCMFCDemoDlg::GetClickText()const{         CString str;         str.Format(L"clicked %d times",Clicks);         return str;}   
voidCMFCDemoDlg::SetLink2Text(){         Link2.SetWindowText(L"Link was ” + GetClickText() + L”“); }

When handling the NM_CLICK notification, I checked the szID member of structure LITEM and took the appropriate action:

voidCMFCDemoDlg::OnNMClickSyslink2(NMHDR *pNMHDR, LRESULT *pResult){         PNMLINK pNMLink =(PNMLINK) pNMHDR;   
        if(wcscmp(pNMLink->item.szID, L"clicked")==0)         {                 Clicks++;                 SetLink2Text();         }  
        *pResult =0;}

The result is shown here:

Hopefully the sample code that I put together will help you work with CLinkCtrl and the syslink control in VS 2008.

Syslink Control in MFC 9.0(转)的更多相关文章

  1. MFC控件(8):command button与syslink control

    在VS 2008里MFC多了4种控件,分别是 split buttons ,command button , syslink controls和 network address controls. s ...

  2. mfc中Button、Edit Control和MFC EditBrowse Control的用法

    [前(fei)言(hua)] 写LL(1)分析器被CString转string卡了一个多小时也是醉了. 趁着还算清醒写下这次用到的控件的使用方法好了. 这次实验的mfc用到了四个控件:Edit Con ...

  3. MFC9.0 Outlook控件的标题显示无法修改

    这是我在开发中遇到的问题,现记录下来,以便帮助你们. 不想看废话的可以只看最后三行,但你会错过很多. 俗话说的好啊,"Wise men learn by other men's mistak ...

  4. VS2010/MFC编程入门之二(利用MFC向导生成单文档应用程序框架)

    VS2010/MFC编程入门之二(利用MFC向导生成单文档应用程序框架)-软件开发-鸡啄米 http://www.jizhuomi.com/software/141.html   上一讲中讲了VS20 ...

  5. 十年MFC经历认识的Microsoft技术 [转]

    十年MFC经历认识的Microsoft技术[原创] 孙辉 自从2005年3月8日下午16时“十年MFC经历认识的Microsoft技术”以帖子的方式发表于CSDN论坛后,引起了许多网友得好评,使得笔者 ...

  6. vc++窗口的创建过程(MFC消息机制的经典文章)

    一.什么是窗口类  在Windows中运行的程序,大多数都有一个或几个可以看得见的窗口,而在这些窗口被创建起来之前,操作系统怎么知道该怎样创建该窗口,以及用户操作该窗口的各种消息交给谁处理呢?所以VC ...

  7. MFC9.0 Outlook控件的标题显示无法改动

    这是我在开发中遇到的问题,现记录下来,以便帮助你们. 不想看废话的能够仅仅看最后三行,但你会错过非常多. 俗话说的好啊,"Wise men learn by other men's mist ...

  8. VC++ 6.0 中使用 MSComm.ocx

    很多人喜欢单独安装VC++6.0,而不是完整安装VS,这样占用空间比较少,启动也快.但是要使用某些ActiveX控件的时候却会出现许可证问题(requires a design-time licenc ...

  9. MFC关于.rc文件 .rc2文件

    .rc文件和.rc2文件 c和rc2都是资源文件,包含了应用程序中用到的所有的资源. 两者不同在于:rc文件中的资源可以直接在VC集成环境中以可视化的方法进行编辑和修改; 而rc2中的资源不能在VC的 ...

随机推荐

  1. vue总结 06组件

    组件基础 基本示例 这里有一个 Vue 组件的示例: // 定义一个名为 button-counter 的新组件Vue.component('button-counter', { data: func ...

  2. 移动端Touch事件

    案例1: <!doctype html> <html lang="en"> <head> <meta charset="UTF- ...

  3. Dropout caffe源码

    GPU和CPU实现的不一样,这里贴的是CPU中的drop out 直接看caffe里面的源码吧:(产生满足伯努利分布的随机数mask,train的时候,data除以p,...... scale_ = ...

  4. UFLDL 教程学习笔记(三)

    教程地址:http://ufldl.stanford.edu/tutorial/supervised/SoftmaxRegression/ logstic regression是二分类的问题,如果想要 ...

  5. python包安装-centos7/windows

    1.修改pip源 临时使用: 可以在使用pip的时候在后面加上-i参数,指定pip源 eg: pip install scrapy -i https://pypi.tuna.tsinghua.edu. ...

  6. IE源代码摘抄,基于泄漏的IE5.0(持续更新)

    下载了一份很久以前泄漏的IE5.0的源代码,虽然已经是很古远的版本了.但是通过调试现有版本浏览器与查看源代码,发现关键部分的差距并不是很大,代码很有参考意义.这里把重要的函数.数据结构摘抄出来以备参考 ...

  7. Jenkins+Ant+Git+Jmeter实现持续集成

    个人记录: 基本的配置与Jenkins+Ant+SVN+Jmeter实现持续集成的配置一样,主要在Jenkins的配置上的区别会有所不同 安装的插件: enkins安装好之后,需要为其安装gitlab ...

  8. tp5总结(二)

    1.简化路由[一方面可以更好的让搜索引擎抓取:另一方面简化路由,利于记忆] 1-1.在[public/]下面创建admin.php 复制index.php 然后绑定前后台模块define('BIND_ ...

  9. Just a Hook (线段树)

    给你n个数(初始时每个数的值为1),m个操作,每个操作把区间[l,r]里的数更新为c,问最后这n个数的和是多少. 区域更新用懒惰标记 #include<bits/stdc++.h> usi ...

  10. Eclipse 更改默认的编码 和 换行符