您的位置:首页 > 编程语言 > C语言/C++

VC++之对话框中添加工具栏

2012-01-18 13:23 190 查看
1、添加工具栏资源ID为IDR_TOOLBAR

2、在对话框的类定义中加:

CToolBarm_ToolBar;

3、在OnInitDialog中或其它合适的消息响应中加如下代码:(函数可查看MSDN)

01
m_ToolBar.Create(
this
);
//创建工具栏
02
m_ToolBar.LoadToolBar(IDR_TOOLBAR);
//加载工具栏
03
04
//得出控件条大小.
05
CRectrect;
06
CRectrectNow;
07
GetClientRect(rect);
08
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0,reposQuery,rectNow);
09
10
//放置控件条位置
11
CPointptOffset(rectNow.left-rect.left,rectNow.top-rect.top);
12
13
CRectrcChild;
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
CRectrcWindow;
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
void
OnBtnXXX();
//消息响应函数声明
2
ON_COMMAND(ID_BTN_XXX
/*工具按钮ID*/
,OnBtnXXX
/*函数名*/
)
//消息映射
3
void
CXXXDlg::OnBtnXXX(){}
//消息处理函数
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: