offsetrect,添加对话框后如何添加控件栏?
1、添加工具栏资源ID为IDR_TOOLBAR2、在对话框的类定义中加:
CToolBar m_ToolBar;
3、在OnInitDialog中或其它合适的消息响应中加如下代码:(函数可查看MSDN)
01 m_ToolBar.Create(this);//创建工具栏
02 m_ToolBar.LoadToolBar(IDR_TOOLBAR);//加载工具栏
03
04 //得出控件条大小.
05 CRect rect;
06 CRect rectNow;
07 GetClientRect(rect);
08 RepositionBars(afx_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0,reposQuery,rectNow);
09
10 //放置控件条位置
11 CPoint ptOffset(rectNow.left-rect.left,rectNow.top-rect.top);
12
13 CRect rcChild;
14 CWnd* pwndChild=GetWindow(GW_CHILD);
15 while(pwndChild)
16 {
17 pwndChild->GetWindowRect(rcChild);
18 ScreenToClient(rcChild);
19 rcChild.OffsetRect(ptOffset);
20 pwndChild->MoveWindow(rcChild,FALSE);
21 pwndChild=pwndChild->GetNextWindow();
22 }
23
24 //调整对话框尺寸
25 CRect rcWindow;
26 GetWindowRect(rcWindow);
27 rcWindow.right+=rect.Width()-rectNow.Width();
28 rcWindow.bottom+=rect.Height()-rectNow.Height();
29 MoveWindow(rcWindow, FALSE);
30
31 //控件条定位
32 RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
33
34 //对框居中
35 CenterWindow();
4、手工添加处理函数
1 afx_msg voidOnBtnXXX();//消息响应函数声明
2 ON_COMMAND(ID_BTN_XXX/*工具按钮ID*/,OnBtnXXX/*函数名*/)//消息映射
3 voidCXXXDlg::OnBtnXXX(){}//消息处理函数
还没有评论,来说两句吧...