📄 ctrls_in_tb.shtml.htm
字号:
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Author" CONTENT="Zafir Anjum">
<TITLE>ToolBar - Place Controls on ToolBars</TITLE>
</HEAD>
<body background="../fancyhome/back.gif" tppabs="http://www.codeguru.com/fancyhome/back.gif" bgcolor="#FFFFFF" link="#B50029" vlink="#8E2323" alink="#FF0000" bgproperties="fixed">
<table WIDTH="100%">
<tr WIDTH="100%">
<td><td>
</tr>
</table>
<CENTER>
<H3>
<FONT COLOR="#AOAO99">Place Controls on ToolBars</FONT></H3></CENTER>
<CENTER><H3><HR></H3></CENTER>
This article was contributed by <A HREF="mailto:rmore@cri.com">Randy More</A>.
<p>It is very easy (once you see how it is done) to place combo-boxes, edit boxes,
progress controls, etc. into toolbars. Below are two examples of this, in the first a
ComboBox is placed on a toolbar, and in the second a cluster of checkboxes is added. In
both cases the technique is the same:</p>
<p align="center"><b><font size="+3"><img src="ctrls_in_tb1.gif" tppabs="http://www.codeguru.com/toolbar/ctrls_in_tb1.gif" x-sas-useimagewidth x-sas-useimageheight align="bottom" width="365" height="24"></font></b> </p>
<p align="center"><b><font size="+3"><img src="ctrls_in_tb2.gif" tppabs="http://www.codeguru.com/toolbar/ctrls_in_tb2.gif" x-sas-useimagewidth x-sas-useimageheight align="bottom" width="410" height="24"></font></b> </p>
<p><b>Step 1</b>: Place a button on the toolbar in the spot where you want the control(s)
to eventually be. YOU MUST place a seperator on either side of the button!. Give the
button an easily remembered resource name such as IDP_PLACEHOLDER2 in the example below.</p>
<p><img src="ctrls_in_tb3.gif" tppabs="http://www.codeguru.com/toolbar/ctrls_in_tb3.gif" x-sas-useimagewidth x-sas-useimageheight align="bottom" width="306" height="151"></p>
<p><b>Step 2</b>: Derive a class from CToolBar and give it a member variable for the
control you will be creating. For the ComboBox example that class looks like this. No
extra methods are required, just a place for the instance of the control to live.</p>
<PRE><TT><FONT COLOR="#990000">
class CMainToolBar : public CToolBar
{
public:
CComboBox m_wndSnap;
};
</FONT></TT></PRE>
<p><b>Step 3:</b> In your main frame's .h file replace the instance of the CToolBar with
you new class. Be sure to add an include statement for the class definition created in
step 1.<br>
</p>
<p><font size="2" color="#990000"><big>protected: // control bar embedded members<br>
CStatusBar m_wndStatusBar;<br>
CMainToolBar m_wndToolBar;<br>
</big></font></p>
<p><b>Step 4:</b> At the end of your main frame's OnCreate method you replace the
placeholder button with your control as follows:<br>
</p>
<PRE><TT><FONT COLOR="#990000">
int SMCMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
牋
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -