Production stretching, contraction, casual dialog

zhaozj2021-02-11  193

Production stretching, contraction, free dialog box, ice Visual C , is the mainstream development tool for the current Windows programming and development. The dialog box is used in Visual C programming. Such as mode dialogs, no mode dialogs, dialog-based applications, and more. Most of the VC books spend a lot of space and pen ink, which fully demonstrates the role of the dialog in the Windows application. Many people may have used BitWare software, I don't know if you still remember that its interface dialog can stretch. Press a button and the dialog extends in the horizontal or vertical direction. Press the button again, the dialog returns to the original size. In fact, this is not a very complicated issue. Let's explain how to make a dialog box. 1 Open the Visualc Workbench, and the new project is set to AAA. 2 Creating a dialog-based application as follows: The rest of the options are default. 3 Increase control resources in dialog resources, as shown below: Among them, a row of controls up to right and two row controls closest to the following will be displayed or covered when the dialog extends or contracted. And for example, we intend to correspond to their values. And we need to associate a member variable for each control via ClassWizard, as follows: Refer to the DODATAEXChange () function We can know the variables associated with each control, as shown below: DDX_Text (PDX, IDC_HEight, m_wheight); ddx_text (pDX, IDC_STREAM_ID, m_wStreamID); DDX_Text (pDX, IDC_WIDTH, m_wWidth); DDX_Text (pDX, IDC_SEQUENCE_ORDER, m_wSequenceOrder); DDX_Text (pDX, IDC_MAX_RATE, m_dwMaxRate); DDX_Text (pDX, IDC_MIN_RATE, m_dwMinRate); DDX_Text (pDX, IDC_HEIGHT2, m_wHeight2); DDX_Text (pDX, IDC_MAX_RATE2, m_dwMaxRate2); DDX_Text (pDX, IDC_MIN_RATE2, m_dwMinRate2); DDX_Text (pDX, IDC_SEQUENCE_ORDER2, m_wSequenceOrder2); DDX_Text (pDX, IDC_STREAM_ID2, m_wStreamID2); DDX_Text (pDX, IDC_WIDTH2, m_wWidth2); DDX_Check ( PDX, IDC_HORIZONTAL, M_BHORIZONTAL); DDX_CHECK (PDX, IDC_Vertical, M_Bvertage); In fact, we can also directly use ClassWizard to directly copy the above code COPY to DODATAEXCHANGE () function // {{AFX_DATA_MAP (CAAADLG) .... .. //}} AFX_DATA_MAP, (Note Be sure to "// {AFX_DATA_MAP (CAAADLG)" and "//}} AFX_DATA_MAP").

At the same time, in the aaadlg.h file, in // {AFX_DATA (CAAADLG) enum {IDD = IDD_AAA_DIALOG}; ...... //}} AFX_DATA can be added as the variable definition: (Note must be " // between {{AFX_DATA (CAaaDlg) "and" //}} AFX_DATA ") UINT m_wHeight; UINT m_wStreamID; UINT m_wWidth; UINT m_wSequenceOrder; DWORD m_dwMaxRate; DWORD m_dwMinRate; UINT m_wHeight2; DWORD m_dwMaxRate2; DWORD m_dwMinRate2; UINT m_wSequenceOrder2; UINT M_WSTREAMID2; UINT M_WWIDTH2; BOOL M_BHORIZONTAL; BOOL M_BVertical; 5 After completing the above steps, we can define a few new variables to save the information when the window is stretched, and the information when the contraction is used. As follows: Word m_worigrinwidth; // The window width in the original state word m_wreducedwidth; // Surface Width Word M_WorigrinHeight; // The window height in the original state word m_wreducedheight; // In the window height Word M_ScreenWidth; / / Screen Width Word M_ScreenHeight; // The screen height After completing all the above steps, you can control the stretching and contraction of the window, first we come to the specific code, then make specific explanations.

Code: CenterWindow (NULL); m_screenWidth = GetSystemMetrics (SM_CXSCREEN); m_screenHeight = GetSystemMetrics (SM_CYSCREEN); WINDOWPLACEMENT * lpwndpl = new WINDOWPLACEMENT; GetWindowPlacement (lpwndpl); m_wOrigrinWidth = lpwndpl-> rcNormalPosition.right; m_wOrigrinWidth - = lpwndpl-> rcNormalPosition .left; m_wOrigrinHeight = lpwndpl-> rcNormalPosition.bottom; m_wOrigrinHeight - = lpwndpl-> rcNormalPosition.top; LPRECT lpRect1, lpRect2; lpRect1 = new RECT; lpRect2 = new RECT; GetDlgItem (IDC_PROGRESS_BAR) -> GetWindowRect (lpRect1); GetDlgItem ( IDC_STREAM_ID) -> GetWindowRect (lpRect2); lpwndpl-> rcNormalPosition.right = (lpRect1-> right lpRect2-> left) / 2; m_wReducedWidth = lpwndpl-> rcNormalPosition.right; m_wReducedWidth - = lpwndpl-> rcNormalPosition.left; GetDlgItem (IDC_PROGRESS_BAR) -> GetWindowRect (lpRect1); GetDlgItem (IDC_SEQUENCE_ORDER2) -> GetWindowRect (lpRect2); lpwndpl-> rcNormalPosition.bottom = (lpRect1-> bottom lpRect2-> top) / 2; m_wReducedHeight = lpwndpl-> rcNormalPosition.bottom ; m_wreducedheight - = lpwndpl-> rcnorm alPosition.top; delete lpRect1; delete lpRect2; if (m_bHorizontal == TRUE) {lpwndpl-> rcNormalPosition.right = lpwndpl-> rcNormalPosition.left; lpwndpl-> rcNormalPosition.right = m_wOrigrinWidth; lpwndpl-> rcNormalPosition.bottom = lpwndpl -> rcNormalPosition.top; lpwndpl-> rcNormalPosition.bottom = m_wReducedHeight;} else {lpwndpl-> rcNormalPosition.right = lpwndpl-> rcNormalPosition.left; lpwndpl-> rcNormalPosition.right = m_wReducedWidth; lpwndpl-> rcNormalPosition.bottom = Lpwndpl-> rcnormalposition.top; lpwndpl->

rcNormalPosition.bottom = m_wReducedHeight;} if (m_bVertical == TRUE) {lpwndpl-> rcNormalPosition.right = lpwndpl-> rcNormalPosition.left; lpwndpl-> rcNormalPosition.right = m_wReducedWidth; lpwndpl-> rcNormalPosition.bottom = lpwndpl-> rcNormalPosition.top; lpwndpl-> rcNormalPosition.bottom = m_wOrigrinHeight;} else {lpwndpl-> rcNormalPosition.right = lpwndpl-> rcNormalPosition.left; lpwndpl-> rcNormalPosition.right = m_wReducedWidth; lpwndpl-> rcNormalPosition.bottom = lpwndpl- > rcNormalPosition.top; lpwndpl-> rcNormalPosition.bottom = m_wReducedHeight;} SetWindowPlacement (lpwndpl); the above code is first placed in the middle of the screen window, this can be achieved by a function CenterWindow (GetDesktopWindow ()), the CenterWindow function () The usage is: void centerWindow (CWND * PALTERNATEOWNER = NULL); where parameter Palternateowner points to the pointer to the window you want. Then use the function getSystemMetrics (INT NINDEX) to get the current settings such as screen resolution. NINDEXS = SM_CXSCREEN When the function returns the width of the screen; the return value unit is a pixel point. NINDEXS = SM_CYSCREEN When the function returns the height of the screen; the return value unit is a pixel point. Function BOOL getWindowPlacement (WindowPlace * LPWNDPL) is the most important. His argument is a pointer to the structure variable WINDOWPLACEMENT pointer (lpwndpl); wherein WINDOWPLACEMENT structure variable data structure specifically: typedef struct tagWINDOWPLACEMENT {/ * wndpl * / UINT length; UINT flags; UINT showCmd; POINT ptMinPosition; POINT ptMaxPosition; RECT rcNormalPosition WindowPlacement; he contains the positioning information on the screen on the screen. The meaning of the member variable is: Length: refers to the length of the structural variable, the unit byte. Flags: Sign value, control window minimize or window restore, you can take the following value: WPF_SETMINPOSITION: The X position and Y position when the window minimizes the window. WPF_RESTORETOMAXIMIZED: The specified window is restored to maximize the way, although the possible window is not minimized at maximized. Do not change the default reduction method of the window. Showcmd: The current display status of the specified window. You can take the value: SW_HIDE: Hide the window and activate another window. SW_MINIMIZE: Minimize the Specified Window and activate the top window in the system window list.

SW_RESTORE: Activate and displays the window, if the window is minimized or maximized, the window is restored to the original size and location. SW_SHOW: Activate and displays the window with the current size and location of the window. SW_SHOWMAXIMIZED: Activate and display the window in maximization. SW_SHOWMINIMIZED: The window is activated and displayed in an icon. SW_SHOWMINNOACTIVE: Ways window. But does not change the activity status of the window. SW_SHOWNA: Displays the window with the current status of the window. SW_SHOWNOACTIVATE: The window is displayed in the first size and location display window. But do not change the activity of the window. SW_SHOWNORMAL: Activate and displays the window. If the window is maximized or minimized, the window is restored to the original size and position. PTMINPOSITION: The left injuried angle coordinate of the specified window minimizes. PTMAXPosition: The left injury coordinate of the specified window maximizes. RcNORMALPSITION: Specifies the coordinates of the window when restored. You can get the configuration information of the window by flexible use of function getWindowplacement (). Seeing this, some readers may have thought of the sister function setWindowPlacement () of the getWindowplacement () function, without having to say, the usage is as follows: BOOL setWindowplacement (WINDOWPLACEMENT * LPWNDPL); Obviously, through the function setWindowplace (), simple calculation We can set the position, size, and state of the window, so that we can display the size, location, etc. of the window. We will not explain more here.

6 ClassWizard use of controls and IDC_VERTICAL increase IDC_HORIZONTAL message map BB_CLICKED, respectively, and add the following code in the message mapping functions as follows: void CAaaDlg :: OnHorizontal () {// TODO:! Add your control notification handler code here m_bHorizontal = m_bHorizontal; UpdateData (FALSE); WINDOWPLACEMENT * lpwndpl = new WINDOWPLACEMENT; GetWindowPlacement (lpwndpl); if (m_bHorizontal == TRUE) {lpwndpl-> rcNormalPosition.right = lpwndpl-> rcNormalPosition.left; lpwndpl-> rcNormalPosition.right = m_wOrigrinWidth; / * lpwndpl-> rcNormalPosition.bottom = lpwndpl-> rcNormalPosition.top; lpwndpl-> rcNormalPosition.bottom = m_wReducedHeight; * /} else {lpwndpl-> rcNormalPosition.right = lpwndpl-> rcNormalPosition.left; lpwndpl-> rcNormalPosition.right = m_wReducedWidth; / * lpwndpl-> rcNormalPosition.bottom = lpwndpl-> rcNormalPosition.top; lpwndpl-> rcNormalPosition.bottom = m_wReducedHeight; * /} SetWindowPlacement (lpwndpl); delete lpwndpl;} void CAaaDlg :: OnVertical () {/ / TODO: Add Your Control Notification Handler Code Here M_Bvertical =! M_bvertage; UPDATEDATA (FAL SE); WINDOWPLACEMENT * lpwndpl = new WINDOWPLACEMENT; GetWindowPlacement (lpwndpl); if (m_bVertical == TRUE) {lpwndpl-> rcNormalPosition.bottom = lpwndpl-> rcNormalPosition.top; lpwndpl-> rcNormalPosition.bottom = m_wOrigrinHeight;} else { lpwndpl-> rcNormalPosition.bottom = lpwndpl-> rcNormalPosition.top; lpwndpl-> rcNormalPosition.bottom = m_wReducedHeight;} SetWindowPlacement (lpwndpl); delete lpwndpl;} 7 Finally ClassWizard increase of the control message map IDC_BEGIN_SIMULATE BB_CLICKED. Here we simulate a random number display program for 100 cycles.

转载请注明原文地址:https://www.9cbs.com/read-4542.html

New Post(0)