﻿<?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++博客-兴趣才是王道！-文章分类-ＶＣ＋＋</title><link>http://www.cppblog.com/iuhiao/category/7918.html</link><description>阿高不骗你</description><language>zh-cn</language><lastBuildDate>Fri, 15 Aug 2008 11:02:50 GMT</lastBuildDate><pubDate>Fri, 15 Aug 2008 11:02:50 GMT</pubDate><ttl>60</ttl><item><title>VC++之对话框中添加工具栏</title><link>http://www.cppblog.com/iuhiao/articles/58963.html</link><dc:creator>阿高</dc:creator><author>阿高</author><pubDate>Fri, 15 Aug 2008 10:58:00 GMT</pubDate><guid>http://www.cppblog.com/iuhiao/articles/58963.html</guid><wfw:comment>http://www.cppblog.com/iuhiao/comments/58963.html</wfw:comment><comments>http://www.cppblog.com/iuhiao/articles/58963.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/iuhiao/comments/commentRss/58963.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/iuhiao/services/trackbacks/58963.html</trackback:ping><description><![CDATA[<div id=td_content>
<p>1、添加工具栏资源ID为IDR_TOOLBAR<br>2、在对话框的类定义中加：<br>&nbsp;CToolBar m_ToolBar;<br>3、在OnInitDialog中或其它合适的消息响应中加如下代码：（函数可查看MSDN）<br>&nbsp;<br>&nbsp;m_ToolBar.Create(this);&nbsp;//创建工具栏<br>&nbsp;m_ToolBar.LoadToolBar(IDR_TOOLBAR);//加载工具栏<br>&nbsp;<br>&nbsp;//得出控件条大小.<br>&nbsp;CRect rect;<br>&nbsp;CRect rectNow;<br>&nbsp;GetClientRect(rect);<br>&nbsp;RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0,reposQuery,rectNow);</p>
<p>&nbsp;//放置控件条位置<br>&nbsp;CPoint ptOffset(rectNow.left-rect.left,rectNow.top-rect.top); </p>
<p>&nbsp;CRect&nbsp; rcChild;<br>&nbsp;CWnd* pwndChild=GetWindow(GW_CHILD);<br>&nbsp;while (pwndChild)<br>&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>&nbsp;&nbsp;pwndChild-&gt;GetWindowRect(rcChild);<br>&nbsp;&nbsp;ScreenToClient(rcChild);<br>&nbsp;&nbsp;rcChild.OffsetRect(ptOffset);<br>&nbsp;&nbsp;pwndChild-&gt;MoveWindow(rcChild,FALSE);<br>&nbsp;&nbsp;pwndChild=pwndChild-&gt;GetNextWindow();<br>&nbsp;}</p>
<p>&nbsp;//调整对话框尺寸<br>&nbsp;CRect rcWindow;<br>&nbsp;GetWindowRect(rcWindow);<br>&nbsp;rcWindow.right+=rect.Width()-rectNow.Width();<br>&nbsp;rcWindow.bottom+=rect.Height()-rectNow.Height();<br>&nbsp;MoveWindow(rcWindow, FALSE);<br>&nbsp;<br>&nbsp;//控件条定位<br>&nbsp;RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);<br>&nbsp;&nbsp;<br>&nbsp;//对框居中<br>&nbsp;CenterWindow();</p>
<p>4、手工添加处理函数<br>&nbsp;afx_msg void OnBtnXXX();//消息响应函数声明<br>&nbsp;ON_COMMAND(ID_BTN_XXX/*工具按钮ID*/,OnBtnXXX/*函数名*/)//消息映射<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void CXXXDlg::OnBtnXXX(){}//消息处理函数 </p>
</div>
<img src ="http://www.cppblog.com/iuhiao/aggbug/58963.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iuhiao/" target="_blank">阿高</a> 2008-08-15 18:58 <a href="http://www.cppblog.com/iuhiao/articles/58963.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VC++之对话框中添加状态栏</title><link>http://www.cppblog.com/iuhiao/articles/58962.html</link><dc:creator>阿高</dc:creator><author>阿高</author><pubDate>Fri, 15 Aug 2008 10:57:00 GMT</pubDate><guid>http://www.cppblog.com/iuhiao/articles/58962.html</guid><wfw:comment>http://www.cppblog.com/iuhiao/comments/58962.html</wfw:comment><comments>http://www.cppblog.com/iuhiao/articles/58962.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/iuhiao/comments/commentRss/58962.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/iuhiao/services/trackbacks/58962.html</trackback:ping><description><![CDATA[<p>对话框中添加状态栏方法： <br>&nbsp;&nbsp;&nbsp; 通过网上查资料和自己试验，发现以下两种方法：<br>一、<br>（1）在要添加状态栏的对话框类的类定义中 CStatusBarCtrl&nbsp;&nbsp;&nbsp;&nbsp; *m_StatBar;<br>（2）在OnInitDialog中或其它合适的消息响应中加如下代码：（函数可查看MSDN）<br>&nbsp;m_StatBar=new&nbsp;&nbsp; CStatusBarCtrl;<br>&nbsp;RECT&nbsp;&nbsp;&nbsp;&nbsp; m_Rect;&nbsp;&nbsp; <br>&nbsp; &nbsp;GetClientRect(&amp;m_Rect);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //获取对话框的矩形区域<br>&nbsp; &nbsp;m_Rect.top=m_Rect.bottom-20;&nbsp;&nbsp;&nbsp; //设置状态栏的矩形区域<br>&nbsp; &nbsp;m_StatBar-&gt;Create(WS_BORDER|WS_VISIBLE|CBRS_BOTTOM,m_Rect,this,3);&nbsp;&nbsp; </p>
<p>&nbsp;int nParts[4]= {100, 200, 300,-1};&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //分割尺寸<br>&nbsp;m_StatBar-&gt;SetParts(4, nParts); &nbsp;//分割状态栏<br>&nbsp;m_StatBar-&gt;SetText("这是第一个指示器",0,0); //第一个分栏加入"这是第一个指示器"<br>&nbsp;m_StatBar-&gt;SetText("这是第二个指示器",1,0); //以下类似<br>&nbsp;/*也可使用以下方式加入指示器文字<br>&nbsp;m_StatBar.SetPaneText(0,"这是第一个指示器",0);<br>&nbsp;其他操作：m_StatBar-&gt;SetIcon(3,SetIcon(AfxGetApp()-&gt;LoadIcon(IDI_ICON3),FALSE));<br>&nbsp;//在第四个分栏中加入ID为IDI_ICON3的图标<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *********************************************/</p>
<p>&nbsp;m_StatBar-&gt;ShowWindow(SW_SHOW); <br>二、<br>（1）在对话框类的.cpp源文件的开头加上如下代码：<br>&nbsp;static UINT BASED_CODE indicators[]=&nbsp;&nbsp; <br>&nbsp;//状态栏的指示器列表，如有未定义的字符串名，需在Resource View的String Table中添加定义<br>&nbsp; &nbsp;{<br>&nbsp;&nbsp;&nbsp; &nbsp; ID_INDICATOR_CAPS,<br>&nbsp;&nbsp; &nbsp; ID_INDICATOR_NUM,<br>&nbsp; ID_INDICATOR_USER,//需在Resource View的String Table中添加定义<br>&nbsp; &nbsp;};<br>（2）在要添加状态栏的对话框类的类定义中 CStatusBarCtrl&nbsp; m_StatusBar;<br>（3）在OnInitDialog中或其它合适的消息响应中加如下代码：<br>&nbsp;//不能是突出和无边框风格<br>&nbsp;m_StatusBar.CreateEx(this,SBT_TOOLTIPS,WS_CHILD | WS_VISIBLE | CBRS_BOTTOM,AFX_IDW_STATUS_BAR );<br>&nbsp;m_StatusBar.SetIndicators(indicators,sizeof(indicators)/sizeof(UINT));//设置指示器数量<br>&nbsp;&nbsp;CRect rect;<br>&nbsp;&nbsp;&nbsp; &nbsp;GetClientRect(&amp;rect);</p>
<p>&nbsp;&nbsp;m_StatusBar.SetPaneInfo(0,ID_INDICATOR_CAPS,SBPS_NORMAL,rect.Width()/3);//设置指示器窗口的有关信息<br>&nbsp; &nbsp;m_StatusBar.SetPaneInfo(1,ID_INDICATOR_NUM,SBPS_STRETCH ,rect.Width()/3);</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,ID_INDICATOR_CAPS);//很重要****<br>&nbsp;&nbsp;&nbsp; &nbsp;m_StatusBar.GetStatusBarCtrl().SetBkColor(RGB(180,20,180));//设置背景<br>&nbsp;&nbsp;m_StatusBar.SetPaneText(0,"指示器1",0);<br>&nbsp;&nbsp;m_StatusBar.SetPaneText(1,"指示器2",0);</p>
<img src ="http://www.cppblog.com/iuhiao/aggbug/58962.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/iuhiao/" target="_blank">阿高</a> 2008-08-15 18:57 <a href="http://www.cppblog.com/iuhiao/articles/58962.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>