3

I have a dialog resource with some controls inside, mostly a user and password edit controls, bonded to a CFormView. Such dialog is a small rectangle of 300 x 200 pixels.

When I run the application, the CFrameWindow occupies almost all screen, so the dialog shows in top-left corner. If I try to get the rectangle dimension of CFormView, I found that it has been expanded to visible area in CMainFrame, no matter the original dialog size.

What I currently get

My question is whether is possible to keep the dialog (the CFormView) centred in the middle of the CMainFrame, and keep always centred even if the ON_SIZE message is called.

What I want

Thank you.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Pablo
  • 557
  • 3
  • 16
  • 2
    I just did a quick search and see several. Eg: https://www.codeguru.com/cpp/misc/misc/article.php/c3765/Automatically-Center-the-Controls-in-CFormView.htm But I have no personal experience with this. What about adjusting the dynamic layout properties of the controls in the resource editor? – Andrew Truckle Mar 23 '21 at 19:39
  • 1
    I'd suggest that's not the desired solution. Better would be to make the frame smaller, and then center it. This answer shows how to make the frame smaller: https://stackoverflow.com/questions/20940927/how-does-one-resize-the-formdialog-in-a-mfc-sdi-cformview-application – Joseph Willcoxson Mar 23 '21 at 19:52
  • 1
    Probably in overriding RecalcLayout() in your frame class is where you want to intercept this. Working from memory here...and don't have a VC++ on this machine...but, the frame gets the view and resizes it to be the same size as the frame client area (well, close--area reserved for view after toolbars, etc, taken care of). You could have the formview be a child of another window and have that window center the formview. For instance, splitter windows are the child of the frame, and then views are children of the splitter window. – Joseph Willcoxson Mar 23 '21 at 20:35
  • 1
    You don't have to write any line of code. Just use the dynamic layout capabilities in VS2019 rc editor. – Tom Tom Mar 27 '21 at 21:37

1 Answers1

1

In VS2019 you don't have to write any line of code. The rc Editor has the dynamic layout function capabilities. Place the controls exactly in the middle of the dialog. Then set the

enter image description here

Tom Tom
  • 1,127
  • 11
  • 25