In fact, it is not difficult to prohibit the modification of the size of a single document form and the title, so I will discuss the implementation of this item.
First, find the precreatewindow (createstruct & CS) function in the single document cmainframe (). This function is used to set some features of our form. Now, let's take a closer look at this function, as follows:
Bool cmainframe: precreatewindow (createstruct & CS)
{
If (! Cframewnd: precreatewindow (CS ))
Return false;
// Todo: Modify the window class or styles here by modifying
// The createstruct CS
Return true;
}
First, let's take a look at this parameter createstruct & CS, which is a reference to the createstruct structure. Well, let's look at msdn and look at this structure, as shown below:
Typedef struct tagcreatestruct {// CS
Lpvoid lpcreateparams;
Hinstance;
Hmenu;
Hwnd hwndparent;
Int Cy;
Int CX;
Int y;
Int X;
Long style;
Lpctstr lpszname;
Lpctstr lpszclass;
DWORD dwexstyle;
} Createstruct;
Let's take a look at these parameters one by one:
Lpvoid lpcreateparams: this parameter is used to point to the data that will be used to create a window.
Hinstance: this parameter identifies the handle of the module instance with a new window.
Hmenu: this parameter identifies the menu to be used in the new window. If it is a subwindow, it contains an integer ID.
Hwnd hwndparent: this parameter identifies a window with a new window. If the new window is a top-level window, this parameter can be null.
Int Cy: this parameter specifies the height of the new window.
Int CX: this parameter specifies the width of the new window.
Int Y: this parameter specifies the Y axis in the upper left corner of the new window. If the new window is a child window, the coordinates are relative to the parent window; otherwise, the coordinates are relative to the screen origin.
Int X: Specifies the x-axis coordinates in the upper left corner of the new window. If the new window is a child window, the coordinates are relative to the parent window; otherwise, the coordinates are relative to the screen origin.
Long style: this parameter specifies the style of the new window.
Lpctstr lpszname: this parameter points to a string ending with null and specifies the name of the new window.
Lpctstr lpszclass: this parameter points to a string ending with null and specifies the Windows Class Name of the new window (A wndclass structure; For more information, see the Win32 SDK documentation ).
DWORD dwexstyle: this parameter specifies the extended style of the new window.
Among these parameters, we usually use cy, CX, Y, X, style, and lpszname.
Now, in precreatewindow (createstruct & CS)
Add code to prohibit the change of the window size of a single document:
Bool cmainframe: precreatewindow (createstruct & CS)
{
If (! Cframewnd: precreatewindow (CS ))
Return false;
// Todo: Modify the window class or styles here by modifying
// The createstruct CS
CS. hmenu = NULL; // remove the menu
CS. Style & = ~ Ws_maximizebox; // disable the push maximization button
CS. Style & = ~ Ws_thickframe; // you are not allowed to change the window size.
CS. Cx = 700; // window width
CS. Cy = 500; // window height
CS. Style & = ~ Fws_addtotitle; // remove fws_addtotitle
CS. lpszname = "title" // change the title and replace the title.
Return true;
}
Here, we should note that when assigning values to these parameters, we need to use the & symbol to have another ~ Symbol:
CS. Style & = ~ Ws_maximizebox; // disable the push maximization button
This statement removes ws_maximizebox from the style. It is an inverse operation, similar to other operations.
// CS. Style & = ~ Ws_maximizebox | ~ Ws_minimizebox; remove the "maximize and minimize" button in the dialog box.
// CS. Style & = ~ Ws_maximizebox; // disable the push maximization button