大家好,我现在在对话框里加入了工具条,在对话框最大化时我想工具栏的位置跟着变化,我使用了onsize函数,但是我发现并没有效果,最大化时,工具栏位置不变保持原样,下面是部分代码,大家帮我看一下void CWzdDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy); // TODO: Add your message handler code here
if(m_Wndtoolbar.GetSafeHwnd())
{
CRect rect;
m_Wndtoolbar.GetClientRect(&rect);
int x1=rect.Width();
int y1=rect.Height();
m_Wndtoolbar.MoveWindow(0,0,x1,y1,FALSE);
}
else
{
//没有生成的话先生成
CRect rect;
this->GetClientRect(&rect);//得到整个对话框的大小!
int x=rect.Width();
int y=rect.Height();
if (!m_Wndtoolbar.CreateEx(this, TBSTYLE_FLAT,
WS_CHILD|WS_VISIBLE| CBRS_ALIGN_TOP|CBRS_GRIPPER|CBRS_TOOLTIPS,
CRect(10,y-93,0,0))||!m_Wndtoolbar.LoadToolBar(IDR_TOOLBAR1))
{
TRACE0("Failed to create Tool bar\n");
}
m_Wndtoolbar.ShowWindow(SW_SHOW);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
}}
{
CDialog::OnSize(nType, cx, cy); // TODO: Add your message handler code here
if(m_Wndtoolbar.GetSafeHwnd())
{
CRect rect;
m_Wndtoolbar.GetClientRect(&rect);
int x1=rect.Width();
int y1=rect.Height();
m_Wndtoolbar.MoveWindow(0,0,x1,y1,FALSE);
}
else
{
//没有生成的话先生成
CRect rect;
this->GetClientRect(&rect);//得到整个对话框的大小!
int x=rect.Width();
int y=rect.Height();
if (!m_Wndtoolbar.CreateEx(this, TBSTYLE_FLAT,
WS_CHILD|WS_VISIBLE| CBRS_ALIGN_TOP|CBRS_GRIPPER|CBRS_TOOLTIPS,
CRect(10,y-93,0,0))||!m_Wndtoolbar.LoadToolBar(IDR_TOOLBAR1))
{
TRACE0("Failed to create Tool bar\n");
}
m_Wndtoolbar.ShowWindow(SW_SHOW);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
}}
{
CRect rect;
GetClientRect(&rect);
int x1=rect.Width();
int y1=rect.Height();
m_Wndtoolbar.MoveWindow(0,0,x1,y1,FALSE);
}
就是在OnSize函数中
movewindow或者setwindowposition
{
CDialog::OnSize(nType, cx, cy);
if (nType==SIZE_RESTORED)
{
if (::IsWindow(m_m_Wndtoolbar.m_hWnd))
m_Wndtoolbar.MoveWindow(0,0,x1,y1,FALSE);
}
}