MFC Resizing controls

CoderSource.net
MFC Resizing controls
Rating:

Date: 5/1/2004 12:00:00 AM

   There are times when we need to dynamically resize the controls inside the Windows/Dialogs. This article tries to give a small sample of how to resize a Tree Control inside a CFormView derived class dynamically. This can then be extended to all other MFC Controls.
   The following article assumes the application is already created and Applications, dialogs and controls are in place. It tries to resize a Tree control dynamically whenever the ON_WM_SIZE message is dispatched to the Application.


void CControllerView::OnSize(UINT nType, int cx, int cy)
{
    CFormView::OnSize(nType, cx, cy);

    // Declare a CRect to get the co-ordinates
    CRect l_formRect;

    GetClientRect(&l_formRect);

    // get pointer to the control to be resized dynamically
    CTreeCtrl* pTreeCtrl;
    pTreeCtrl = (CTreeCtrl *)GetDlgItem(IDC_TREEFOLDER);

    //Calculate the new width of the control to be resized
    long newWidthTree = l_formRect.Width()/3;

    if(newWidthTree > 250)
       newWidthTree = 250;

    long newWidthTab = l_formRect.Width() - newWidthTree ;
    long newHeightTree = l_formRect.Height();

    // Now resize the control dynamically by calling MoveWindow
    pTreeCtrl->MoveWindow(l_formRect.TopLeft().x+5, l_formRect.TopLeft().y+25, (long)newWidthTree,     (long)newHeightTree-25, TRUE);


    // repaint control
    pTreeCtrl->RedrawWindow();
 }
}
 

You Can Rate this Article, if you are Logged In      
 

More Links from CoderSource.net:

 
Refer to a Friend:

Your Details:

Name:     e-mail:

Friend Details:

Name:    e-mail:    


MENU
Home
MFC 
C++
.Net
WIN32
Programming
Forum
My Articles
Add to Google
Add to My Yahoo!
Welcome to Codersource.Net Login | Register | Faq  

SEARCH
Google
 

NOTES:


Thanks for visiting our CoderSource.net. This site will be improved with more articles. Interested visitors can also submit their articles through the Submit Article link.Your article will also be published after due consideration by the editor. 

© Copyright 2003. All rights on content reserved by CoderSource.net. Contact    About Us