CDialog中在最大化后Button随着改变位置

来源:互联网 发布:淘宝丝芙兰68折代购 编辑:程序博客网 时间:2024/06/06 02:28

   增加成员变量  bool m_ismax ;

                       CRect rect,m_rect;

   初始化   m_ismax = false;

 

 

在onsize中增加如下代码:

 

    CWnd *pWnd = GetDlgItem(IDC_START);


  if(pWnd!=NULL)     //刚开始的时候不会执行该if里边的东西,只有在点击最大化后才会执行
 {
  pWnd->GetWindowRect(&rect);
  ScreenToClient(&rect);

 

  //始终是相对于当前客户区来改变Button的位置

 

  if(true == m_ismax)   //现在是最大化,需要还原。
  {
   m_ismax = false;
   rect.left = cx - (m_rect.right - rect.right) - rect.Width();
   rect.right = cx - (m_rect.right - rect.right);
   pWnd->MoveWindow(rect.left,rect.top,rect.Width(),rect.Height());
  }

 

  if(nType == SIZE_MAXIMIZED)
  {


   if(false == m_ismax)    //现在还不是最大化,需要最大化。
   {


     rect.left = cx - (m_rect.right - rect.right) - rect.Width();
    rect.right = cx - (m_rect.right - rect.right);
    
    m_ismax = true;
    pWnd->MoveWindow(rect.left,rect.top,rect.Width(),rect.Height());

   }
  }

 

 }
  GetClientRect(&m_rect); 

   

 

   

原创粉丝点击