📄 subject_61814.htm
字号:
<p>
序号:61814 发表者:海底人 发表日期:2003-11-21 23:44:08
<br>主题:如何在对话框上加载自制工具栏?谢谢
<br>内容:请教高手:<BR> 我想在一个菜单项中弹出的对话框中加载自制的工具栏,可是显示对话框却没有工具栏。代码如下:<BR><BR>if (!m_Bar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||<BR> !m_Bar.LoadToolBar(IDR_BAR1))<BR> {<BR> TRACE0("Failed to create toolbar\n");<BR> return -1; // fail to create<BR>}<BR><BR>为何呢?是否还要重画工具栏呢?怎么做呢?谢谢高手。
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:hurtmanzc 回复日期:2003-11-21 23:51:00
<br>内容:在 OnInitDialog 中加入下面代码:<BR><BR> BOOL CYourDlg::OnInitDialog()<BR> {<BR> CDialog::OnInitDialog(); <BR><BR> // Create the toolbar. To understand the meaning of the styles used, you <BR> // can take a look at the MSDN for the Create function of the CToolBar class.<BR> ToolBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS |CBRS_FLYBY | CBRS_BORDER_BOTTOM);<BR><BR> // I have assumed that you have named your toolbar's resource as IDR_TOOLBAR1.<BR> // If you have given it a different name, change the line below to accomodate <BR> // that by changing the parameter for the LoadToolBar function.<BR> ToolBar.LoadToolBar(IDR_TOOLBAR1);<BR> <BR> CRect rcClientStart;<BR> CRect rcClientNow;<BR> GetClientRect(rcClientStart);<BR><BR> // To reposition and resize the control bar<BR> RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,0, reposQuery, rcClientNow);<BR> CPoint ptOffset(rcClientNow.left - rcClientStart.left,rcClientNow.top-rcClientStart.top);<BR><BR> CRect rcChild;<BR> CWnd* pwndChild = GetWindow(GW_CHILD);<BR><BR> while (pwndChild)<BR> {<BR> pwndChild->GetWindowRect(rcChild);<BR> ScreenToClient(rcChild);<BR> rcChild.OffsetRect(ptOffset);<BR> pwndChild->MoveWindow(rcChild, FALSE);<BR> pwndChild = pwndChild->GetNextWindow();<BR> }<BR><BR> CRect rcWindow;<BR> GetWindowRect(rcWindow);<BR> rcWindow.right += rcClientStart.Width() - rcClientNow.Width();<BR> rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();<BR> MoveWindow(rcWindow, FALSE); <BR><BR> // And position the control bars<BR> RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);<BR> <BR> return TRUE; // return TRUE unless you set the focus to a control<BR> }<BR> <BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:海底人 回复日期:2003-11-22 00:01:58
<br>内容:我在书上看到的也是这样,只是我想知道<BR> CRect rcClientStart;<BR> CRect rcClientNow;<BR> GetClientRect(rcClientStart);<BR>是什么意思?<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:michael 回复日期:2003-11-22 07:55:37
<br>内容: 获得客户区范围
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:hurtmanzc 回复日期:2003-11-22 10:21:59
<br>内容:由于工具条是动态加入的,其位置可能与原来对话框中控件冲突,因此在加入工具条后应该计算出加入工具条后剩余的用户区部分,并移动对话框中原有控件的位置。<BR><BR>CRect rcClientStart;//用于存放整个用户区<BR>CRect rcClientNow;//用于存放加入工具条后剩余的用户区<BR>GetClientRect(rcClientStart);//取得整个用户区并存放到<BR> //rcClientStart中<BR>//下面这个函数计算出加入工具条后剩余的用户区,并存放到<BR>//rcClientNow中,参考MSDN<BR>RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,0, reposQuery, rcClientNow);<BR> <BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:海底人 回复日期:2003-11-23 21:31:09
<br>内容:谢谢hurtmanzc和michael。你们真是太热心了。谢谢!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -