简体   繁体   中英

Minimize button won't appear on MFC Dialog

I am having trouble adding the minimise button to my MFC Dialog application. I have enabled minimise box (true).

The minimise button appears in the designer view but when I run the application the buttons are not visible.

Other settings are: Style: Overlapped
Application Window: True
Border: Dialog Frame
Tool Window: False
System Menu: True

I tried adding: ModifyStyle(0, WS_MINIMIZEBOX, TRUE);

to the OnInitDialog() but hasn't solved it.

There are 3 styles that I can choose which are popup, child and overlapped. If I use popup I don't see a title bar and cannot drag the window. Child throws an access violation if I use that style, so the only style I can choose is overlapped which shows the title bar and allows me to drag the window but the minimise button is not visible.

I am using Visual Studio 2019 and running Windows 10 1809.

I have double checked and minimise box is set to TRUE however it still won't show up on the dialog box when running.

The problem is when I use the Popup window style, I do not see the title bar at all! Also if I use the popup style I am unable to drag the window (title bar is missing). Overlapped seems the only style that I can use.

Try something like this:

BOOL CMFCApplication1Dlg::OnInitDialog()
{
    ModifyStyle(0, WS_POPUP | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX, TRUE);
    ...
}

Consider modifying your dialog template (in the .RC file) to include the necessary style bits instead of modifying the style at runtime.

MFC is no different from programming a dialog without any frameworks. You declare a DIALOGEX resource, and have the system load it up, and display a dialog based on that template.

To get a dialog with a minimize box it needs at least the styles WS_MINIMIZEBOX and WS_SYSMENU 1 . Open up the .rc script that defines the DIALOGEX dialog template, and make sure those 2 styles are present in the STYLE element.

A default dialog template for a dialog-based application (with a minimize box) will typically be defined like this:

IDD_MFCAPPLICATION1_DIALOG DIALOGEX  0, 0, 320, 200
STYLE DS_SHELLFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION
 | WS_THICKFRAME
 | WS_SYSMENU
 | WS_MINIMIZEBOX
EXSTYLE WS_EX_APPWINDOW
CAPTION ""
FONT 8, "MS Shell Dlg"
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,209,179,50,14
    PUSHBUTTON      "Cancel",IDCANCEL,263,179,50,14
    CTEXT           "TODO: Place dialog controls here.",IDC_STATIC,10,96,300,8
END

You don't need to write any code that executes at runtime to get this behavior.


1 From Window Styles : " WS_MINIMIZEBOX : The window has a minimize button. [...] The WS_SYSMENU style must also be specified. "

BOOL CMFCApplication1Dlg::OnInitDialog(){

ModifyStyle(0, WS_MINIMIZEBOX, TRUE);
ModifyStyle(0, WS_POPUP, TRUE);
ModifyStyle(0, WS_BORDER, TRUE);
ModifyStyle(0, WS_SYSMENU, TRUE);
ModifyStyle(0, WS_CAPTION, TRUE);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM