Create a Borland style floating window
A friend who used the Borland Series Development Tool Product (Delphi, C Builder, JBuilder) must notice the characteristics of the Borland product interface, that is, the MDI (multi-document interface) is displayed, and the separated multi-window, especially the main window Floating on the top of the screen, when the main window does not account for the entire customer area, but still on the screen, users can have more space usage. So how can I achieve the effect similar to the main window? Now introduce a method of implementing Delphi.
To achieve the effect of the main window mentioned above, you must do three points: 1. When the program is started, the main window is at the top of the screen, and the width is full of screen; 2. Dock the user drags the toolbar (Dockable Toolbar) When / coolbar, the window can be automatically resized; 3. When the user clicks to maximize the button, the window is kept at the top and the size remains unchanged.
Now, it is assumed that a COOLBAR named CBMain is included in the main window of the current project (the general main window contains only menus and toolbars). Set the TFRMMAIN's AutoSize property to false.
Specific steps are as follows:
1. Add an oncreate event for the main window, the code is as follows:
Procedure tfrmmain.formcreate (sender: TOBJECT);
Begin
TOP: = 0; // Set the upper left corner of the main window to the upper left corner of the screen
LEFT: = 0; //
Width: = Screen.width; // Set the main window width as the screen width
END;
Screen is a class instance predefined by the system, corresponding to the system desktop, from which some parameters are available.
2. Add a private member to the definition part of TFRMMain:
Private
H: integer;
Add an OnResize event for the main window, the code is as follows:
Procedure tfrmmain.formResize (sender: TOBJECT);
Begin
ClientHeight: = CBMAIN.HEIGHT; // Set the height of the window customer area to Coolbar
H: = height; // Save the current window height in the variable h
END;
The OnResize event is triggered because the window is initialized or when you click the maximum button, you can guarantee that the window height is always correct.
3, this is the most critical step, we must change the default maximum routine of Windows to control the maximized window size and location. Therefore, we re-map the handle of WM_ GETMINMAXINFO. WM_GETMINMAXINFO message Returns a pointer to the MinMaxInfo structure in LPARAM, and the structure of MinMaxInfo is as follows:
TagminMaxInfo = Record
PTRESERVED: TPOINT; / / System Reserved
PTMAXSIZE: TPOINT; / / Maximum size
PTMaxPosition: tpoint; // Maximize
Ptmintracksize: TPOINT; / / The smallest size
PTMaxTracksize: TPOINT; // Window's maximum size
END;
MinMaxInfo: tagminmaxinfo;
For our purposes, only PTMaxSize, PTMaxPosition two members are enough. Windows replaces the default maximum parameter by calling this structure as a parameter by calling this structure.
The specific operation is as follows: The definition part of TFRMMain adds a private member definition:
Private
Procedure FormMaximum (Var Msg: TMESSAGE); Message WM_GETMINMAXINFO;
To define the message handle of WM_GETMINMAXINFO.
Add implementation code in the Implementation section:
Procedure Tfrmmain.FormMaximum (Var Msg: TMessage);
VAR
LPMMI: ^ TagminMaxInfo;
Begin
LPMMI: = Pointer (msg.lparam); // Get points to TagminMaxInfo
LPMMI ^ .ptmaxSize: = Point (Screen.Width, H); / / Set the length of the window
LPMMI ^ .ptmaxPosition: = Point (0); // Set the location of the upper left corner of the window
END;
One thing to pay attention to: lpmmi ^ .ptmaxSize: = Point (Screen.width, H); a sentence cannot be written to lpmmi ^ .ptmaxSize: = Point (Screen.Width, frmmain.Height); this is because TFORM is a VCL control, here Messages in the message handle cannot directly reference members in TFORM.
At this point, I have already gone! Others, if you allow users to change the window size, can you drag a window, you can implement it by simple adjustment, just look at your needs.