Now: Tutorial for Web and Software Design > Programming > c > Programming Content
> MFC Resizing controls [Bookmark it]
MFC Resizing controls
   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();
 }
}
 

[Bookmark][Print] [Close][To Top]
  • Prev Article-Programming:

  • Next Article-Programming:
  • Related Materias
    Crystal Reports Tutorial -
    Creating a Toolbar - Visua
    Visual Basic Explorer - Tu
    Win32 program to create di
    CreateNamedPipe - Creating
    Win32 dll Creation and usa
    Preventing Cross-site Scri
    Using Microsoft Data Acces
    Disabling Mouse clicks whi
    Creating Custom Controls i
    Topics
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Graphic Design Tutorial
     

    Coreldraw Tutorial

      Illustrator Tutorial
      3D Graphics Articles
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial&Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial&Articles
     

    XML Style Tutorial

      AJAX Tutorial
      XML Mobile
    Flash Tutorial&Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial&Articles
     

    Linux Tutorial

      Symbian Tutorial
      MacOS Tutorial