Win32: How to hide 3rd party windows in taskbar by hWnd - c++

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.

Related

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.

embed window(glfwCreateWindow) as child to C++ MFC parent form

Please refer this link
Embedding a GLFW window inside windows forms
How can the same achieved by using VC++ to embed glfw window to Parent form?
Try this:
Call glfwWindowHint() to set GLFW_DECORATED and GLFW_VISIBLE to false.
Call glfwCreateWindow().
Call glfwGetWin32Window() to get the native handle of the OpenGL window.
Call SetParent() to set your form as the new parent of the OpenGL window.
Call GetWindowLong() / SetWindowLong() to remove the WS_POPUP and add the WS_CHILDWINDOW style for the OpenGL window.
Call ShowWindow() to finally make the OpenGL window visible.
I got this from github.com/Chronial/foo_chronflow :: EngineWindow.cpp.
You might also call SetWindowPos() to adjust the position of the OpenGL window within your form.
The link in zett42's post is dead, so here's a more complete snippet
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
GLFWwindow* pWindow = glfwCreateWindow(width, height, "", NULL, NULL);
HWND hwNative = glfwGetWin32Window(m_pWindow);
SetParent(hwNative, hwParentWindow);
long style = GetWindowLong(hwNative, GWL_STYLE);
style &= ~WS_POPUP; // remove popup style
style |= WS_CHILDWINDOW; // add childwindow style
SetWindowLong(hwNative, GWL_STYLE, style);
... any other initialisation code (e.g enable/disable gl features) ...
ShowWindow(hwNative, SW_SHOW);

How to change console window style at runtime?

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

avoid windows resizing with double click

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

C++ WinAPI Need Help Stuck At Making Window Minimize With Left Click Taskbar Programmatically

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.