?? 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 + -