I'm making a game in console application and I want to prevent user resizing and maximizing window. How can I do this using HWND?
I found solution. This code will disable window Size and Maximize box:
HWND consoleWindow = GetConsoleWindow();
SetWindowLong(consoleWindow, GWL_STYLE, GetWindowLong(consoleWindow, GWL_STYLE) & ~WS_MAXIMIZEBOX & ~WS_SIZEBOX);
Related
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.
I've spent many hours on google and haven't found any relevent results on this particular subject.
I have an application I am wanting to be minimized when the user clicks on it in the taskbar (if it's not already minimized). The problem seems to be related to the fact the window is borderless. When I set it to have a border, it minimizes just fine when clicking it in the taskbar, without any code intervention. But I need the window borderless because I'm making a "custom border" using the client area.
tl;dr how do I check if the current application is being clicked in the taskbar?
Many thanks!
Samuel
There is no need to tinker with the taskbar.
Just make sure you have the WS_MINIMIZEBOX|WS_MAXIMIZEBOX styles set for your window. Otherwise your window won't handle WM_SYSCOMMAND with a wParam of SC_MINIMIZE and SC_RESTORE.
Some resource editors like the one in Visual Studio make it impossible to set WS_MINIMIZEBOX|WS_MAXIMIZEBOX when you remove the standard window border. You may programmatically add the styles back like this:
DWORD style = GetWindowLong( hwnd, GWL_STYLE );
SetWindowLong( hwnd, GWL_STYLE, style | WS_MINIMIZEBOX | WS_MAXIMIZEBOX );
Related with this post
I tried to disable window resizing. So I disabled wxDEFAULT_FRAME_STYLE and wxRESIZE_BORDER options on my wxFrame... and it works.
But now, if user makes a double click over caption bar, the windows is resized again.
How could I avoid windows resizing when user make a double click over caption bar?
Thanks.
You need to remove the wxMAXIMIZE_BOX style.
As per comments, you've been having problems doing this, or perhaps the wxWidgets that you are using does not map through to the underlying window style. If that is the case then you can remove the WS_MAXIMIZEBOX window style like this:
DWORD style = GetWindowLongPtr(hwnd, GWL_STYLE);
SetWindowLongPtr(hwnd, GWL_STYLE, style & ~WS_MAXIMIZEBOX);
I'm making a custom caption bar with custom draw buttons by removing the window default bar with SetWindowLong(hWndParent, GWL_STYLE, 0). Everything is going good by now except I'm stuck at making my window minimize by clicking the taskbar programmatically. I'm trying the WM_ACTIVATEAPP right now but the window are unable to minimize properly.
This is the code for WM_ACTIVATEAPP for main window:
case WM_ACTIVATEAPP:
if(LOWORD(wParam) == FALSE)
SendMessage(hWndParent,WM_SYSCOMMAND,SC_MINIMIZE,NULL);
break;
When you left click the task bar,it will minimize BUT once you released the click.. the window will be restored.. Is there something missing? I want to make it minimize after you release the click.
Notes: I dint put the activate window code because the window seems to be able to restore itself by clicking the taskbar after being minimized with custom draw button.
You're probably not handling WM_NCACTIVATE as well. Try handling it, similar to this:
case WM_NCACTIVATE:
break;
case WM_ACTIVATEAPP:
if (LOWORD(wParam) == FALSE)
SendMessage(hWnd, WM_SYSCOMMAND, SC_MINIMIZE, NULL);
break;
Edit:
I must have missed the part of your question where you said you removed the default bar by setting the style to 0. That is definitely not the proper way to do it, you should do something along the lines of this, as found here:
LONG lStyle = GetWindowLong(hWnd, GWL_STYLE);
lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
SetWindowLong(hWnd, GWL_STYLE, lStyle);
After you do that you should no longer need to handle WM_ACTIVATEAPP or WM_NCACTIVATE to properly minimize/maximize the window.
I have to hide popup windows in third party library.
I have implemented windows hook stuff with SetWindowsHookEx and know all the newely created hWnd(s). I listen to HSHELL_WINDOWCREATED callback and do the following:
long style= GetWindowLong(hWnd, GWL_STYLE);
style &= ~(WS_VISIBLE); // this works - window become invisible
style |= WS_EX_TOOLWINDOW; // flags don't work - windows remains in taskbar
style &= ~(WS_EX_APPWINDOW);
SetWindowLong(hWnd, GWL_STYLE, style);
What I do wrong here to hide newely created windows in task bar?
Before you use SetWindowLong, call ShowWindow(hWnd, SW_HIDE), then call SetWindowLong, then call ShowWindow again like ShowWindow(hWnd, SW_SHOW). So your code will look like this:
long style= GetWindowLong(hWnd, GWL_STYLE);
style &= ~(WS_VISIBLE); // this works - window become invisible
style |= WS_EX_TOOLWINDOW; // flags don't work - windows remains in taskbar
style &= ~(WS_EX_APPWINDOW);
ShowWindow(hWnd, SW_HIDE); // hide the window
SetWindowLong(hWnd, GWL_STYLE, style); // set the style
ShowWindow(hWnd, SW_SHOW); // show the window for the new style to come into effect
ShowWindow(hWnd, SW_HIDE); // hide the window so we can't see it
Here is a relevant quote from Microsoft's Website:
To prevent the window button from being placed on the taskbar, create
the unowned window with the WS_EX_TOOLWINDOW extended style. As an
alternative, you can create a hidden window and make this hidden
window the owner of your visible window.
The Shell will remove a window's button from the taskbar only if the
window's style supports visible taskbar buttons. If you want to
dynamically change a window's style to one that doesn't support
visible taskbar buttons, you must hide the window first (by calling
ShowWindow with SW_HIDE), change the window style, and then show the
window.
You must use GWL_EXSTYLE to get/set the EX flags, GWL_STYLE will not work for EX flags.