I'm following a tutorial for MFC/C++ that regards automatic resizing of elements in a formview. Essentially, I want to have a CFormView dialog with elements that occupy the entire screen, no matter what the desktop resolution is, and elements that move around as the window is resized. I've found a tutorial that covers this:
Everything is working, except when I resize the window. That is to say that no matter what my desktop resolution is, my form fully fills it. However, when I resize the window, the elements don't move around to accommodate the new size of the window. I suspect this is due to this (from the tutorial):
sm was originally designed for dialogs where the dialog or parent-window and its controls, both have constant dimensions. A problem arises when you use the mechanism with CFormView. A CFormView resizes itself to fit into the area of the parent-window in which it is contained. Since this process happens before you can call InitAnchors(), the control-map will be empty and the controls will not be resized correctly.
A workaround for this is to use the flag ANIF_CALCSIZE when calling the InitAnchors-function. If you call InitAnchors(ANIF_CALCSIZE)
, then the InitAnchors-function will try to find the original size of the parent-window (your CFormView) by taking the bottom-right-most coordinate of all controls which are in the control-map."
I've used this ANIF_CALCSIZE argument, and everything works as described.
Here is my OnSize overloading function:
void CLustreView::OnSize(UINT nType, int cx, int cy)
CFormView::OnSize(nType, cx, cy);
I haven't forgotten to #include <atltypes.h>, the code compiles, but the elements still won't accommodate the size of the window.