Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CFormView control sizing

CFormView control sizing

Scheduled Pinned Locked Moved C / C++ / MFC
c++csshelpquestion
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Manmohan29
    wrote on last edited by
    #1

    I have two views ( CMainView and CMembersView ) in my SDI application. The code below resizes my MFC GridCtrl according to size of app's window when the view is initialized. I get valid values for CRect grid_rect {top=0 bottom=952 left=0 right=1819} in CMainView. But in CMemberView I am having some undesired values.

    void CMembersView::OnInitialUpdate()
    {

    CFormView::OnInitialUpdate();
    
    
    initialized = TRUE;
    
    CWnd \*pGridCtrl = this->GetDlgItem(IDC\_MEMBERSGRID);
    ASSERT(pGridCtrl);		// Must exist
    
    CRect rect,grid\_rect;
    
    CWnd \*pWnd = this->GetOwner();
    pWnd->GetClientRect(rect);
    
    
    **pGridCtrl->GetWindowRect(grid\_rect); // problem is here. no grid\_rect coordinates
    

    // grid_rect {top=-32639 bottom=-32483 left=-32709 right=-31884} CRect**
    // some adjustments
    grid_rect = rect;
    grid_rect.left += 16;
    grid_rect.top += 150;
    grid_rect.bottom -= 300;
    grid_rect.right -= 16;

    pGridCtrl->MoveWindow(grid\_rect);
    

    Where am I going wrong ?

    Future Lies in Present. Manmohan Bishnoi

    X R 2 Replies Last reply
    0
    • M Manmohan29

      I have two views ( CMainView and CMembersView ) in my SDI application. The code below resizes my MFC GridCtrl according to size of app's window when the view is initialized. I get valid values for CRect grid_rect {top=0 bottom=952 left=0 right=1819} in CMainView. But in CMemberView I am having some undesired values.

      void CMembersView::OnInitialUpdate()
      {

      CFormView::OnInitialUpdate();
      
      
      initialized = TRUE;
      
      CWnd \*pGridCtrl = this->GetDlgItem(IDC\_MEMBERSGRID);
      ASSERT(pGridCtrl);		// Must exist
      
      CRect rect,grid\_rect;
      
      CWnd \*pWnd = this->GetOwner();
      pWnd->GetClientRect(rect);
      
      
      **pGridCtrl->GetWindowRect(grid\_rect); // problem is here. no grid\_rect coordinates
      

      // grid_rect {top=-32639 bottom=-32483 left=-32709 right=-31884} CRect**
      // some adjustments
      grid_rect = rect;
      grid_rect.left += 16;
      grid_rect.top += 150;
      grid_rect.bottom -= 300;
      grid_rect.right -= 16;

      pGridCtrl->MoveWindow(grid\_rect);
      

      Where am I going wrong ?

      Future Lies in Present. Manmohan Bishnoi

      X Offline
      X Offline
      xrg_soft 163 com
      wrote on last edited by
      #2

      The window size is never specified when you first call pGridCtrl->GetWindowRect(grid_rect); in the OnInitialUpdate. Please write some codelike below in your CMembersView::OnSize

      CWnd *pGridCtrl = this->GetDlgItem(IDC_MEMBERSGRID);
      ASSERT(pGridCtrl); // Must exist
      if ( ::IsWindow(pGridCtrl->GetSafeHwnd()) )
      {
      pGridCtrl->MoveWindow(..

      modified on Thursday, August 25, 2011 4:08 AM

      M 1 Reply Last reply
      0
      • M Manmohan29

        I have two views ( CMainView and CMembersView ) in my SDI application. The code below resizes my MFC GridCtrl according to size of app's window when the view is initialized. I get valid values for CRect grid_rect {top=0 bottom=952 left=0 right=1819} in CMainView. But in CMemberView I am having some undesired values.

        void CMembersView::OnInitialUpdate()
        {

        CFormView::OnInitialUpdate();
        
        
        initialized = TRUE;
        
        CWnd \*pGridCtrl = this->GetDlgItem(IDC\_MEMBERSGRID);
        ASSERT(pGridCtrl);		// Must exist
        
        CRect rect,grid\_rect;
        
        CWnd \*pWnd = this->GetOwner();
        pWnd->GetClientRect(rect);
        
        
        **pGridCtrl->GetWindowRect(grid\_rect); // problem is here. no grid\_rect coordinates
        

        // grid_rect {top=-32639 bottom=-32483 left=-32709 right=-31884} CRect**
        // some adjustments
        grid_rect = rect;
        grid_rect.left += 16;
        grid_rect.top += 150;
        grid_rect.bottom -= 300;
        grid_rect.right -= 16;

        pGridCtrl->MoveWindow(grid\_rect);
        

        Where am I going wrong ?

        Future Lies in Present. Manmohan Bishnoi

        R Offline
        R Offline
        Rage
        wrote on last edited by
        #3

        IIRC GetXXXRect take pointers as parameters. Have you tried with

        pGridCtrl->GetWindowRect(**&**grid_rect);

        Same comment for the GetClientRect call a few line above.

        M 1 Reply Last reply
        0
        • R Rage

          IIRC GetXXXRect take pointers as parameters. Have you tried with

          pGridCtrl->GetWindowRect(**&**grid_rect);

          Same comment for the GetClientRect call a few line above.

          M Offline
          M Offline
          Manmohan29
          wrote on last edited by
          #4

          This is working fine :-

          void CMainView::OnInitialUpdate() // CMainView is my application's default view
          {
          CFormView::OnInitialUpdate();

          initialized = TRUE;
          CWnd \*pGridCtrl = GetDlgItem(IDC\_SALEPURCHASEGRIDCTRL);
          CRect rect,grid\_rect;
          
          CWnd \*pWnd = this->GetOwner();
          pWnd->GetClientRect(rect);
          
          
          pGridCtrl->GetWindowRect(grid\_rect);     // works fine here
          grid\_rect = rect;
          grid\_rect.left += 16;
          grid\_rect.top += 150;
          grid\_rect.bottom -= 300;
          grid\_rect.right -= 16;
          
          pGridCtrl->MoveWindow(grid\_rect);        // GridCtrl is resized properly
          

          .
          .
          .

          This is not working properly:-

          void CMembersView::OnInitialUpdate()
          {

          CFormView::OnInitialUpdate();
          
          initialized = TRUE;
          CWnd \*pGridCtrl = this->GetDlgItem(IDC\_MEMBERSGRID);
          ASSERT(pGridCtrl);		// Must exist
          
          CRect rect,grid\_rect;
          
          CWnd \*pWnd = this->GetOwner();
          pWnd->GetClientRect(rect);                // Also tried with &rect
          
          pGridCtrl->GetWindowRect(grid\_rect); // problem is here. no grid\_rect coordinates.   Also tried with &grid\_rect
          grid\_rect = rect;
          grid\_rect.left += 16;
          grid\_rect.top += 150;
          grid\_rect.bottom -= 300;
          grid\_rect.right -= 16;
          
          pGridCtrl->MoveWindow(&grid\_rect);
          

          .
          .
          .

          --------------------------------------------- _" Future Lies in Present "_Manmohan Bishnoi

          R 1 Reply Last reply
          0
          • X xrg_soft 163 com

            The window size is never specified when you first call pGridCtrl->GetWindowRect(grid_rect); in the OnInitialUpdate. Please write some codelike below in your CMembersView::OnSize

            CWnd *pGridCtrl = this->GetDlgItem(IDC_MEMBERSGRID);
            ASSERT(pGridCtrl); // Must exist
            if ( ::IsWindow(pGridCtrl->GetSafeHwnd()) )
            {
            pGridCtrl->MoveWindow(..

            modified on Thursday, August 25, 2011 4:08 AM

            M Offline
            M Offline
            Manmohan29
            wrote on last edited by
            #5

            Doesn't help much.

            --------------------------------------------- _" Future Lies in Present "_Manmohan Bishnoi

            X 1 Reply Last reply
            0
            • M Manmohan29

              This is working fine :-

              void CMainView::OnInitialUpdate() // CMainView is my application's default view
              {
              CFormView::OnInitialUpdate();

              initialized = TRUE;
              CWnd \*pGridCtrl = GetDlgItem(IDC\_SALEPURCHASEGRIDCTRL);
              CRect rect,grid\_rect;
              
              CWnd \*pWnd = this->GetOwner();
              pWnd->GetClientRect(rect);
              
              
              pGridCtrl->GetWindowRect(grid\_rect);     // works fine here
              grid\_rect = rect;
              grid\_rect.left += 16;
              grid\_rect.top += 150;
              grid\_rect.bottom -= 300;
              grid\_rect.right -= 16;
              
              pGridCtrl->MoveWindow(grid\_rect);        // GridCtrl is resized properly
              

              .
              .
              .

              This is not working properly:-

              void CMembersView::OnInitialUpdate()
              {

              CFormView::OnInitialUpdate();
              
              initialized = TRUE;
              CWnd \*pGridCtrl = this->GetDlgItem(IDC\_MEMBERSGRID);
              ASSERT(pGridCtrl);		// Must exist
              
              CRect rect,grid\_rect;
              
              CWnd \*pWnd = this->GetOwner();
              pWnd->GetClientRect(rect);                // Also tried with &rect
              
              pGridCtrl->GetWindowRect(grid\_rect); // problem is here. no grid\_rect coordinates.   Also tried with &grid\_rect
              grid\_rect = rect;
              grid\_rect.left += 16;
              grid\_rect.top += 150;
              grid\_rect.bottom -= 300;
              grid\_rect.right -= 16;
              
              pGridCtrl->MoveWindow(&grid\_rect);
              

              .
              .
              .

              --------------------------------------------- _" Future Lies in Present "_Manmohan Bishnoi

              R Offline
              R Offline
              Rage
              wrote on last edited by
              #6

              Are the coordinate that should be returned by GetWindowRect really null ? What does the debugger says (if you look into the pGridCtrl structure) ? Have tried GetLastError ?

              M 1 Reply Last reply
              0
              • R Rage

                Are the coordinate that should be returned by GetWindowRect really null ? What does the debugger says (if you look into the pGridCtrl structure) ? Have tried GetLastError ?

                M Offline
                M Offline
                Manmohan29
                wrote on last edited by
                #7

                In CMainView :- grid_rect {top=-0 bottom=912 left=0 right=1819} CRect In CMembersView :- grid_rect {top=-32639 bottom=-32483 left=-32709 right=-31884} CRect

                --------------------------------------------- _" Future Lies in Present "_Manmohan Bishnoi

                R 1 Reply Last reply
                0
                • M Manmohan29

                  In CMainView :- grid_rect {top=-0 bottom=912 left=0 right=1819} CRect In CMembersView :- grid_rect {top=-32639 bottom=-32483 left=-32709 right=-31884} CRect

                  --------------------------------------------- _" Future Lies in Present "_Manmohan Bishnoi

                  R Offline
                  R Offline
                  Rage
                  wrote on last edited by
                  #8

                  Actually, you are overwriting grid_rect in the next part of the code with the content of rect, making the GetWindowRect call unnecessary. What if you comment out this line pGridCtrl->GetWindowRect(grid_rect); ? ( just to test if the MoveWindow is accepted).

                  M 1 Reply Last reply
                  0
                  • R Rage

                    Actually, you are overwriting grid_rect in the next part of the code with the content of rect, making the GetWindowRect call unnecessary. What if you comment out this line pGridCtrl->GetWindowRect(grid_rect); ? ( just to test if the MoveWindow is accepted).

                    M Offline
                    M Offline
                    Manmohan29
                    wrote on last edited by
                    #9

                    I use it to just test whether grid_rect fetches some values or not. Ok. I comment it out. But still it doesn't help.

                    --------------------------------------------- _" Future Lies in Present "_Manmohan Bishnoi

                    R 1 Reply Last reply
                    0
                    • M Manmohan29

                      I use it to just test whether grid_rect fetches some values or not. Ok. I comment it out. But still it doesn't help.

                      --------------------------------------------- _" Future Lies in Present "_Manmohan Bishnoi

                      R Offline
                      R Offline
                      Rage
                      wrote on last edited by
                      #10

                      Then I guess the OP was right and the structure/window is not initialized properly at this point of time. So either this is the standard behaviour, and you will have to initialize it in another event, or something goes wrong when creating the GridCtrl.

                      1 Reply Last reply
                      0
                      • M Manmohan29

                        Doesn't help much.

                        --------------------------------------------- _" Future Lies in Present "_Manmohan Bishnoi

                        X Offline
                        X Offline
                        xrg_soft 163 com
                        wrote on last edited by
                        #11

                        I guess you do not catch all my meaning. If you just set the grid position in OnInitialUpdate, then even it works. There still some problem after you resize your application. To make sure it works in all case, you must do it inside OnSize

                        CMembersView::OnSize:
                        CWnd *pGridCtrl = this->GetDlgItem(IDC_MEMBERSGRID);
                        ASSERT(pGridCtrl); // Must exist
                        if ( ::IsWindow(pGridCtrl->GetSafeHwnd()) )
                        {
                        // assume you need to move the grid to the left half of CMembersView
                        CRect rctClient;
                        this->GetClientRect(&rctClient);
                        pGridCtrl->MoveWindow(0, 0, rctClient.Width()/2, rctClient.Height());
                        }

                        modified on Thursday, August 25, 2011 10:19 AM

                        M 1 Reply Last reply
                        0
                        • X xrg_soft 163 com

                          I guess you do not catch all my meaning. If you just set the grid position in OnInitialUpdate, then even it works. There still some problem after you resize your application. To make sure it works in all case, you must do it inside OnSize

                          CMembersView::OnSize:
                          CWnd *pGridCtrl = this->GetDlgItem(IDC_MEMBERSGRID);
                          ASSERT(pGridCtrl); // Must exist
                          if ( ::IsWindow(pGridCtrl->GetSafeHwnd()) )
                          {
                          // assume you need to move the grid to the left half of CMembersView
                          CRect rctClient;
                          this->GetClientRect(&rctClient);
                          pGridCtrl->MoveWindow(0, 0, rctClient.Width()/2, rctClient.Height());
                          }

                          modified on Thursday, August 25, 2011 10:19 AM

                          M Offline
                          M Offline
                          Manmohan29
                          wrote on last edited by
                          #12

                          yes you were right. now code is working. thanks. :thumbsup:

                          --------------------------------------------- _" Future Lies in Present "_Manmohan Bishnoi

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups