How to change the size and the position of controls in MFC?

How to change the size and the position of controls in MFC?

Anonymous
Not applicable
1,523 Views
1 Reply
Message 1 of 2

How to change the size and the position of controls in MFC?

Anonymous
Not applicable

Hi,everyone:

    I got some questions while using ARXWizardMFCSupport to create a DockControlBar. I attach a button to the ChildDialog, but the size and the position keep still while I change the size of the ChildDialog. Here is my code to change size and position of the button.

GetClientRect(&m_rect);  
void CMyDlg::ChangeSize(UINT nID, int x, int y) 
{
       CWnd *pWnd;
       pWnd=GetDlgItem(nID); 
       if(pWnd!=NULL)
       {
               CRect rec; 
               pWnd->GetWindowRect(&rec); 
               ScreenToClient(&rec);
               rec.left=rec.left*x/m_rect.Width();
               rec.top=rec.top*y/m_rect.Height();
               rec.bottom=rec.bottom*y/m_rect.Height();
               rec.right=rec.right*x/m_rect.Width();
               pWnd->MoveWindow(rec); 
      }
}

void CMyDlg::OnSize(UINT nType, int cx, int cy) 
{
            CDialog::OnSize(nType, cx, cy);
 
            // TODO: Add your message handler code here
            if(nType!=SIZE_MINIMIZED )
          {
                  ChangeSize(IDC_BUTTON1,cx,cy);              
                  GetClientRect(&m_rect); 
         }
}

I've refer to the help documentations, and found that the CAcUiDialog class was based on CDialog class, which was based on CWnd class, so the function should be called successfully.

Can anyone tell me what I could do to achieve my goal?

Thanks a lot!

0 Likes
Accepted solutions (1)
1,524 Views
1 Reply
Reply (1)
Message 2 of 2

thierry_prince
Advocate
Advocate
Accepted solution

Hi,

 

I'm not sure I understand what you really want to do.

 

If you want your button to be moved or resized when its parent window is moved or resized, then the AdUiDialog class (base class of AcUiDialog) has an internal mechanism to simplify this operation. Take a look at the methods MoveControl* and StretchControl*.

 

If not, sorry for the spam...

 

Cheers,

Thierry