Syslink Control in MFC 9.0(转)
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.
- 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(转)的更多相关文章
- MFC控件(8):command button与syslink control
在VS 2008里MFC多了4种控件,分别是 split buttons ,command button , syslink controls和 network address controls. s ...
- mfc中Button、Edit Control和MFC EditBrowse Control的用法
[前(fei)言(hua)] 写LL(1)分析器被CString转string卡了一个多小时也是醉了. 趁着还算清醒写下这次用到的控件的使用方法好了. 这次实验的mfc用到了四个控件:Edit Con ...
- MFC9.0 Outlook控件的标题显示无法修改
这是我在开发中遇到的问题,现记录下来,以便帮助你们. 不想看废话的可以只看最后三行,但你会错过很多. 俗话说的好啊,"Wise men learn by other men's mistak ...
- VS2010/MFC编程入门之二(利用MFC向导生成单文档应用程序框架)
VS2010/MFC编程入门之二(利用MFC向导生成单文档应用程序框架)-软件开发-鸡啄米 http://www.jizhuomi.com/software/141.html 上一讲中讲了VS20 ...
- 十年MFC经历认识的Microsoft技术 [转]
十年MFC经历认识的Microsoft技术[原创] 孙辉 自从2005年3月8日下午16时“十年MFC经历认识的Microsoft技术”以帖子的方式发表于CSDN论坛后,引起了许多网友得好评,使得笔者 ...
- vc++窗口的创建过程(MFC消息机制的经典文章)
一.什么是窗口类 在Windows中运行的程序,大多数都有一个或几个可以看得见的窗口,而在这些窗口被创建起来之前,操作系统怎么知道该怎样创建该窗口,以及用户操作该窗口的各种消息交给谁处理呢?所以VC ...
- MFC9.0 Outlook控件的标题显示无法改动
这是我在开发中遇到的问题,现记录下来,以便帮助你们. 不想看废话的能够仅仅看最后三行,但你会错过非常多. 俗话说的好啊,"Wise men learn by other men's mist ...
- VC++ 6.0 中使用 MSComm.ocx
很多人喜欢单独安装VC++6.0,而不是完整安装VS,这样占用空间比较少,启动也快.但是要使用某些ActiveX控件的时候却会出现许可证问题(requires a design-time licenc ...
- MFC关于.rc文件 .rc2文件
.rc文件和.rc2文件 c和rc2都是资源文件,包含了应用程序中用到的所有的资源. 两者不同在于:rc文件中的资源可以直接在VC集成环境中以可视化的方法进行编辑和修改; 而rc2中的资源不能在VC的 ...
随机推荐
- Scrapy的【SitemapSpider】的【官网示例】没有name属性
Windows 10家庭中文版,Python 3.6.4,Scrapy 1.5.0, 上午看了Scrapy的Spiders官文,并按照其中的SitemapSpider的示例练习,发现官文的示例存在问题 ...
- Scrapy命令行工具简介
Windows 10家庭中文版,Python 3.6.4,virtualenv 16.0.0,Scrapy 1.5.0, 在最初使用Scrapy时,使用编辑器或IDE手动编写模块来创建爬虫(Spide ...
- 学习总结——JMeter做http接口功能测试
JMeter对各种类型接口的测试 默认做接口测试前,已经给出明确的接口文档(如,http://test.nnzhp.cn/wiki/index.php?doc-view-59):本地配好了JMeter ...
- ASP .Net Core系统部署到 CentOS7 64 具体方案
.Net Core 部署到 CentOS7 64 位系统中的步骤 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2.0) 3.Supervisor(进程管理工具,目的是 ...
- python基础学习之路No.5 数学函数以及操作
python的基本数学函数 函数 返回值 ( 描述 ) abs(x) 返回数字的绝对值,如abs(-10) 返回 10 ceil(x) 返回数字的上入整数,如math.ceil(4.1) 返回 5 c ...
- mysql数据库主从同步复制原理
MySQL的Replication(英文为复制)是一个多MySQL数据库做主从同步的方案,特点是异步复制,广泛用在各种对MySQL有更高性能.更高可靠性要求的场合.与之对应的是另一个同步技术是MySQ ...
- python图片处理(二)
python中图像处理有pillow和skimage 图像中一般有个RGBA值,RGB顾名思义就是红绿蓝值,A表示alpha表示是透明度. from PIL import ImageColor pri ...
- markdown转换为html
想要自己实现markdown编辑器,欲使用markdown-it作为编辑器,有着比较多的插件,可以实现代码高亮以及对数学公式转换等功能. // Activate/deactivate rules, w ...
- UtraEdit正则表达式替换.def
* (? 替换(?结尾 ),*$ 替换),开头
- Java人员正确使用 IntelliJ IDEA的方式
原文: http://tengj.top/2017/02/22/idea1-1/ 作者: 嘟嘟MD 前言 博主是Java开发人员,以前一直都用myeclipse来开发的,说实话感觉myeclipse毫 ...