﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-lanshengsheng</title><link>http://www.cppblog.com/lanshengsheng/</link><description /><language>zh-cn</language><lastBuildDate>Sun, 12 Apr 2026 09:37:17 GMT</lastBuildDate><pubDate>Sun, 12 Apr 2026 09:37:17 GMT</pubDate><ttl>60</ttl><item><title>http://blog.csdn.net/lanshengsheng2012</title><link>http://www.cppblog.com/lanshengsheng/archive/2013/05/07/200084.html</link><dc:creator>盛胜</dc:creator><author>盛胜</author><pubDate>Tue, 07 May 2013 08:53:00 GMT</pubDate><guid>http://www.cppblog.com/lanshengsheng/archive/2013/05/07/200084.html</guid><wfw:comment>http://www.cppblog.com/lanshengsheng/comments/200084.html</wfw:comment><comments>http://www.cppblog.com/lanshengsheng/archive/2013/05/07/200084.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lanshengsheng/comments/commentRss/200084.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lanshengsheng/services/trackbacks/200084.html</trackback:ping><description><![CDATA[<a href="http://blog.csdn.net/lanshengsheng2012">http://blog.csdn.net/lanshengsheng2012<br /><br />由于</a>这个博客仅限于c++方面。目前进行我的博客转移到csdn<img src ="http://www.cppblog.com/lanshengsheng/aggbug/200084.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lanshengsheng/" target="_blank">盛胜</a> 2013-05-07 16:53 <a href="http://www.cppblog.com/lanshengsheng/archive/2013/05/07/200084.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VC动态创建控件</title><link>http://www.cppblog.com/lanshengsheng/archive/2013/04/07/199173.html</link><dc:creator>盛胜</dc:creator><author>盛胜</author><pubDate>Sun, 07 Apr 2013 06:36:00 GMT</pubDate><guid>http://www.cppblog.com/lanshengsheng/archive/2013/04/07/199173.html</guid><wfw:comment>http://www.cppblog.com/lanshengsheng/comments/199173.html</wfw:comment><comments>http://www.cppblog.com/lanshengsheng/archive/2013/04/07/199173.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lanshengsheng/comments/commentRss/199173.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lanshengsheng/services/trackbacks/199173.html</trackback:ping><description><![CDATA[<div style="color: #333333; font-family: Arial; background-color: #ffffff; word-wrap: break-word; word-break: break-all; line-height: 18px; font-weight: bold; overflow: hidden; visibility: visible !important; zoom: 1 !important;">VC动态创建控件</div><div style="font-family: Arial; background-color: #ffffff; word-wrap: break-word; word-break: break-all; line-height: 18px; margin: 5px 0px 8px; color: #666666; visibility: visible !important; zoom: 1 !important;">2010-12-15 11:09</div><table style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; background-color: #ffffff; table-layout: fixed; width: 960px;"><tbody><tr><td style="word-wrap: break-word; word-break: break-all; line-height: 18px; visibility: visible !important; zoom: 1 !important;"><div id="blog_text" style="word-wrap: break-word; word-break: normal; line-height: 20px; overflow: hidden; visibility: visible !important; zoom: 1 !important; position: relative !important;"><p style="line-height: normal;"><strong>动态控件是指<span style="color: #0000ff;">在需要时由Create()创建的控件</span>，这与预先在对话框中放置的控件是不同的。&nbsp;<br /><br />　　<span style="color: #ff0000;">一、创建动态控件：</span><br /><br />　　为了对照，我们先来看一下静态控件的创建。<br /><br />　　放置静态控件时必须先建立一个容器，一般是对话框，这时我们在对话框编辑窗口中，从工具窗口中拖出所需控件放在对话框中即可，再适当修改控件ID，设置控件属性，一个静态控件就创建好了，当对话框被显示时，其上的控件也会显示。<br /><br />　　静态控件不需要调用Create()函数来创建。<br /><br />　　而创建动态控件有很大不同，以下以按钮为例，看一下动态控件的创建过程：<br /><br />　　1.建立控件ID号：<br /><br />　　ID号是控件的标识，创建控件前必须先为它设置一个ID号。<br /><br />　　打开资源中的&#8220;String Table&#8221;，在空白行上双击鼠标，这时会弹出一个ID属性对话框，在其中的ID编辑框中输入ID，如：IDC_MYBUTTON，在Caption中输入控件标题或注解（注：Caption框不能为空，为空会导致创建失败），这里我输入的是按钮上要显示的文字--动态按钮。<br /><br />　　2.建立控件对象：<br /><br />　　不同种类的控件应创建不同的类对象：<br /><br />　　&#183;按钮控件 CButton （包括普通按钮、单选按钮和复选按钮）<br />　　&#183;编辑控件 CEdit<br />　　&#183;静态文本控件 CStatic<br />　　&#183;标签控件 CTabCtrl<br />　　&#183;旋转控件 CSpinButtonCtrl<br />　　&#183;滑标控件 CSliderCtrl<br />　　&#183;多信息编辑控件 CRichEditCtrl<br />　　&#183;进度条控件 CProgressCtrl<br />　　&#183;滚动条控件 CSrcollBar<br />　　&#183;组合框控件 CComboBox<br />　　&#183;列表框控件 CListBox<br />　　&#183;图像列表控件 CImageCtrl<br />　　&#183;树状控件 CTreeCtrl<br />　　&#183;动画控件 CAnimateCtrl<br /><br />　　本例中我们创建一个CButton类的普通按钮。注意不能直接定义CButton对象，如：CButton m_MyBut;这种定义只能用来给静态控件定义控制变量，不能用于动态控件。<br /><br />　　正确做法是用new调用CButton构造函数生成一个实例：<br /><br /></strong></p><table width="90%" align="center" bgcolor="#dadacf" border="1" style="table-layout: auto !important;"><tbody><tr><td style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important;">CButton *p_MyBut = new CButton();</td></tr></tbody></table><br />　　然后用CButton类的Create()函数创建，该函数原型如下：<br /><br /><table width="90%" align="center" bgcolor="#dadacf" border="1" style="table-layout: auto !important;"><tbody><tr><td style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important;">BOOL Create( LPCTSTR lpszCaption, DWORD dwStyle, const RECT&amp; rect, CWnd* pParentWnd, UINT nID );</td></tr></tbody></table><br />　　lpszCaption是按钮上显示的文本；dwStyle指定按钮风格，可以是按钮风格与窗口风格的组合，取值有：<br /><br />　　窗口风格：<br /><br />　　&#183;WS_CHILD 子窗口，必须有<br />　　&#183;WS_VISIBLE 窗口可见，一般都有<br />　　&#183;WS_DISABLED 禁用窗口，创建初始状态为灰色不可用的按钮时使用<br />　　&#183;WS_TABSTOP 可用Tab键选择<br />　　&#183;WS_GROUP 成组，用于成组的单选按钮中的第一个按钮<br /><br />　　按钮风格：<br /><br />　　&#183;BS_PUSHBUTTON 下压式按钮，也即普通按钮<br />　　&#183;BS_AUTORADIOBUTTON 含自动选中状态的单选按钮<br />　　&#183;BS_RADIOBUTTON 单选按钮，不常用<br />　　&#183;BS_AUTOCHECKBOX 含自动选中状态的复选按钮<br />　　&#183;BS_CHECKBOX 复选按钮，不常用<br />　　&#183;BS_AUTO3STATE 含自动选中状态的三态复选按钮<br />　　&#183;BS_3STATE 三态复选按钮，不常用<br />　<br />　　以上风格指定了创建的按钮类型，不能同时使用，但必须有其一。<br /><br />　　&#183;BS_BITMAP 按钮上将显示位图<br />　　&#183;BS_DEFPUSHBUTTON 设置为默认按钮，只用于下压式按钮，一个对话框中只能指定一个默认按钮<br />　　&#183;rect指定按钮的大小和位置；<br />　　&#183;pParentWnd指示拥有按钮的父窗口，不能为NULL；<br />　　&#183;nID指定与按钮关联的ID号，用上一步创建的ID号。<br /><br />　　不同控件类的Create()函数略有不同，可参考相关资料。<br /><br />　　例：p_MyBut-&gt;Create( "动态按钮", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(20,10,80,40), this, IDC_MYBUTTON );<br />这样，我们就在当前对话框中的(20,10)处创建了宽60，高30，按钮文字为&#8220;动态按钮&#8221;的下压式按钮。<br /><br />　　为了使创建过程更方便易用，我定义了如下函数：<br /><br /><table width="90%" align="center" bgcolor="#dadacf" border="1" style="table-layout: auto !important;"><tbody><tr><td style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important;">CButton* CTextEditorView::NewMyButton(int nID,CRect rect,int nStyle)<br />{<br />CString m_Caption;<br />m_Caption.LoadString( nID ); //取按钮标题<br />CButton *p_Button = new CButton();<br />ASSERT_VALID(p_Button);<br />p_Button-&gt;Create( m_Caption, WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | nStyle, rect, this, nID ); //创建按钮<br />return p_Button;<br />}</td></tr></tbody></table><br />　　其中m_Caption.LoadString( nID )是从字符串表中读取按钮文本，这样在创建按钮ID时，应该把文本设置好，参数nStyle为除必须风格外的额外风格。<br /><br />　　以下，调用该函数在ONINIATIAL中创建三个按钮，并指定第一个按钮为默认按钮，按钮的ID在STRING TABLE中已预先设置好了：<br /><br /><table width="90%" align="center" bgcolor="#dadacf" border="1" style="table-layout: auto !important;"><tbody><tr><td style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important;"><p><span style="color: #ff0000;">//CButton *p_MyBtn[3];//为了在后面释放资源，改为在类头文件中声明为</span></p><p><span style="color: #ff0000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //公有变量<br /></span>&nbsp;p_MyBtn[0]=NewMyButton(ID_MYBTN1,CRect(10,20,60,40),BS_DEFPUSHBUTTON);<br />&nbsp;p_MyBtn[1]=NewMyButton(ID_MYBTN2,CRect(10,50,60,70),0);<br />&nbsp;p_MyBtn[2]=NewMyButton(ID_MYBTN3,CRect(10,80,60,100),0);</p></td></tr></tbody></table><p>&nbsp;</p><p style="line-height: normal;">&nbsp;</p><p style="line-height: normal;"><strong><span style="color: #ff0000;">二、动态控件的响应：</span><br /><br />　　动态控件的响应函数不能用ClassWizard添加，只能手动添加。仍以上面的按钮为例，我们制作按钮的单击响应函数。<br /><br />　　1.在MESSAGE_MAP中添加响应函数：<br /><br />　　MESSAGE_MAP表中定义了消息响应函数，其格式为：消息名(ID,函数名)，当我们用ClassWizard添加函数时，会自动添加在AFX_MSG_MAP括起的区间内，如：<br /><br /></strong></p><p style="line-height: normal;"></p><table width="90%" align="center" bgcolor="#dadacf" border="1" style="table-layout: auto !important;"><tbody><tr><td style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important;">BEGIN_MESSAGE_MAP(CTextEditorView, CFormView)<br />//{{AFX_MSG_MAP(CTextEditorView)<br />ON_BN_CLICKED(IDC_ICONBUT0, OnIconbut0)<br />//}}AFX_MSG_MAP<br />END_MESSAGE_MAP()</td></tr></tbody></table><p>&nbsp;</p><p style="line-height: normal;">　<br />　　手工添加时不要添加到AFX_MSG_MAP区间内，以防ClassWizard不能正常工作，如：&nbsp;<br /><br /></p><p style="line-height: normal;"></p><table width="90%" align="center" bgcolor="#dadacf" border="1" style="table-layout: auto !important;"><tbody><tr><td style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important;">BEGIN_MESSAGE_MAP(CTextEditorView, CFormView)<br />//{{AFX_MSG_MAP(CTextEditorView)<br />ON_BN_CLICKED(IDC_ICONBUT0, OnIconbut0)<br />//}}AFX_MSG_MAP<br />ON_BN_CLICKED(ID_MYBTN1, OnMybtn1)<br />ON_BN_CLICKED(ID_MYBTN2, OnMybtn2)<br />ON_BN_CLICKED(ID_MYBTN3, OnMybtn3)<br />END_MESSAGE_MAP()</td></tr></tbody></table><p>&nbsp;</p><p style="line-height: normal;"><br />　　其中ON_BN_CLICKED是按钮单击消息。<br /><br />　　2.在头文件中添加函数定义：<br /><br />　　用ClassWizard添加函数时，会在头文件的AFX_MSG区间内添加函数定义，如：&nbsp;<br /><br /></p><p style="line-height: normal;"></p><table width="90%" align="center" bgcolor="#dadacf" border="1" style="table-layout: auto !important;"><tbody><tr><td style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important;">protected:<br />//{{AFX_MSG(CTextEditorView)<br />afx_msg void OnIconbut0();<br />//}}AFX_MSG<br />DECLARE_MESSAGE_MAP()</td></tr></tbody></table><p>&nbsp;</p><p style="line-height: normal;"><br />　　我们模仿这种形式，只是把函数定义添加到AFX_MSG区间外就行了：<br /><br /></p><p style="line-height: normal;"></p><table width="90%" align="center" bgcolor="#dadacf" border="1" style="table-layout: auto !important;"><tbody><tr><td style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important;">protected:<br />//{{AFX_MSG(CTextEditorView)<br />afx_msg void OnIconbut0();<br />//}}AFX_MSG<br />afx_msg void OnMybtn1();<br />afx_msg void OnMybtn2();<br />afx_msg void OnMybtn3();<br />DECLARE_MESSAGE_MAP()</td></tr></tbody></table><p>&nbsp;</p><p style="line-height: normal;"><br />　　3.编写消息响应函数：<br /><br />　　以上是把消息和函数关联起来了，具体在单击按钮后应做的工作在函数中完成：&nbsp;<br /><br /></p><p style="line-height: normal;"></p><table width="90%" align="center" bgcolor="#dadacf" border="1" style="table-layout: auto !important;"><tbody><tr><td style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important;">void CTextEditorView::OnMybtn1()<br />{<br />MessageBox( "哈！你单击了动态按钮。" );<br />}<br />void CTextEditorView::OnMybtn2()<br />{<br />&#8230;&#8230;<br />}<br />void CTextEditorView::OnMybtn3()<br />{<br />&#8230;&#8230;<br />}</td></tr></tbody></table><p>&nbsp;</p><p style="line-height: normal;"><br />　　除了按钮的响应函数外，你还可以用上面获得的指针访问按钮，如：<br /><br />　　修改按钮的大小和位置：p_MyBtn[0]-&gt;MoveWindow(&#8230;&#8230;);<br /><br />　　修改按钮文本：p_MyBtn[0]-&gt;SetWindowText(&#8230;&#8230;);<br /><br />　　显示/隐藏按钮：p_MyBtn[0]-&gt;ShowWindow(&#8230;&#8230;);等等。<br /></p><p style="line-height: normal;"><span style="color: #ff0000;">三、回收资源：<br /></span><br />　　由于动态控件对象是由new生成的，它不会被程序自动释放，所以需手工释放。在控件不再使用时可以删除它，在对话框中的析构函数中销毁（析构函数没有手动添加）：<br /><br /></p><p style="line-height: normal;"></p><table width="90%" align="center" bgcolor="#dadacf" border="1" style="table-layout: auto !important;"><tbody><tr><td style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important;"><p>CMonthCalCtrlDlg::~CMonthCalCtrlDlg()<br />{<br />&nbsp;for(int i=0;i&lt;3;i++)<br />&nbsp;&nbsp;&nbsp; {if(p_MyBtn[i])<br />&nbsp;&nbsp;&nbsp; &nbsp;delete p_MyBtn[i];</p><p>&nbsp;&nbsp;&nbsp; p_MyBtn[0]=NULL;//若采用其他方式释放，则加上这句，否则会出错<br />&nbsp;&nbsp;&nbsp; }<br />}</p></td></tr></tbody></table><p>&nbsp;</p><p style="line-height: normal;"><br />　　以上就是按钮控件动态生成的方法。</p></div></td></tr></tbody></table><img src ="http://www.cppblog.com/lanshengsheng/aggbug/199173.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lanshengsheng/" target="_blank">盛胜</a> 2013-04-07 14:36 <a href="http://www.cppblog.com/lanshengsheng/archive/2013/04/07/199173.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>vc 如何建动态按钮</title><link>http://www.cppblog.com/lanshengsheng/archive/2013/04/07/199172.html</link><dc:creator>盛胜</dc:creator><author>盛胜</author><pubDate>Sun, 07 Apr 2013 06:33:00 GMT</pubDate><guid>http://www.cppblog.com/lanshengsheng/archive/2013/04/07/199172.html</guid><wfw:comment>http://www.cppblog.com/lanshengsheng/comments/199172.html</wfw:comment><comments>http://www.cppblog.com/lanshengsheng/archive/2013/04/07/199172.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lanshengsheng/comments/commentRss/199172.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lanshengsheng/services/trackbacks/199172.html</trackback:ping><description><![CDATA[<p align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-size: 9pt;"><span style="color: #1e1e1e;"><span style="font-size: medium;">vc 如何建动态按钮</span></span></span></p><p align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-size: 9pt;">&nbsp;</span></p><p align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-size: 9pt;"><span style="color: #1e1e1e;"><span style="font-size: medium;">在类的定义中，定义如下变量</span></span></span></p><p align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-size: 9pt;"><span style="color: #1e1e1e;"></span></span></p><div bg_c-sharp"="" style="width: 687.046875px;"><div><div><strong>[c-sharp]</strong>&nbsp;<a href="http://blog.csdn.net/fanpeii/article/details/5820290#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/fanpeii/article/details/5820290#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 413px; top: 493px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">Cbutton&nbsp;m_btn;&nbsp;&nbsp;</li></ol></div><p>&nbsp;</p><p align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-size: 9pt;">&nbsp;</span></p><p align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-size: 9pt;"><span style="color: #1e1e1e;"><span style="font-size: medium;">那么在类的成员函数中就可以使用了如下来创建按钮。</span></span></span></p><p align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="color: #1e1e1e;"><span style="font-size: medium;"></span></span></p><div bg_c-sharp"="" style="width: 687.046875px;"><div><div><strong>[c-sharp]</strong>&nbsp;<a href="http://blog.csdn.net/fanpeii/article/details/5820290#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/fanpeii/article/details/5820290#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 413px; top: 632px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">m_btn.Create("动态创建的按钮",BS_DEFPUSHBUTTON|WS_VISIBLE|WS_CHILD,CRect(0,0,100,100),this,123);&nbsp;&nbsp;</li></ol></div><p>&nbsp;</p><p align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-size: 9pt;"><span style="color: #1e1e1e;"><span style="font-size: medium;">注，创建第二次的时候会出错。所以要用。</span></span></span></p><p align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="color: #1e1e1e;"></span></p><div bg_c-sharp"="" style="width: 687.046875px;"><div><div><strong>[c-sharp]</strong>&nbsp;<a href="http://blog.csdn.net/fanpeii/article/details/5820290#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">view plain</a><a href="http://blog.csdn.net/fanpeii/article/details/5820290#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat;">copy</a><div style="position: absolute; left: 413px; top: 763px; width: 18px; height: 18px; z-index: 99;"></div></div></div><ol start="1"><li style="line-height: 18px;">M_btn.&nbsp;DestroyWindow();&nbsp;&nbsp;</li></ol></div><p>&nbsp;</p><p align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="color: #1e1e1e;"><span style="font-size: medium;">来释放再进行创建。</span></span></p><p align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"></p><p align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="color: #1e1e1e;"><span style="font-size: medium;">借由这个动态创建，弄清了一些MFC的构架，MFC是基于所有的类而得出的成果，一个类派生与另一个基类，从CWnd到CDialog就是一个很好的例子。CDialog派生与CWnd。</span></span></p><p align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="color: #1e1e1e;"><span style="font-size: medium;">如果我要创建一个按钮，就必须用CDialog定义一个新的变量，这个变量就成了一个按钮，我就可以利用这个按钮类进行 各类操作，例如定义其的大小，风格。</span></span></p><p align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-size: 9pt;">&nbsp;</span></p><p align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-size: 9pt;"><span style="font-size: medium;">皆由此可见，所有的窗口都是一个类定义来的。无论是按钮，标签，ComBox，List等等，都可以使用这个方法进行创建。</span></span></p><p align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"></p><p align="left" style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-size: 9pt;"><span style="font-size: medium;">在编辑代码方面，VC与VB就有了，对于用户来说，就有了本质上的差别，VB的或许更加方便，而VC需要处理的细节太多了。<br /><br /><br /></span></span><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px;">//创建按钮&nbsp;</span><br style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px;" /><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px;">CButton &nbsp; *m_pBt1 &nbsp; = &nbsp; new &nbsp; CButton(); &nbsp; &nbsp;&nbsp;</span><br style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px;" /><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px;">ASSERT_VALID(m_pBt1);&nbsp;</span><br style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px;" /><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px;">m_pBt1-&gt; Create(_T("进入[A]"), &nbsp; WS_GROUP &#166;WS_CHILD &#166;WS_VISIBLE &#166;BS_PUSHBUTTON, &nbsp; CRect(10,10,20,20), &nbsp; this, &nbsp; IDC_AUTOCUT_POSTEACH &nbsp; ); &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><br style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px;" /><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px;">m_pBt1-&gt; MoveWindow(0, &nbsp; 152, &nbsp; 100, &nbsp; 100); &nbsp;&nbsp;</span><br style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px;" /><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px;">//修改风格 &nbsp;&nbsp;</span><br style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px;" /><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px;">HWND &nbsp; &nbsp; &nbsp; hwnd=m_pBt1-&gt; GetSafeHwnd(); &nbsp; &nbsp; &nbsp;&nbsp;</span><br style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px;" /><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px;">long &nbsp; &nbsp; &nbsp; lStyle=GetWindowLong(hwnd,GWL_EXSTYLE);&nbsp;</span><br style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px;" /><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px;">SetWindowLong(hwnd,GWL_EXSTYLE,lStyle &#166;WS_EX_DLGMODALFRAME); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><br style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px;" /><span style="color: #666666; font-family: 宋体, Arial; font-size: 12px;">::SetWindowPos(hwnd,0, &nbsp; 12, &nbsp; 55, &nbsp; 55, &nbsp; 111, &nbsp; SWP_NOREPOSITION &#166;SWP_NOACTIVATE &#166;SWP_NOMOVE &#166;SWP_FRAMECHANGED);</span></p><img src ="http://www.cppblog.com/lanshengsheng/aggbug/199172.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lanshengsheng/" target="_blank">盛胜</a> 2013-04-07 14:33 <a href="http://www.cppblog.com/lanshengsheng/archive/2013/04/07/199172.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DATETIME</title><link>http://www.cppblog.com/lanshengsheng/archive/2013/03/30/198944.html</link><dc:creator>盛胜</dc:creator><author>盛胜</author><pubDate>Sat, 30 Mar 2013 04:10:00 GMT</pubDate><guid>http://www.cppblog.com/lanshengsheng/archive/2013/03/30/198944.html</guid><wfw:comment>http://www.cppblog.com/lanshengsheng/comments/198944.html</wfw:comment><comments>http://www.cppblog.com/lanshengsheng/archive/2013/03/30/198944.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lanshengsheng/comments/commentRss/198944.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lanshengsheng/services/trackbacks/198944.html</trackback:ping><description><![CDATA[<div>&nbsp;//m_pdbado-&gt;GetFieldValue(_T("AccountCreateDate"),str);<br />			m_pdbado-&gt;GetFieldValue(_T("AccountCreateDate"),coledatetime);<br />			str&nbsp;=&nbsp;coledatetime.Format("%Y-%m-%d&nbsp;%H:%M:%S");<br />			if&nbsp;(str.size()&gt;64)<br />			{<br />				m_strError&nbsp;=&nbsp;"超过长度";<br />				//m_pdbado-&gt;CloseRecordset();<br />				return&nbsp;false;<br />			}<br />			strcpy_s(user_info.AccountCreateDate,64,str.c_str());<br />要用COleDateTime&nbsp;coledatetime;&nbsp;读取，再格式化&nbsp;</div><img src ="http://www.cppblog.com/lanshengsheng/aggbug/198944.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lanshengsheng/" target="_blank">盛胜</a> 2013-03-30 12:10 <a href="http://www.cppblog.com/lanshengsheng/archive/2013/03/30/198944.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MFC开线程</title><link>http://www.cppblog.com/lanshengsheng/archive/2013/03/30/198942.html</link><dc:creator>盛胜</dc:creator><author>盛胜</author><pubDate>Sat, 30 Mar 2013 02:18:00 GMT</pubDate><guid>http://www.cppblog.com/lanshengsheng/archive/2013/03/30/198942.html</guid><wfw:comment>http://www.cppblog.com/lanshengsheng/comments/198942.html</wfw:comment><comments>http://www.cppblog.com/lanshengsheng/archive/2013/03/30/198942.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lanshengsheng/comments/commentRss/198942.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lanshengsheng/services/trackbacks/198942.html</trackback:ping><description><![CDATA[<div>BOOL C*****::StartMakeing( void )</div><div>{</div><div><span style="white-space:pre">	</span>unsigned threadID = 0; &nbsp;&nbsp;</div><div><span style="white-space:pre">	</span>m_start = true;</div><div></div><div><span style="white-space:pre">	</span>m_hThread =(HANDLE) _beginthreadex(NULL, 0, MakeMontage, (LPVOID)this, 0, &amp;threadID );</div><div><span style="white-space:pre">	</span>return (m_start != NULL); &nbsp;&nbsp;</div><div>}<br /><br /><div>unsigned __stdcall&nbsp;C*****::MakeMontage( LPVOID lpParameter )</div><div>{</div><div><span style="white-space:pre">	</span>if(lpParameter)</div><div><span style="white-space:pre">	</span>{</div><div><span style="white-space:pre">		</span>C***** *pclient = (CDossierMontage*)lpParameter;</div><div><span style="white-space:pre">		</span>pclient-&gt;doMake();</div><div><span style="white-space:pre">	</span>}</div><div><span style="white-space:pre">	</span>return 0xdead;</div><div>}<br /><br /><div>void&nbsp;C*****::doMake( )</div></div></div><img src ="http://www.cppblog.com/lanshengsheng/aggbug/198942.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lanshengsheng/" target="_blank">盛胜</a> 2013-03-30 10:18 <a href="http://www.cppblog.com/lanshengsheng/archive/2013/03/30/198942.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MFC美化</title><link>http://www.cppblog.com/lanshengsheng/archive/2013/03/29/198925.html</link><dc:creator>盛胜</dc:creator><author>盛胜</author><pubDate>Fri, 29 Mar 2013 09:30:00 GMT</pubDate><guid>http://www.cppblog.com/lanshengsheng/archive/2013/03/29/198925.html</guid><wfw:comment>http://www.cppblog.com/lanshengsheng/comments/198925.html</wfw:comment><comments>http://www.cppblog.com/lanshengsheng/archive/2013/03/29/198925.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lanshengsheng/comments/commentRss/198925.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lanshengsheng/services/trackbacks/198925.html</trackback:ping><description><![CDATA[<div><span style="white-space: pre;">OnPain()<br />	</span>CPaintDC *pdc=&amp;dc;</div><div><span style="white-space:pre">	</span>CRect r;</div><div><span style="white-space:pre">	</span>GetClientRect(&amp;r);</div><div><span style="white-space:pre">	</span>CBitmap *pBitmap= new CBitmap;</div><div><span style="white-space:pre">	</span>BITMAP bm;</div><div><span style="white-space:pre">	</span></div><div><span style="white-space:pre">	</span>pBitmap-&gt;LoadBitmap(IDB_BG_NEW);</div><div><span style="white-space:pre">	</span>pBitmap-&gt;GetBitmap(&amp;bm);</div><div><span style="white-space:pre">	</span>CDC* pDisplayMemDC = new CDC;</div><div><span style="white-space:pre">	</span>pDisplayMemDC-&gt;CreateCompatibleDC(pdc);</div><div><span style="white-space:pre">	</span>pDisplayMemDC-&gt;SelectObject(pBitmap);</div><div><span style="white-space:pre">	</span>pdc-&gt;StretchBlt(r.left,r.top+30,r.Width(),r.Height()-30,pDisplayMemDC,</div><div><span style="white-space:pre">		</span>0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);</div><div><span style="white-space:pre">	</span>pBitmap-&gt;DeleteObject();<br /><br /><div><span style="white-space:pre">	</span>ReleaseDC(pdc);</div><div><span style="white-space:pre">	</span>ReleaseDC(pDisplayMemDC);<span style="white-space:pre">		</span></div><div><span style="white-space:pre">	</span>delete pDisplayMemDC;</div><div><span style="white-space:pre">	</span>delete pBitmap;<br /><br />OnCtlColor<br /><div><span style="white-space:pre">	</span>//修改窗口控件背景颜色</div><div><span style="white-space:pre">	</span>if (nCtlColor == CTLCOLOR_STATIC)</div><div><span style="white-space:pre">	</span>{</div><div><span style="white-space:pre">		</span>pDC-&gt;SetBkMode(TRANSPARENT);</div><div><span style="white-space:pre">		</span>pDC-&gt;SetTextColor(#dedede);</div><div><span style="white-space:pre">		</span>pDC-&gt;SetBkColor(#383838);</div><div><span style="white-space:pre">		</span>hbr = CreateSolidBrush(#383838);</div><div><span style="white-space:pre">	</span>}</div><div><span style="white-space:pre">	</span>if (nCtlColor == CTLCOLOR_EDIT)</div><div><span style="white-space:pre">	</span>{</div><div><span style="white-space:pre">		</span>pDC-&gt;SetTextColor(#dedede);</div><div><span style="white-space:pre">		</span>pDC-&gt;SetBkColor(#13344d);</div><div><span style="white-space:pre">		</span>hbr = CreateSolidBrush(#13344d);</div><div><span style="white-space:pre">	</span>}<br />OnEraseBkgnd<br /><div><span style="white-space:pre">	</span>CRect windowRect;</div><div><span style="white-space:pre">	</span>GetWindowRect(windowRect);</div><div><span style="white-space:pre">	</span>ScreenToClient(windowRect);</div><div><span style="white-space:pre">	</span>pDC-&gt;FillSolidRect(windowRect, #383838);</div><div><span style="white-space:pre">	</span>return TRUE;</div></div></div></div><img src ="http://www.cppblog.com/lanshengsheng/aggbug/198925.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lanshengsheng/" target="_blank">盛胜</a> 2013-03-29 17:30 <a href="http://www.cppblog.com/lanshengsheng/archive/2013/03/29/198925.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MFC第三方软件打开文件</title><link>http://www.cppblog.com/lanshengsheng/archive/2013/03/29/198924.html</link><dc:creator>盛胜</dc:creator><author>盛胜</author><pubDate>Fri, 29 Mar 2013 09:26:00 GMT</pubDate><guid>http://www.cppblog.com/lanshengsheng/archive/2013/03/29/198924.html</guid><wfw:comment>http://www.cppblog.com/lanshengsheng/comments/198924.html</wfw:comment><comments>http://www.cppblog.com/lanshengsheng/archive/2013/03/29/198924.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lanshengsheng/comments/commentRss/198924.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lanshengsheng/services/trackbacks/198924.html</trackback:ping><description><![CDATA[<div><span style="white-space:pre">		</span>if (PathFileExists(path))</div><div><span style="white-space:pre">		</span>{</div><div><span style="white-space:pre">			</span>CString tempStr;</div><div><span style="white-space:pre">			</span>tempStr.Format("shell32.dll,OpenAs_RunDLL %s",path);</div><div><span style="white-space:pre">			</span>int<span style="white-space:pre">	</span>isError=(int)ShellExecute(NULL, "open", "rundll32.exe ", tempStr, "", SW_SHOW);</div><div><span style="white-space:pre">			</span>if (isError&lt;32)</div><div><span style="white-space:pre">			</span>{</div><div><span style="white-space:pre">				</span>MessageBox("相应文件打开失败","提示");</div><div><span style="white-space:pre">			</span>}</div><div><span style="white-space:pre">		</span>}</div><div><span style="white-space:pre">		</span>else</div><div><span style="white-space:pre">		</span>{</div><div><span style="white-space:pre">			</span>MessageBox("文件路径有误！");</div><div><span style="white-space:pre">		</span>}</div><img src ="http://www.cppblog.com/lanshengsheng/aggbug/198924.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lanshengsheng/" target="_blank">盛胜</a> 2013-03-29 17:26 <a href="http://www.cppblog.com/lanshengsheng/archive/2013/03/29/198924.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MFC发送消息</title><link>http://www.cppblog.com/lanshengsheng/archive/2013/03/29/198923.html</link><dc:creator>盛胜</dc:creator><author>盛胜</author><pubDate>Fri, 29 Mar 2013 08:58:00 GMT</pubDate><guid>http://www.cppblog.com/lanshengsheng/archive/2013/03/29/198923.html</guid><wfw:comment>http://www.cppblog.com/lanshengsheng/comments/198923.html</wfw:comment><comments>http://www.cppblog.com/lanshengsheng/archive/2013/03/29/198923.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lanshengsheng/comments/commentRss/198923.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lanshengsheng/services/trackbacks/198923.html</trackback:ping><description><![CDATA[<div>关闭<br />SendMessage(WM_SYSCOMMAND, SC_CLOSE);<br />最小化<br /><div>SendMessage(WM_SYSCOMMAND, SC_MINIMIZE);<br />最大化<br /><div>SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE);<br />恢复原来大小<br /><div>SendMessage(WM_SYSCOMMAND, SC_RESTORE);<br />对话框接受拖动<br /><div>PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));</div><br /><br /><em style="font-family: arial, 宋体, sans-serif; line-height: 24px; text-indent: 30px; background-color: #ffffff;"><strong>B00L PostMessage（</strong>HWND<strong>hWnd，</strong>UINT<strong>Msg，</strong>WPARAM<strong>wParam，</strong>LPARAM<strong>lParam）；<br /></strong></em><div class="para" style="margin-bottom: 14px; text-indent: 30px; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff;"><strong>hWnd</strong>：其窗口程序接收消息的窗口的句柄。可取有特定含义的两个值：</div><div class="para" style="margin-bottom: 14px; text-indent: 30px; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff;"><em>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;HWND_BROADCAST</em>：消息被寄送到系统的所有顶层窗口，包括无效或不可见的非自身拥有的窗口、&nbsp;&nbsp;被覆盖的窗口和弹出式窗口。消息不被寄送到子窗口</div><div class="para" style="margin-bottom: 14px; text-indent: 30px; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff;"><em>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;NULL</em>：此函数的操作和调用参数dwThread设置为当前线程的<a target="_blank" href="http://baike.baidu.com/view/390932.htm" style="color: #136ec2;">标识符</a>PostThreadMessage函数一样</div><div class="para" style="margin-bottom: 14px; text-indent: 30px; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff;">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<strong>Msg</strong>：指定被寄送的消息。</div><div class="para" style="margin-bottom: 14px; text-indent: 30px; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff;"><strong>wParam</strong>：指定附加的消息特定的信息。</div><div class="para" style="margin-bottom: 14px; text-indent: 30px; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff;"><strong>IParam</strong>：指定附加的消息特定的信息。</div><div class="para" style="margin-bottom: 14px; text-indent: 30px; font-family: arial, 宋体, sans-serif; line-height: 24px; background-color: #ffffff;"><strong>返回值</strong>：如果<a target="_blank" href="http://baike.baidu.com/view/2369016.htm" style="color: #136ec2;">函数调用</a>成功，返回非零值：如果函数调用失败，返回值是零。若想获得更多的<a target="_blank" href="http://baike.baidu.com/view/627766.htm" style="color: #136ec2;">错误信息</a>，请调用GetLastError函数。</div><br /></div></div></div></div><img src ="http://www.cppblog.com/lanshengsheng/aggbug/198923.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lanshengsheng/" target="_blank">盛胜</a> 2013-03-29 16:58 <a href="http://www.cppblog.com/lanshengsheng/archive/2013/03/29/198923.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL查询数据库某个字段值个数</title><link>http://www.cppblog.com/lanshengsheng/archive/2013/03/26/198834.html</link><dc:creator>盛胜</dc:creator><author>盛胜</author><pubDate>Tue, 26 Mar 2013 06:16:00 GMT</pubDate><guid>http://www.cppblog.com/lanshengsheng/archive/2013/03/26/198834.html</guid><wfw:comment>http://www.cppblog.com/lanshengsheng/comments/198834.html</wfw:comment><comments>http://www.cppblog.com/lanshengsheng/archive/2013/03/26/198834.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lanshengsheng/comments/commentRss/198834.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lanshengsheng/services/trackbacks/198834.html</trackback:ping><description><![CDATA[<div>SELECT COUNT(1) AS RecordNum FROM (SELECT MonitoryPointID FROM casedatarel WHERE 1=1 AND Type = 1 GROUP BY MonitoryPointID)a</div><img src ="http://www.cppblog.com/lanshengsheng/aggbug/198834.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lanshengsheng/" target="_blank">盛胜</a> 2013-03-26 14:16 <a href="http://www.cppblog.com/lanshengsheng/archive/2013/03/26/198834.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VC中鼠标经过按钮弹出功能提示（TIPS)</title><link>http://www.cppblog.com/lanshengsheng/archive/2013/03/25/198797.html</link><dc:creator>盛胜</dc:creator><author>盛胜</author><pubDate>Mon, 25 Mar 2013 01:25:00 GMT</pubDate><guid>http://www.cppblog.com/lanshengsheng/archive/2013/03/25/198797.html</guid><wfw:comment>http://www.cppblog.com/lanshengsheng/comments/198797.html</wfw:comment><comments>http://www.cppblog.com/lanshengsheng/archive/2013/03/25/198797.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lanshengsheng/comments/commentRss/198797.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lanshengsheng/services/trackbacks/198797.html</trackback:ping><description><![CDATA[<span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">在VC中，也常常为一些图片按钮添加一些功能提示。</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">下面讲解实现过程：</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">该功能的实现主要是用CToolTipCtrl类。该类在VC&nbsp;</span><wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;"><wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;">&nbsp;<wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;"><wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;"><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">msdn中有详细说明。</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">首先</span><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">在对话框的头文件中加入初始化语句：public:下，加入：CToolTipCtrl&nbsp;</span><wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;"><wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;">&nbsp;<wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;"><wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;">&nbsp;<wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;"><wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;">&nbsp;<wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;"><wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;"><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">m_Mytip;</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">然后在初始化对话框函数中加入：</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">m_Mytip.Create(this);&nbsp;</span><wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;"><wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;">&nbsp;<wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;"><wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;"><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">m_Mytip.AddTool( GetDlgItem(IDC_BUTTON), "你想要添加的提示信息" ); //IDC_BUTTON为你要添加提示信息的按钮的ID</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">m_Mytip.SetDelayTime(200); //设置延迟</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">m_Mytip.SetTipTextColor( #0000ff ); //设置提示文本的颜色</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">m_Mytip.SetTipBkColor( #ffffff); //设置提示框的背景颜色</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">m_Mytip.Activate(TRUE); //设置是否启用提示</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">然后在类向导中添加PreTranslateMessage消息响应函数</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">BOOL CXXXDlg::PreTranslateMessage(MSG* pMsg)</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">{</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">// T</span><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">ODO: Add your specialized code here and/or call the base class</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" />&nbsp;<wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;"><wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;">&nbsp;<wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;"><wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;"><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">if(pMsg-</span><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">&gt;message==WM_MOUSEMOVE)</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" />&nbsp;<wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;"><wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;">&nbsp;<wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;"><wbr style="color: #464646; font-family: simsun; background-color: #bcd3e5;"><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">m_Mytip.RelayEvent(pMsg);</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">return CDialog::PreTranslateMessage(pMsg);</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">}</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">注：如果要为多个按钮添加功能提示只需在</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">m_Mytip.AddTool( GetDlgItem(IDC_BUTTON), "你想要添加的提示信息" );</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">的下面再加上类似语句，如</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">m_Mytip.AddTool( GetDlgItem(IDC_BUTTON1), "你想要添加的提示信息1" );</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">m_Mytip.AddTool( GetDlgItem(IDC_BUTTON2), "你想要添加的提示信息2" );</span><br style="color: #464646; font-family: simsun; background-color: #bcd3e5;" /><span style="color: #464646; font-family: simsun; background-color: #bcd3e5;">。。。。。。。。<br /><br /><br /></span><span style="color: #111111; font-family: arial; font-size: 12px; line-height: normal; background-color: #f5f5f5;">例子：<br /><br />声明：<br /></span><div>CToolTipCtrl m_Tip;<br /><br />初始化：<br /><div>BOOL C***Dlg::OnInitDialog()<br />{<br />省略部分。。。。。。。。。。<br /></div></div><div><span style="white-space:pre">	</span>//按钮浮动提示</div><div><span style="white-space:pre">	</span>m_Tip.Create(this);</div><div><span style="white-space:pre">	</span>m_Tip.AddTool(&amp;m_BtnPlay,"播放");</div><div><span style="white-space:pre">	</span>m_Tip.SetDelayTime(100);</div><div><span style="white-space:pre">	</span>m_Tip.Activate(TRUE);<br />}<br />类视图中重写：<br /><div>BOOL C****Dlg::PreTranslateMessage(MSG* pMsg)</div><div>{</div><div><span style="white-space:pre">	</span>// TODO: 在此添加专用代码和/或调用基类</div><div><span style="white-space:pre">	</span>m_Tip.RelayEvent(pMsg);<br />}</div></div><img src ="http://www.cppblog.com/lanshengsheng/aggbug/198797.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lanshengsheng/" target="_blank">盛胜</a> 2013-03-25 09:25 <a href="http://www.cppblog.com/lanshengsheng/archive/2013/03/25/198797.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>