resize a CFormView programmatically
-
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!
-
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!
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
-
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
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(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!
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 ofAfxGetMainWnd()->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
-
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 ofAfxGetMainWnd()->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
I'll try that when I get home. Thanks!
-
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
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.