大家好,我现在在对话框里加入了工具条,在对话框最大化时我想工具栏的位置跟着变化,我使用了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); 
     }}

解决方案 »

  1.   

    if(m_Wndtoolbar.GetSafeHwnd())   
           {   
                 
    CRect   rect;   
                    GetClientRect(&rect);    
    int x1=rect.Width();
        int y1=rect.Height();
                    m_Wndtoolbar.MoveWindow(0,0,x1,y1,FALSE);

     
           }   
      

  2.   

    http://m2.tech.topzj.com/thread-5159-1-1.html
      

  3.   

    在对话框大小变化中,重画对话框上的控件
    就是在OnSize函数中
      

  4.   

    m_Wndtoolbar.MoveWindow(0,0,x1,y1,TRUE);
      

  5.   

    得到控件句柄
    movewindow或者setwindowposition
      

  6.   

    void CWzdDlg::OnSize(UINT nType, int cx, int cy) 
    {
          CDialog::OnSize(nType, cx, cy);
          if (nType==SIZE_RESTORED)
          {
                if (::IsWindow(m_m_Wndtoolbar.m_hWnd))
                      m_Wndtoolbar.MoveWindow(0,0,x1,y1,FALSE);
          }
    }