Alt + Space is not working on a borderless window - c++

I have created a borderless window by intercepting the WM_NCCALCSIZE command. The idea is to create a custom GUI. Here is the code that I used to create a clean slate:
case WM_NCCALCSIZE:
return 0;
Somehow though, WM_NCCALCSIZE also disabled the system menu. Pressing Alt + Space only gives an error beep. I am unable to test the "Minimize" and "Maximize" functions. How can I restore the system menu?

Related

A message box that never loses focus

A message box created with
MessageBox (NULL, "Text", "Title", MB_ICONINFORMATION | MB_SYSTEMMODAL);
stays on top of other windows, but it loses keyboard focus when the user clicks another window.
How could I create a message box (or an Edit box or a dialog box) that never loses keyboard focus, so if I try to switch to another window using [ALT-TAB] or mouse or any other method, or if another application running in a background opens its own Edit box, the keyboard focus would jump back to my message / Edit box?
The standard MessageBox function doesn't have such an option, so I tried a custom Edit box. I experimented with WM_SETFOCUS, WM_KILLFOCUS, WM_NCACTIVATE, SetForegroundWindow, SetFocus, but had no luck so far. When I open another window, the keyboard focus stubbornly goes to that window.
RegisterHotKey(0,1,MOD_ALT,VK_TAB); //disables alt+tab until message box returns
SetTimer(hwnd,1,100,0); //0.1 sec is enough for message box window creation
MessageBox(0,"Text","Title",MB_ICONINFORMATION|MB_SYSTEMMODAL); //since it's system modal, main message loop will wait for it to return
ClipCursor(0); //frees cursor
UnregisterHotKey(0,1); //enables alt+tab again
Here we use a timer to clip cursor so that user won't be able to click outside of the message box. I left title part of the messagebox outside of the clip area because clicking there negates cursor clipping.
case WM_TIMER:
{
KillTimer(hwnd,1);
RECT rc;
GetWindowRect(FindWindow(0,"Title"),&rc);
rc.top+=22; //title area left out of clip area
ClipCursor(&rc); //user cannot move their mouse outside of the message box
break;
}
This however can't block Ctrl + Alt + Del but does what you ask.

Win32 popup menu width [duplicate]

I'm creating a custom control in wxWidgets that displays a menu as part of it, and currently working on the Windows side of things. wxWidgets doesn't have a way of setting the width of a menu. It just makes the window as wide as the longest string plus a few pixels on either side.
In the API, there is a way to get the actual Windows API menu handle. Does the Windows API have a method of setting the width of a menu other than just calculating it on its own based on the width of the string?
With the handle of the menu, you can cycle through the menu items and call SetMenuItemInfo, indicating that you want to owner-draw the menu items. When you do this, the window that the menu is attached to will receive the WM_MEASUREITEM message, which you would then respond to by setting the dimensions required for the menu. It is here you can set your width.
Of course, this means you have to subclass the windows message handler for the window that contains the menu.
First of all, try to obtain the HWND to the menu:
(1) WM_DRAWITEM (2)get the HDC (3)WindowFromDC(),
then you can arbitrarily adjust aspects of the menu.
NOTE: don't send WM_QUIT WM_CLOSE to the menu, or you'll effectively shut down your computer with no clue.

SW_SHOWNOACTIVATE does not work if program is minimized by clicking the taskbar button

My application can receive a message from another application. If the app is minimized, I want to restore it to the previous state without giving focus to it.
I'm doing it by calling
::ShowWindow(hWnd, SW_SHOWNOACTIVATE);
It works well if the app was minimized using the Minimize button in the title bar, but if the app was minimized by clicking its button in the Windows task bar, then the app will receive focus.
Can this be fixed or worked around?
You could do the following HWND hwndForegroundWindow = GetForegroundWindow() before your ShowWindow function call. Afterwards you can restore the foreground window with SetForegroundWindow(hwndForegroundWindow). It depends on what you mean with focus though, foreground window and focus are something different (For element focus use GetFocus and SetFocus).

Can I show a window without showing Windows Explorer taskbar?

I have created a new window using C + Win32 API, and I attached it to a game.
The game runs on Windowed (no border) mode, which means that it's simply a big window which is shown over the taskbar, creating the effect of a full-screen mode.
I've binded F11 to pop-up the console with:
ShowWindow(hConsole, SW_HIDE);
ShowWindow(hConsole, SW_SHOW);
That pop-ups the console window, and it works fine, except that it also shows the taskbar.
Is there any way to make the game still stay over the task bar, while showing the console?

How to keep window inactive on simulated clicks?

I made a program in C++ that simulates clicks on an inactive window using:
PostMessage (z, WM_LBUTTONDOWN, 0,MAKELONG(t.left+x,t.top+y));
But whenever it makes a click it activates the window and the window moves to the top.
Is there a way I can make the window stay inactive or another way to click it?
I used SetWindowPos(z , HWND_BOTTOM,....) to make that window be at the bottom of the z-order list but it still activates.
EDIT: the window is a game console
Try switching from PostMessage to SendInput and see if you get the same effect.