How does VC ++ maximize or minimize forms? vc forms

Source: Internet
Author: User

How does VC ++ maximize or minimize forms? vc forms

The ShowWindow function is used to maximize the minimum value.

ShowWindow (SW_SHOWMINIMIZED); // minimize ShowWindow (resize); // maximize ShowWindow (SW_RESTORE); // restore ------- PostMessage (hwnd, WM_SYSCOMMAND, SC _MINIMIZE, 0); SC _MAXIMIZE is maximized.

Usage:

BOOL ShowWindow (int nCmdShow); The nCmdShow parameter specifies how CWnd will be displayed. It must be one of the following values: • SW_HIDE hides the window and starts to another window. • SW_MINIMIZE minimizes the window and activates the list of top-level windows in the system. • SW_RESTORE is activated and a window is displayed. If the window is minimized or maximized, Windows restores it to its original size and position. • The SW_SHOW activation window is displayed in its current size and position. • SW_SHOWMAXIMIZED activates the window and displays it as the maximum window size. • SW_SHOWMINIMIZED activation window and display it as an icon. • SW_SHOWMINNOACTIVE as an icon. The current active window remains valid. • SW_SHOWNA is displayed in its current status window. The current active window remains valid. • SW_SHOWNOACTIVATE is displayed in the window of its latest size and position. The current active window remains valid. • SW_SHOWNORMAL is activated and a window is displayed. If the window is minimized or maximized, Windows restores it to its original size and position.
If the return value is non-zero, the window is visible previously. If the return value is 0, the window is hidden previously.

 

You can also use the message method to solve the problem:

PostMessage (hwnd, WM_SYSCOMMAND, SC _MAXIMIZE, 0 );

System message command SC _MAXIMIZE minimization command

Hwnd is the object to be operated!

 

Method 1: Use the SetWindowPos Function
CWnd: SetWindowPos

BOOL SetWindowPos (const CWnd * pWndInsertAfter, int x, int y, int cx, int cy, UINT nFlags );
If the function is successful, a non-zero value is returned; otherwise, 0 is returned.

Description

Call this member function to change the size, position, and Z-axis order of subwindows, pop-up windows, and top-layer windows. Windows are sorted by their Z axis order on the screen. At the top of the Z-axis order, the program is placed at the top of all other windows. All coordinates of the subwindow are customer coordinates (relative to the upper left corner of the parent window customer area ). The window can be moved to the top of the Z axis. You can set the pWndInsertAfter parameter to & wndTopMost, and make sure that the SWP_NOZORDER flag is not set, you can also set the z-axis order of the window so that it is located above all existing top-level windows. When a non-top-level window is set as a top-level window, its own window is also set as a top-level window. Its owner does not change. If the top-level window is located at the bottom of the Z axis (& wndBottom) or any non-top-level window, it is no longer a top-level window. When a top-level window is changed to a non-top-level window, all its owner and all its windows are changed to a non-top-level window. If neither the SWP_NOACTIVE flag nor the SWP_NOZORDER flag is specified (this means that the application requires that the window be activated at the same time and placed in the specified z-axis order ), then, the value specified in the pWndInsertAfter parameter applies only in the following environments: l in the pWndInsertAfter parameter, neither the & wndTopMost nor the & wndNoTopMost parameter is specified.
This window is not an active window. The application cannot activate an inactive window without bringing it to the top of the Z axis order. The application can change the z-axis order of the active window without any restrictions. A non-top-level window may have a top-level window, but vice versa. Any window owned by a top-level window (such as a dialog box) changes itself to a top-level window to ensure that all owned windows are located above their owner. In Windows 3.1 or later versions, you can move Windows to the top of the Z axis order and lock them there by setting their WS_EX_TOPMOST style. This type of top-level window maintains its top-level position even if it is not active. For example, selecting the WinHelp Always On Top command will change the Help window to the Top level and remain visible after you return to the application. To create a top-level window, set the pWndInsertAfter parameter to & wndTopMost when calling SetWindowPos, or set the WS_EX_TOPMOST style when creating the window. If the z-axis sequence contains any window with WS_EX_TOPMOST style, the window moving with & wndTopMost will be placed at the top of all non-top-level windows, but located below any top-level window. When the application activates an inactive window that does not have the WS_EX_TOPMOST style, the window is moved above all non-top-level windows, but below all top-level windows. If the pWndInsertAfter parameter is set to & wndBottom when SetWindowPos is called and CWnd is a top-level window, the window is out of the top-level State (WS_EX_BOTTOM style is cleared ), and the system places the window at the bottom of the Z-axis order.

Parameter pWndInsertAfter
Identifies the CWnd object located before the CWnd object in the z-axis order. This parameter can be a pointer to a CWnd object or a pointer to the following values:
WndBottom places the window at the bottom of the Z-axis order. If this CWnd is a top-level window, the window will lose its top-level state. The system places this window at the bottom of all other windows.
WndTop places the window at the top of the Z axis order.
WndTopMost places the window above all non-top-level windows. This window will keep its top-level position even if it loses its activity status.
WndNoTopMost relocates the window to the top of all non-top-level windows (this means that it is under all top-level windows ). This flag does not work for non-top-level windows. For more information about this function and the usage rules of these parameters, see the description section.

X specifies the new position on the left of the window.
Y specifies the new position at the top of the window.
Cx specifies the new window width.
Cy specifies the new height of the window.

NFlags specifies the size and position options. This parameter can be a combination of the following values:
SWP_DRAWFRAME draws a border around the window (defined when the window is created ).
SWP_FRAMECHANGED sends a WM_NCCALCSIZE message to the window, even if the window size does not change. If this flag is not specified, the WM_NCCALCSIZE message is sent only when the window size changes.
SWP_HIDEWINDOW hides the window.
SWP_NOACTIVATE does not activate the window. If this flag is not set, the window is activated and moved to the top of the top-level or non-top-level window group (dependent on the settings of the pWndInsertAfter parameter.
SWP_NOCOPYBITS discards the content in this customer zone. If this parameter is not specified, the valid content of the customer zone will be saved and copied back to the customer zone after the size or position of the window changes.
SWP_NOMOVE retains the current position (ignore the x and y parameters ).
SWP_NOOWNERZORDER does not change the position of the owner window in the z-axis sequence.
SWP_NOREDRAW does not reproduce the changes. If this flag is set, no changes of any type will occur. This applies to the customer area, non-customer area (including the title and scroll bar), and any part of the parent window overwritten by the moving window. When this flag is set, the application must explicitly invalidate or redraw any part of the window to be repainted and any part of the parent window.
SWP_NOREPOSITION is the same as SWP_NOOWNERZORDER.
SWP_NOSENDCHANGING prevents the window from receiving WM_WINDOWPOSCHANGING messages.
SWP_NOSIZE: Keep the current size (ignore the cx and cy parameters ).
SWP_NOZORDER maintains the current order (ignore pWndInsertAfter ).
SWP_SHOWWINDOW: display window.

========================================================== ======================================

Method 2: Use the MoveWindow Function
Void CWnd: MoveWindow (int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE );
Void CWnd: MoveWindow (LPCRECT lpRect, BOOL bRepaint = TRUE );
Parameters
X specifies the new position on the left of CWnd.
Y specifies the new position on the top of CWnd.
NWidth specifies the new width of CWnd.
NHeight specifies the new height of CWnd.
BRepaint specifies whether to re-draw CWnd. If it is TRUE, CWnd receives a WM_PAINT message in the OnPaint message processing function as usual. If this parameter is set to FALSE, no type of re-painting will be performed. This applies to the customer area, non-customer area (including title bar and scroll bar), and any part of the parent window exposed by CWnd movement. When this parameter is set to FALSE, the application must explicitly invalidate or redraw the required part of the CWnd and parent windows.

The lpRectCRect object or RECT structure, specifying the new size and position. This function changes the position and size of the window. For the top-level CWnd object, the x and y parameters are relative to the upper left corner of the screen. For sub-objects, they are relative to the upper left corner of the parent window customer area.
The MoveWindow function sends a WM_GETMINMAXINFO message. When processing this message, CWnd gets an opportunity to change the maximum and minimum window defaults. If the parameter passed to the MoveWindow member function exceeds these values, the minimum or maximum value can be used in the WM_GETMINMAXINFO processing function.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.