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的 ...
随机推荐
- linux中查看结构体和宏
1.进入目录/usr/include cd /usr/include/ 2.生成ctags文件sudo make ctags -R 3.vim -t 结构体(宏)名称 4.找到相应的宏或者结构体 5. ...
- Scrapy:创建爬虫程序的方式
Windows 10家庭中文版,Python 3.6.4,Scrapy 1.5.0, 在Scrapy中,建立爬虫程序或项目的方式有两种(在孤读过Scrapy的大部分文档后): 1.继承官方Spider ...
- 如何成为技术大牛——阿里CodeLife
天天写业务代码的程序员,怎么成为技术大牛,开始写技术代码? 几个误区 跟着大牛,就可以成为大牛.首先,大牛时间很宝贵,不可能花很多时间去指导你:其次,简单的模仿大牛,只能学到表面知识,不可能成为大牛: ...
- python基础-类的继承
继承:承创建的新类称为“子类”或“派生类”,被继承的类称为“基类”.“父类. 继承的过程,就是从一般到特殊的过程.要实现继承,可以通过“继承”(Inheritance)和“组合”(Compositio ...
- RNN BPTT
双向LSTM
- 使用html+css+js实现魔性的舞蹈
使用html+css+js实现魔性的舞蹈,让我们燥起来!!! 效果图: 代码如下,复制代码即可使用: <!DOCTYPE html> <html > <head> ...
- Selenium_多线程执行测试用例
多线程执行测试用例 这里以百度搜索为例,通过不同的浏览器来启动不同的线程. #!/usr/bin/env python # _*_ coding:utf-8 _*_ __author__ = 'Yin ...
- WinForm界面开发之 启动界面
我们在开发桌面应用程序的时候,由于程序启动比较慢,往往为了提高用户的体验,增加一个闪屏,也就是SplashScreen,好处有:1.让用户看到加载的过程,提高程序的交互响应:2.可以简短展示或者介绍程 ...
- 一步一步学习IdentityServer4 (2) 开始一个简单的事例
前面将来一些配置,但是很多都不是必要的,先放一些事例需要的简要配置把 既然是IdentityServer4 所里下面的例子我 直接放到 Linux上 测试环境 CentOS 7 +Nginx1.9.3 ...
- PHP随机浮点数
function randomFloat($min = 0, $max = 1) { $rand = mt_rand(); $lmax = mt_getrandmax(); return $min + ...