Keywords: Dialog, dialog, Resizable
1. Problem The problem comes from Stanley_xu, I hope to get only the shutdown button (can also be help), the upper left also has an icon that has no program and can change the window size dialog. The BorderStyle and Bordericons properties are set for TFORM to simplify the settings of the window style (otherwise to call the API functions such as SetWindowlong and GetWindowlong). The definition and description of TFORMBORDERSTYLE and TBORDERICON is as follows:
Value MeaningbsDialog Not resizable; standard dialog box border // not change size bsSingle Not resizable; single-line borderbsNone Not resizable; no visible border linebsSizeable Standard resizable borderbsToolWindow like bsSingle but with a smaller captionbsSizeToolWin like bsSizeable with a smaller caption
Type tbordericon = (bisystemmenu, Biminimize, BIMAXIMIZE, BIHELP); tbordericons = set of tbordericon;
Value MeaningbiSystemMenu The form has a Control menu (also known as a System menu) .biMinimize The form has a Minimize buttonbiMaximize The form has a Maximize buttonbiHelp If BorderStyle is bsDialog or biMinimize and biMaximize are excluded, a question mark appears in the form's title bar And When Clicked, The Cursor Changes To Crhelp; OtherWise, No Question Mark Appears.
Obviously, it is only possible to meet the general needs by BorderStyle and Bordericons, and the dialog that can be modified to modify will not be possible. Under normal circumstances, I have to get the most minimized, but can change the size of the size to Bssizeable, remove Bordericons's Biminimize and Bimaximize, the result is like this: The window can modify the size, but the upper left corner has icon,:
Figure 1 Dialog Box with icon
Note that there is icon in the upper left corner.
And our goal is the following effects, there is no icon in the upper left corner, but the window can modify the size.
Figure 2 Open File Dialog
Figure 3 Browsing Folder Dialog
2, the problem solves half of the MSDN, find an article that teaches you how to change the size page (CpropertySheet is arhened as a CPROPERTYPAGE sub page, the latter can not be modified from CDialog Size) "How to Design A Resizable MFC Property Sheet", the method introduced in the text is to modify the window style before the property page is created, and then manually processes the WM_SIZE message.
int CALLBACK CMyPropertySheet :: XmnPropSheetCallback (HWND hWnd, UINT message, LPARAM lParam) {extern int CALLBACK AfxPropSheetCallback (HWND, UINT message, LPARAM lParam); // XMN: Call MFC's callback int nRes = AfxPropSheetCallback (hWnd, message, lParam); switch (message) {case PSCB_PRECREATE: // Set our own window styles ((LPDLGTEMPLATE) lParam) -> style | = (DS_3DLOOK | DS_SETFONT | WS_THICKFRAME | WS_SYSMENU | WS_POPUP | WS_VISIBLE | WS_CAPTION); break;} return nRes;}
I tried to use the same method to use the VCL of a FORM. Set BorderStyle to BSDialog while designing the createParams method. However, the dialog does become a thick border (because there is a WS_THICKFRAME style), the mouse can be automatically changed after moving to each border, there is no icon in the upper left corner, but the window is not changed (the added WM_SIZE message processing process is not triggered) . What's the problem?
Figure 4 is not fully satisfactory dialog
3, the problem solves the source code of Forms.PAS and found the problem. TCUSTOMFORM's WM_NCCREATE message processing has a ModifyysystemMenu embedding process to modify the Form's system menu. Note that the red text is said to "make the system menu look like a dialog." The next few code will delete the system menu item only with "move" and "off".
Procedure tcustommm.wmnccreate (var message: twmccreate);
procedure ModifySystemMenu; var SysMenu: HMENU; begin ...... {Modify the system menu to look more like it's s'pose to} SysMenu: = GetSystemMenu (Handle, False); if FBorderStyle = bsDialog then begin {Make the system menu look like a dialog which has only Move and Close} DeleteMenu (SysMenu, SC_TASKLIST, MF_BYCOMMAND); DeleteMenu (SysMenu, 7, MF_BYPOSITION); DeleteMenu (SysMenu, 5, MF_BYPOSITION); DeleteMenu (SysMenu, SC_MAXIMIZE, MF_BYCOMMAND); DeleteMenu (SysMenu, SC_MINIMIZE, MF_BYCOMMAND); DeleteMenu (sysmenu, sc_size, mf_bycommand); deletemenu (sysmenu, sc_restore, mf_bycommand); end else ...... End;
Begin inherited; setMenu (fMenu); if not (csdesigning in componentstate) THEN MODIFYSYSTEMMUENU; END; So, the problem is deleted due to "SC_SIZE", the window style has a malformed: WS_THICKFRAME (can modify the window size), but Do not respond to the WM_SIZE message (SC_SIZE is deleted). The solution is simple: implement your own WM_NCCREATE message processing, manually modify the system menu.
Procedure tzocdlgresizable.wmnccreate (var message: twmnccreate);
// The following codes are copied from Form.pas line 4047, Delphi 7 sp1 procedure ModifySystemMenu; var SysMenu:. HMENU; begin SysMenu: = GetSystemMenu (Handle, False); {Make the system menu look like a dialog which has only Move , Size and Close commands} DeleteMenu (SysMenu, SC_TASKLIST, MF_BYCOMMAND); DeleteMenu (SysMenu, 7, MF_BYPOSITION); // Do not remove the separater before CLOSE command.// DeleteMenu (SysMenu, 5, MF_BYPOSITION);
DeleteMenu (SysMenu, SC_MAXIMIZE, MF_BYCOMMAND); DeleteMenu (SysMenu, SC_MINIMIZE, MF_BYCOMMAND); {. Do not remove the SIZE command, otherwise we'll lose the capability of resizing the Dialog} // DeleteMenu (SysMenu, SC_SIZE, MF_BYCOMMAND) ;
DeleteMenu (Sysmenu, SC_RESTORE, MF_BYCOMMAND); END;
begin {Skip TCustomForm's WM_NCCREATE handler, which remove the SIZE command from the System Menu.} inherited DefaultHandler (Message); // Dealing with the System Menu in our own way ModifySystemMenu;. end;
4, TZOCDLGRESIZABLE class final solution I encapsulated into a class inherited from TForm, the effect is as follows, the same as Figure 1 (if you want to Figure 2, the system menu you want to Figure 2 delete the row of ModifyysystemMenu), use it from TzoCDLGResizable Inherit one. BTW: I will add a SizeGrip property to TzoCDLGResizable, and the specific situation can be seen.
Figure 5 does not have an icon, can modify the size, a dialog with SizeGrip
Download (exe and source code) http://zocsoft.vicp.net:8080/Article demos/resizabledialog.rar
5, reference information:
MSDN: How To Design A Resizable MFC Property Sheet Reference Address: "Dialog Box for Change Size" in Delphi