Minimize button won't appear on MFC Dialog - c++

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_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.
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);

Related

Win32 programming child window does not have exit button

Hi I am writing a Win32 Windows program. I created a child window with the following command
case ID_VIEW_CARVIEW:
carViewHwnd = CreateWindowEx(WS_EX_TOPMOST, L"Edit", L"Edit",
WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_BORDER,
000, 00, 656, 519, hWnd, (HMENU)NULL, GetModuleHandle(NULL), NULL);
SetWindowLongPtr(carViewHwnd, GWLP_WNDPROC, (LONG_PTR)CarViewWndProc);
However, this child windows has two problems:
It does not have a "close" button on the top right.
It always stay on top of all windows on my desktop top.
How can I change it?
It does not have a "close" button on the top right.
You need set WS_SYSMENU flag for dwStyle parameter to have a window menu on its title bar.
It always stay on top of all windows on my desktop top.
Because you define WS_EX_TOPMOST style: "The window should be placed above all non-topmost windows and should stay above them, even when the window is deactivated."

Maximized WS_POPUP window goes in front of the taskbar

I'm creating a window in C++ with that code:
HWnd = CreateWindow(wc.lpszClassName,
"myapp",
WS_POPUP |WS_VISIBLE,
10, 10, 1000, 800, 0, 0, hInst, NULL);
It appears as I want but when I maximize it with like this:
ShowWindow(hwnd, SW_SHOWMAXIMIZED);
then it's like a fullscreen window so that the taskbar is hidden.
I think it's because it is a POPUP window but this is like I want it to appear.
Do I need to create my own maximize function or is there a parameter to avoid that ?
Thanks
You can add WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX style.
If you want your window to be without caption then you will need to adjust window size manually to fit into desktop work area that you can query using SystemParametersInfo specifying SPI_GETWORKAREA flag.
This is a feature where the Taskbar will get out of your full-screen application:
If you want to create a fullscreen window that covers the taskbar, just create a fullscreen window and the taskbar will automatically get out of the way.
I’ve seen people hunt for the taskbar window and then do a ShowWindow(hwndTaskbar, SW_HIDE) on it. This is nuts for many reasons.
Don’t do any of this messing with the taskbar. Just create your fullscreen window and let the taskbar do its thing automatically.
Since this is Stackoverflow, a combination of Wikipedia and Reddit, i want this relevant information saved for the next guy asking this question.

Groupbox resizing issue with radio buttons on top

I'm not sure what I'm doing wrong here. I'm trying to implement a resizing dialog window using MFC. The code is pretty straightforward. I override the following sizing notification:
void CMyDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
//...
//First move the groupbox, pGroupbox is of type CWnd
pGroupbox->MoveWindow(rcGroupbox);
//And then move all radio buttons in it
//Each is moved the exact same way
//pEachRadioButton is of type CWnd
pEachRadioButton->MoveWindow(rcEachRadioButton);
}
But what I get as a result is this.
First here's the initial groupbox:
It happens only when I start dragging the bottom of the main window frame down. I get this artifact:
Note that the radio button positions themselves are correct. If I move the mouse over either of them, it redraws itself correctly (like this "shut-down" button):
Here's the layout of the dialog itself:
IDD_MY_DIALOG DIALOGEX 0, 0, 437, 190
STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_APPWINDOW
CAPTION "My dialog"
MENU IDR_MENU_MAIN
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
PUSHBUTTON "&Cancel",IDCANCEL,381,169,50,14
GROUPBOX "When Tasks Are Completed",IDC_STATIC_WHEN_COMPLETED,7,113,423,36
CONTROL "Close the pro&gram",IDC_RADIO_CLOSE_PROGRAM,"Button",BS_AUTORADIOBUTTON | WS_GROUP,26,129,73,8
CONTROL "Put computer to sleep",IDC_RADIO_SLEEP,"Button",BS_AUTORADIOBUTTON,122,129,84,10
CONTROL "Hibernate computer",IDC_RADIO_HIBERNATE,"Button",BS_AUTORADIOBUTTON,229,129,78,10
CONTROL "Shut down computer",IDC_RADIO_SHUT_DOWN,"Button",BS_AUTORADIOBUTTON,330,129,81,10
DEFPUSHBUTTON "&OK",IDC_BUTTON_SET,311,161,67,22
END
I did some search and found this article, but unfortunately setting those styles did not fix the bug.
Any idea how to fix this?
PS. I'm testing it on Windows Vista, 7, or 8 with visual themes enabled.
When you move a window, the window manager will move the current image of the window as it exists. Unfortunately because you moved the frame first, all those windows got clipped. Flipping them around wouldn't help, because then the tops would get clipped.
The easy way to fix it would be to call InvalidateRect on each control after moving it.
The better way would be to call BeginDeferWindowPos before you start moving anything, then EndDeferWindowPos when you're done so that all the windows move together.
P.S. Windows prefers for the group box to come after the radio buttons in the tab order, that might make a difference too.

How to make Window full screen in VisualStudio SkeletonBasics-D2D 2013

I'm currently using the SkeletonBasics-D2D library. I would like to give a presentation with the skeleton but need make the window fullscreen. Here are the notes I currently worked through and my next step is potentially modifying the .rc file to work with the full screen windowed app; however, I'd like to ask first is anyone knows another way.
Potentially it could just be manipulating this code in my SkeletonBasics.rc file :
IDD_APP DIALOGEX 0, 0, 512, 424
STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_CONTROLPARENT | WS_EX_APPWINDOW
CAPTION "Skeleton Basics"
CLASS "SkeletonBasicsAppDlgWndClass"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "",IDC_VIDEOVIEW,"Static",SS_BLACKFRAME,0,0,512,384
LTEXT "Click 'Seated' to change skeletal pipeline type!",IDC_STATUS,0,413,511,11,SS_SUNKEN,WS_EX_CLIENTEDGE
CONTROL "Seated",IDC_CHECK_SEATED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,238,391,55,8
END
Notes from code :
creating a window causes different signals to be generated than a dialog
where a dialog expects WM_INITDIALOG on create, a window should expect WM_NCCREATE
the dialog's DLGPROC was being set with CreateDialogParamW(). The window's WNDPROC is set within a WNDCLASS structure and then registered before CreateWindow()
the window's class name is important, as it's referred to in the SkeletonBasics.rc file wc.lpszClassName = L"SkeletonBasicsAppDlgWndClass";
need to determine all messages sent to the window and handle them appropriately
This tutorial is a great example of full screen and have used it to convert my application into full screen.
To get there, I needed to change the dialog proc to a window.
http://www.directxtutorial.com/Lesson.aspx?lessonid=11-4-4

WinAPI: Create resizable window without title bar, but with minimize/maximize/close buttons (as Firefox/Chrome/Opera)

If you look at the windows of the browsers Firefox, Chrome or Opera, you'll notice that their windows
have minimize/maximize/close buttons
are resizable
but have no title bar
I'm interested: how can I create such a window?
What I have already tried:
I looked around on StackOverflow (and googled, too), and found this: opening a window that has no title bar with win32
Unluckily, this didn't help completely:
The first step was to extend the solution proposed on opening a window that has no title bar with win32
hWnd = CreateWindow(szWindowClass, szTitle, WS_BORDER,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
SetWindowLong(hWnd, GWL_STYLE, WS_SIZEBOX);
// See remarks on http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545.aspx
SetWindowPos(hWnd, 0,
0, 0, 0, 0, // Position + Size
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
Of course, this delivers no minimize/maximize buttons, but on the other hand, if I want minimize/maximize buttons, I have to do:
SetWindowLong(hWnd, GWL_STYLE, WS_SIZEBOX | WS_MAXIMIZEBOX |
WS_MINIMIZEBOX | WS_SYSMENU | WS_CAPTION);
Why does this combination seem to be necessary? First I probably want WS_MAXIMIZEBOX | WS_MINIMIZEBOX since I want these buttons.
But http://msdn.microsoft.com/en-us/library/ms632600.aspx says that if I set one of WS_MAXIMIZEBOX and WS_MINIMIZEBOX, I also have to set WS_SYSMENU. And when I set WS_SYSMENU, I also have to set WS_CAPTION but this is not what I want, because I wanted to avoid the title bar (indeed: if WS_CAPTION is not set, no minimize/maximize buttons are shown).
So what is to do?
The programs remove the non-client area (the title bar) and have a bunch of custom handling for reproducing the window buttons, icons, system menu etc. The benefit of this is that they can draw to the new "title bar", which is actually part of the standard client area, adding tabs or other custom controls.
The following two articles will show you how to do this on Vista and above (using the DWM):
Setting up a custom title bar on Windows Vista / 7
Setting up a custom title bar - reprise This one has a demo app showing the result of a number of variations / options.
This is very complex to do and get right, so the above two articles are invaluable. The author must have put a lot of work into them! Both links have example code written in Delphi, but it should be easy enough to translate it to C++ - the concepts are identical, it's just syntax.
You might also be interested in general resources on Glass and DWM, since it's all closely related. You'll spot the above two links included in that list :)
You can create a window with or without caption - whatever is more appropriate from the point of view of desired customization (that is "without" is you want to do it "without title bar" as you say), and the important wart is that you take over painting non-client area - this is the key thing.
At this point, there is no one to paint your mimimize/maximize buttons already. It does not however mean that you have to do the painting right from scratch and mimic standard UI. There is DrawFrameControl and friends API where you can use DFCS_CAPTIONMIN argument and have minimize button painted for you. You will also want to respond to other non-client area messages, e.g. handle WM_NCHITTEST to tell Windows where your new window buttons are.
You might also want to check Visual Styles Reference to leverage theme-enabled drawing API such as DrawThemeBackground.
A simple example of this activity is putting an additional button onto caption, such as described in detail here: CCaptionButton (buttons for the titlebar).
I believe they create a normal window and then paint over the title bar with their custom widgets/tabs. This is evident in Firefox, as when it hangs you can see the normal Windows title bar appear over the tabs.