1
votes

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.

3
I only have 3 options: popup, child or overlapped. I tried all three different styles and none have the buttons. Could you give me a hint where I would set WS_MINIMIZEBOX style? Thank you.Mr Tea
In the resource editor, select the main dialog box and then, in the Properties window, scroll to find the "Minimize Box" property and set it to "true". And, normally, a dialog is a "Popup" window.Adrian Mole
The problem is when I use Popup window I do not see the title bar at all!Mr Tea
Is it a dialog-based application or a dialog box that is activated inside the application?Adrian Mole
@IInspectable, What, exactly, is not required ? My suggestion above is to add a few styles. That solved the problem for the OP, regardless of where he added them.Sid S

3 Answers

2
votes

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.

2
votes

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_SYSMENU1. 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.


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

1
votes
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);