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. resize a CFormView programmatically

resize a CFormView programmatically

Scheduled Pinned Locked Moved C / C++ / MFC
career
6 Posts 2 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.
  • H Offline
    H Offline
    Harold Bamford
    wrote on last edited by
    #1

    Greetings, I am trying to change the size of a FormView application after I have resized a control and I must be missing something essential. I can get the window to resize (smaller), but then scroll bars appear that weren't there before. I suspect it is something inherent to how a FormView works as when I resize smaller manually, the scroll bars appear even though no controls are obscured. I suspect I have some setting in the FormView wrong since it doesn't behave with manual resizing. Anyway... My current approach is to call AfxGetMainWnd()->GetWindowPos(), adjust the values and then call SetWindowPos(). Then I call ResizeParentToFit() which almost does the job. Here is a code fragment. The control involved is a CListCtrl...

    WINDOWPLACEMENT wpMain, wpOldList;
    AfxGetMainWnd()->GetWindowPlacement(&wpMain);
    m_RecordList.GetWindowPlacement(&wpOldList);

    ... make the size and content changes to the list ...

    WINDOWPLACEMENT wpNewList;
    m_RecordList.GetWindowPlacement(&wpNewList);

    int sizeChange = wpOldList.rcNormalPosition.right - wpNewList.rcNormalPosition.right;
    wpMain.rcNormalPosition.right -= sizeChange;
    AfxGetMainWnd()->SetWindowPlacement(&wpMain);
    ResizeParentToFit();

    Any hints would be greatly appreciated. Thanks!

    K 1 Reply Last reply
    0
    • H Harold Bamford

      Greetings, I am trying to change the size of a FormView application after I have resized a control and I must be missing something essential. I can get the window to resize (smaller), but then scroll bars appear that weren't there before. I suspect it is something inherent to how a FormView works as when I resize smaller manually, the scroll bars appear even though no controls are obscured. I suspect I have some setting in the FormView wrong since it doesn't behave with manual resizing. Anyway... My current approach is to call AfxGetMainWnd()->GetWindowPos(), adjust the values and then call SetWindowPos(). Then I call ResizeParentToFit() which almost does the job. Here is a code fragment. The control involved is a CListCtrl...

      WINDOWPLACEMENT wpMain, wpOldList;
      AfxGetMainWnd()->GetWindowPlacement(&wpMain);
      m_RecordList.GetWindowPlacement(&wpOldList);

      ... make the size and content changes to the list ...

      WINDOWPLACEMENT wpNewList;
      m_RecordList.GetWindowPlacement(&wpNewList);

      int sizeChange = wpOldList.rcNormalPosition.right - wpNewList.rcNormalPosition.right;
      wpMain.rcNormalPosition.right -= sizeChange;
      AfxGetMainWnd()->SetWindowPlacement(&wpMain);
      ResizeParentToFit();

      Any hints would be greatly appreciated. Thanks!

      K Offline
      K Offline
      KaRl
      wrote on last edited by
      #2

      I'm not sure to understand, so I hope I won't provide a bad answer. As I understand it, you want to force the size of your application. I would do so by resizing the MainFrame object, using CMainFrame::SetWindowPos. Then I would catch the WM_SIZE message in the Form View to handle controls size and position changes. Oh, and you can manage the way your view handles scroll bars by overring CScrollView::SetScrollSizes. HTH,


      Fold With Us! Chaos A.D. Disorder unleashed

      H 2 Replies Last reply
      0
      • K KaRl

        I'm not sure to understand, so I hope I won't provide a bad answer. As I understand it, you want to force the size of your application. I would do so by resizing the MainFrame object, using CMainFrame::SetWindowPos. Then I would catch the WM_SIZE message in the Form View to handle controls size and position changes. Oh, and you can manage the way your view handles scroll bars by overring CScrollView::SetScrollSizes. HTH,


        Fold With Us! Chaos A.D. Disorder unleashed

        H Offline
        H Offline
        Harold Bamford
        wrote on last edited by
        #3

        K(arl) wrote: As I understand it, you want to force the size of your application. I would do so by resizing the MainFrame object, using CMainFrame::SetWindowPos. Then I would catch the WM_SIZE message in the Form View to handle controls size and position changes. Yes, I want to set the size of the application. I've tried using SetWindowPos(), but it works no better. Catching the OnSize stuff would not help as the control has already been sized; there is nothing to be done. Manually (or rather programatically) adjusting the scroll bar is something I would like to avoid. For now, I am using a kludge by setting the original size of the Formview and the control that gets resized (in the visual dialog editor) to something absurdly small. Then when I load up the control and resize it, I can also resize the MainFrame and it seems to work. No annoying, unneeded scrollbars appear. But this seems like an inelegant solution. Surely there is a better way!

        K 1 Reply Last reply
        0
        • H Harold Bamford

          K(arl) wrote: As I understand it, you want to force the size of your application. I would do so by resizing the MainFrame object, using CMainFrame::SetWindowPos. Then I would catch the WM_SIZE message in the Form View to handle controls size and position changes. Yes, I want to set the size of the application. I've tried using SetWindowPos(), but it works no better. Catching the OnSize stuff would not help as the control has already been sized; there is nothing to be done. Manually (or rather programatically) adjusting the scroll bar is something I would like to avoid. For now, I am using a kludge by setting the original size of the Formview and the control that gets resized (in the visual dialog editor) to something absurdly small. Then when I load up the control and resize it, I can also resize the MainFrame and it seems to work. No annoying, unneeded scrollbars appear. But this seems like an inelegant solution. Surely there is a better way!

          K Offline
          K Offline
          KaRl
          wrote on last edited by
          #4

          I suppose the code you indicated is in a method of the Form View, right? Did you try to resize the view using /*CFormView::*/SetWindowPos() instead of AfxGetMainWnd()->SetWindowPos() (which would resize the main frame) and then calling ResizeParentToFit which should resize the Main Frame according to the size of the view?


          Fold With Us! Chaos A.D. Disorder unleashed

          H 1 Reply Last reply
          0
          • K KaRl

            I suppose the code you indicated is in a method of the Form View, right? Did you try to resize the view using /*CFormView::*/SetWindowPos() instead of AfxGetMainWnd()->SetWindowPos() (which would resize the main frame) and then calling ResizeParentToFit which should resize the Main Frame according to the size of the view?


            Fold With Us! Chaos A.D. Disorder unleashed

            H Offline
            H Offline
            Harold Bamford
            wrote on last edited by
            #5

            I'll try that when I get home. Thanks!

            1 Reply Last reply
            0
            • K KaRl

              I'm not sure to understand, so I hope I won't provide a bad answer. As I understand it, you want to force the size of your application. I would do so by resizing the MainFrame object, using CMainFrame::SetWindowPos. Then I would catch the WM_SIZE message in the Form View to handle controls size and position changes. Oh, and you can manage the way your view handles scroll bars by overring CScrollView::SetScrollSizes. HTH,


              Fold With Us! Chaos A.D. Disorder unleashed

              H Offline
              H Offline
              Harold Bamford
              wrote on last edited by
              #6

              K(arl) wrote: As I understand it, you want to force the size of your application. I would do so by resizing the MainFrame object, using CMainFrame::SetWindowPos. Then I would catch the WM_SIZE message in the Form View to handle controls size and position changes. Oh, and you can manage the way your view handles scroll bars by overring CScrollView::SetScrollSizes. OK, now I understand what you meant. What I am doing now is use WindowSetPos() and SetScrollSizes. Pretty much as you suggested. I didn't understand from the documentation what SetScrollSizes did. It just sets the the threhold for window size for when the scrollbars appear. Which is what I needed. Thanks for your help.

              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