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的 ...
随机推荐
-
20145330《Java程序设计》第一次实验报告
20145330<Java程序设计>第一次实验报告 实验一Java开发环境的熟悉 实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Ja ...
-
Spring MVC 事务配置
Spring MVC事务配置 要了解事务配置的所有方法,请看一下<Spring事务配置的5种方法> 本文介绍两种配置方法: 一. XML,使用tx标签配置拦截器实现事务 一. ...
-
【CodeForces 602A】C - 特别水的题3-Two Bases
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102271#problem/C Description After seeing the ...
-
JAX-RS开发 hello world
1.建立maven webapp工程aty-rest. 2. 在pom文件增加spring框架.jax-rs接口.CXF实现 <dependency> <groupId>jav ...
-
(新)elasticsearch6.0版本安装head插件
ES6.0版本安装head插件 1.1 前言 不知道是我电脑问题还是最近的开源软件都比较**,mysql和elasticsearch新版本变动都比较大. elasticsearch6.0貌似已经不支持 ...
-
as无法在vivo上安装程序解决
1. vivo手机真的很麻烦,首先要确定vivo账号密码,允许安装后还一直失败.记录下解决方案 在工程目录的gradle.properties中添加android.injected.testOnly ...
-
莫比乌斯反演学习笔记(转载自An_Account大佬)
转载自An_Account大佬 提示:别用莫比乌斯反演公式,会炸的 只需要记住: [gcd(i,j)=1]=∑d∣gcd(i,j)μ(d)[gcd(i,j)=1]=\sum_{d|gcd(i,j)}\ ...
-
HttpClient 超时时间
setSoTimeout(MilSec):连接超时时间.如果在连接过程中有数据传输,超时时间重新计算. setConnectTimeout(MilSec):获取连接超时时间.如果该参数没有设置,那么默 ...
-
前端获得session信息方式对比,优化
在开发中,页面 js 经常会遇到需要 当前登录用户信息(菜单权限,用户基本信息,配置信息) 的地方,一般情况我们可能对这些信息获取方式不是太在意,但是现在的前端通过webpack打包,即使做了代码分割 ...
-
PHP通过mysqli连接mysql数据库
数据库连接的天龙八步: 1.连接数据库 连接:mysqli_connect 2.成功与否判断 连接错误号:mysqli_connect_errno 连接错误信息:mysqli_connect_erro ...