Win32 programming child window does not have exit button - c++

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

Related

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

Winapi c++ make static image behave like a button (Hover, Click)

I want to change a Static bitmap image when hovering it. I've tried using a button instead, but the picture never fill the button. I've tried too TrackMouseEvent but I want it to be always active so i cannot use this. Is there a way to get notified when mouse hover a static control or to make a control that behaves like that?
This is my control:
HWND Button = CreateWindow("Static", NULL,
WS_VISIBLE | WS_CHILD | SS_BITMAP | SS_NOTIFY,
20, 240, 120, 20,
hwnd, (HMENU)101, NULL, NULL);
SendMessage(hwnd, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)view.vBitMap);
I use SS_NOTIFY nto get notified when user clicks it or doubleclicks it, but unlike BS_NOTIFY, it don't tell when hovering on WM_NOTIFY

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

Child window created by CreateEx() overlapped by sibling windows

I tried to create a child window using:
CreateWindowEx( NULL, NULL, "MyChild", WS_CHILD | WS_VISIBLE | WS_BORDER, 300, 300, 400, 200, hParentWnd, NULL, NULL );
where the parent HWND hParentWnd has many other child windows already. However, this created a child window hiding behind all the siblings. Windows Spy++ shows that it is on top (first) of the z-order among the child windows of hParentWnd. I have tried all different win32 commands including SetWindowPos(), BringWindowToTop(), SetForegroundWindow(), SetFocus(), SetActiveWindow(), SendMessage(WM_ACTIVATE, 0, 0), etc., but none brings it from behind the siblings. When I replaced WS_CHILD by WS_OVERLAPPEDWINDOW in the CreateWindowEx() command, the created non-child window has no problem showing as the topmost foreground active window. So what must I do to get the child window to the top from behind the siblings?
Thanks a million.
z/0
It is quite explicit in the MSDN article for CreateWindowEx():
If the created window is a child window, its default position is at the bottom of the Z-order. If the created window is a top-level window, its default position is at the top of the Z-order.
You'll need to move it to the top of the Z-order with SetWindowPos().

List Control SetFocus Redraw Error on a Tab Control

Environment: Visual Studio 2008, Visual Studio Feature Pack, MFC Dialog App, Windows XP, New Common Controls.
I'm having a problem with a list control that happens to be on a tab control.
To reproduce the problem simply create a dialog based app. Place a tab control on that dialog, then put a list control onto that tab control. You don't need to add any code to the project. Just build and run. Set the focus to the list view and then either minimize the dialog or bring another window in front of it.
Now bring the dialog back to the foreground, the list will not draw itself correctly.
One thing I have tried is handle the set focus event for the list control, but left it with an empty method body, ie...
void CMyListControl::OnSetFocus(CWnd* window)
{
// Default();
}
Then the redraw problem goes away, however now you can not select items within the list. Uncommenting the call to Default makes the problem come back.
If I move the list off of the tab the problem goes away. If I set the focus to another control on the tab or dialog, the problem goes away. This is a weird one.
In fact, if you watch closely you can see the list drawing itself and then being obscured by the tab control.
I know it's late but I had them same problem today. You need to set ListView's parent to Tab control.
hWndTab = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TABCONTROL, NULL,
WS_CHILD | WS_TABSTOP | WS_VISIBLE,
0, 0, 0, 0, hWnd, (HMENU) IDC_TAB, hInstance, NULL);
hWndList = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL,
WS_CHILD | WS_TABSTOP | WS_VISIBLE | LVS_REPORT,
0, 0, 0, 0, hWndTab, (HMENU) IDC_LIST, hInstance, NULL);
Note parent window handler for hWndList: hWndTab. Or you can use SetParent.