How to change the properties of the main window in a program created by MFC
Excerpt from: http://blog.sina.com.cn/s/blog_4bebc4830100aq1m.html
In the single-document interface created by MFC:
(Based on the dialog box, add the PreCreateWindow function directly inside the virtual function in the dialog box's Class wizard, but there is actually no use to try.) Thank you for your test. )
Add the following code in CMainFrame::P Recreatewindow (createstruct& cs) to fix the window size
Cs.style = ws_overlapped | Ws_sysmenu | ws_minimizebox;//| Ws_thickframe;
Cs.style &= ~ws_border;
Cs.dwexstyle &= ~ws_ex_clientedge;
int Iwinborderx = GetSystemMetrics (Sm_cxborder);
int iwinbordery = GetSystemMetrics (Sm_cyborder);
int icaptiony = GetSystemMetrics (sm_cycaption);
int imenuy = GetSystemMetrics (Sm_cymenu);
int istausy = GetSystemMetrics (Sm_cymenu);
CS.CX = 510 + Iwinborderx;
cs.cy = 530 + iwinbordery + icaptiony + istausy + imenuy;
In the code above:
The first three lines determine the window style. | means add style, "&~" means to remove the style. Four to eight rows use the function GetSystemMetrics to get some system data, in pixels. Finally, the width and height of the window are calculated.
Style:
Ws_overlapped has title
Ws_sysmenu has a system menu: Minimize, Maximize, and close
Ws_minimizebox can minimize the window
Ws_thickframe can be dragged to change the window size
Ws_border with black border
Ws_maximizebox can maximize the window
dwExStyle:
Ws_ex_clientedge extended attributes with shaded borders
getsystemmetrics parameter:
SM_CMOUSEBUTTONS return value is the number of mouse keys supported by the system and returns 0, the mouse is not installed on the system.
Sm_cxborder, sm_cyborder returns the width and height of the Windows window border, in pixels, equivalent to the Sm_cxedge parameter
If Windows is in 3D form Sm_cxcursor, Sm_cycursor Returns the width and height of the standard cursor in pixel values
Sm_cxdlgframe, sm_cydlgframe equivalent, and sm_ Cxfixedframe and Sm_cyfixedframe
Sm_cxdoubleclk, sm_cydoubleclk double-click a valid rectangular area in pixel value
Sm_ Cxedge, sm_cyedge width and height of 3D borders in pixel values
Sm_cxfixedframe, sm_cyfixedframe The thickness of the border around a window that has a title but cannot resize (usually some dialog boxes)
Sm_cxframe, sm_cyframe equals Sm_cxsizeframe and Sm_cysizeframe The width and height of the window area of the
Sm_cxfullscreen, sm_cyfullscreen full-screen window
Sm_cxhscroll, sm_cyhscroll The height of the horizontal scrollbar and the width of the arrows on the horizontal scrollbar
sm_cxhthumb the width of the slider on the horizontal scroll bar in pixels
Sm_cxicon, sm_cyicon system default icon height and width (typically 32*32)
Sm_cxiconspacing, sm_cyiconspacing the space between icons when viewing item with a large icon, This distance is always greater than or equal to
sm_cxmaximized, sm_cymaximized The default size of the maximized window at the top level
Sm_cxmaxtrack, Sm_cymaxtrack has the default maximum size of the window that can change the size border and title bar, and if the window is larger than this, the window is not movable.
Sm_cxmenucheck, Sm_cymenucheck the dimensions of the menu check mark bitmap that is calculated in pixels
Sm_cxmenusize, sm_cymenusize the size of the menu bar button calculated in pixels
Sm_cxmin, sm_cymin window can achieve the smallest size
Sm_cxminimized, sm_cyminimized the size of the normal minimized window
Sm_cxmintrack, sm_cymintrack minimum tracking distance, the window will not move when the user drags the distance less than this value.
Sm_cxscreen, sm_cyscreen the screen size calculated in pixels.
Sm_cxsize, sm_cysize the size of the title bar button calculated in pixels
Sm_cxsizeframe, sm_cysizeframe the thickness of the border around the window that can change size
Sm_cxsmicon, Sm_cysmicon the size of small icons in pixels, and small icons generally appear on the window's title bar.
Sm_cxvscroll, Sm_cyvscroll the width of the vertical scrollbar calculated in pixels and the height of the arrows on the vertical scroll bar
Sm_cycaption the height of a normal window caption calculated in pixels
Sm_cymenu the height of a single menu bar calculated in pixels
Sm_cysmcaption the height of the small title bar of a window calculated in pixels
Sm_cyvthumb the height of a scroll block in a vertical scrollbar calculated in pixels
sm_dbcsenabled if a value of true or not 0 indicates that the system has a double-byte version of USER.EXE installed, false or 0 is not.
Sm_debug if the value of TRUE or not 0 indicates that the system has a DEBUG version of USER.EXE installed, false or 0 is not.
Sm_menudropalignment if the value is true or not 0, the drop-down menu is right-aligned or left-aligned.
Sm_mousepresent if a value of true or not 0 is installed, the mouse is not installed.
Sm_mousewheelpresent a Wheel Mouse is installed if the value is true or not 0, otherwise it is not installed. (Windows NT only)
Sm_swapbutton if TRUE or not a value of 0 then the mouse key is exchanged or not.
Parent window Ws_clipchildren style effects on child window refreshes
Excerpt from: http://www.cppblog.com/zaccheo/articles/180331.html
Write the following program, test the parent window before and after setting Ws_clipchildren, the parent window call RedrawWindow or InvalidateRect child window Refresh effect
Operation |
have a Ws_clipchildren |
No Ws_clipchildren |
InvalidateRect |
Invalid zone increase for parent window No effect on child window |
Invalid zone increase for parent window Invalid area of child window increased and the invalid area coordinates are the same (in screen coordinate system) |
RedrawWindow Flag:rdw_invalidate |
Invalid zone increase for parent window No effect on child window |
Invalid zone increase for parent window Invalid area of child window increased and the invalid area coordinates are the same (in screen coordinate system) |
RedrawWindow flag:rdw_invalidate| Rdw_allchildren |
Invalid zone increase for parent window Invalid area of child window increased and the invalid area coordinates are the same (in screen coordinate system) |
Invalid zone increase for parent window Invalid area of child window increased and the invalid area coordinates are the same (in screen coordinate system) |
RedrawWindow flag:rdw_invalidate| Rdw_nochildren |
Invalid zone increase for parent window No effect on child window |
Invalid zone increase for parent window No effect on child window |
Other Windows move on a parent-child window |
The parent window receives the WM_PAINT message, but the invalid area is the intersection of the area after the parent window excludes the child window and the other currently moving window area The child window receives the WM_PAINT message, and the invalid area is the intersection of the child window and the area of the currently moving window |
The parent window receives the WM_PAINT message, but the invalid area is the intersection of the window area that the parent window is currently moving The child window receives the WM_PAINT message, and the invalid area is the intersection of the child window and the area of the currently moving window |
Form region drawing problem Ws_clipchildren and Ws_clipsiblings
Excerpt from: http://www.cnblogs.com/gleam/archive/2012/11/26/2789513.html
Ws_clipchildren, so that the parent form leaves the location of the subform on it when it is drawn, without drawing it, and that area is left with the subform to draw.
Ws_clipsiblings, which must be used in a subform so that the subform will be paint if it receives WM_PAINT and has many subforms (which MSDN says must not be in that area, that does not overlap).
The following is also the understanding of ws_clipsiblings
All overlapped windows and popup windows have ws_clipsiblings properties,
These windows cannot be plotted on its sibling window.
For a child window, if this property is not available, it can be plotted on its sibling window
┌────────┐
│a│
││
│┌─────┼───┐
││c││
││││
└──┼─────┘│
││
│b│
└──────────┘
If a, B are all child windows,
If a has a ws_clipsiblings attribute,
Then a redraw does not redraw part C
Clip is cut, removed meaning quite with the exclude of the English
Both Ws_clipchildren and ws_clipsibling are designed to reduce redraw, reduce flicker, and ensure that the overlapping portion of the window has only one window to implement the paint.
MFC Parent Window Ws_clipchildren styles The effects of child window refreshes and form region drawing problems ws_clipchildren and ws_clipsiblings