Win32: Is it possible to show the window but to hide it from taskbar? - c++

If I have an win32 application with several windows, is it possible to show a window but hide the window icon in the taskbar?
I have tried creating the window with WS_EX_TOOLWINDOW and WS_EX_APPWINDOW.

You have a few options:
Tool windows do not have taskbar buttons. Create a tool window by including the WS_EX_TOOLWINDOW extended window style.
Owned windows without the WS_EX_APPWINDOW extended style do not have taskbar buttons.
Hidden windows do not have taskbar buttons.
Option 1 is simple enough. If you don't want to use a tool window, use a combination of 2 and 3. Create a hidden unowned window that is the owner of your main window.

Related

Creating a POPUP style window

I have an answer regarding creation of the POPUP style window. The thing that do really bothers me is the hWndParent parameter. The docs says:
This parameter is optional for pop-up windows
My question is how does the POPUP window created with the hWndParent parameter set just to NULL behaves? Does it belong to the desktop itself? How is it z-ordered/displayed on the screen? Does it spwan above all other windows or just only over the desktop such that other windows covers it?
I suggest you could refer to the Doc: Window Features
A pop-up window is a special type of overlapped window used for dialog boxes, message boxes, and other temporary windows that appear outside an application's main window. Title bars are optional for pop-up windows; otherwise, pop-up windows are the same as overlapped windows of the WS_OVERLAPPED style.
An overlapped window is a top-level window (non-child window) that has a title bar, border, and client area; it is meant to serve as an application's main window.

Remove window from taskbar on Windows 10

I want to remove window from taskbar on Windows 10 with multiple desktops.
For Windows 8.1 i used ITaskbarList::DeleteTab and it works excellent.
For Windows 10 this method hides Windows from taskbar too, but after it i see this window on all desktops. I want to see this window only on one desktop.
Does anyone know the method to hide window from task bar in Windows 10 and stay this window on one desktop?
Below you can see, what i meant under "hide window from task bar in Windows 10":
In my understanding, borne out by my empirical tests, the windows that appear in the taskbar previews are exactly the same windows that would ordinarily appear in the taskbar. A long time ago, say in Windows 2000, each of an application's eligible windows would just appear as buttons on the taskbar. Starting in Windows XP, taskbar grouping became an option, so that all eligible windows from a single application could be grouped together and appear as a single button on the taskbar. Then, in Windows Vista, it became possible to display previews of these open windows when you hovered over the corresponding taskbar button. Neither Windows 8 nor Windows 10 changed that fundamental rule; they only changed the appearance of the previews.
As such, we can refer back to the MSDN documentation for the rules about which windows appear on the taskbar:
The Shell creates a button on the taskbar whenever an application creates a window that isn't owned. To ensure that the window button is placed on the taskbar, create an unowned window with the WS_EX_APPWINDOW extended style. 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.
Raymond Chen has summarized these rules more precisely here. Quoting him:
There are some basic rules on which windows go into the taskbar. In short:
If the WS_EX_APPWINDOW extended style is set, then it will show (when visible).
If the window is a top-level unowned window, then it will show (when visible).
Otherwise it doesn't show.
(Though the ITaskbarList interface muddies this up a bit.)
You were muddying it up before, calling ITaskbarList::DeleteTab. That is not necessary. To ensure that a window does not appear in the taskbar, just apply the converse of the rules governing when a window does appear in the taskbar.
If you have a top-level unowned window, it will be shown in the taskbar unless you remove the WS_EX_APPWINDOW extended window style. If you have an owned window, then it will not be shown in the taskbar unless the WS_EX_APPWINDOW extended window style is set to force it there.
So if you have the WS_EX_APPWINDOW extended window style set, you should remove it. That is forcing the window to be displayed in the taskbar.
Otherwise, you should set an owner for your window. For example, make the second window be owned by the first.
TL;DR:
Remove both WS_EX_APPWINDOW and WS_EX_TOOLWINDOW from the extended style.
Set an owner for the window.
Example:
Removing flags from the extended style:
SetWindowLong(myHWND, GWL_EXSTYLE,
GetWindowLong(myHWND, GWL_EXSTYLE) & ~WS_EX_APPWINDOW & ~WS_EX_TOOLWINDOW);
Setting an owner:
SetWindowLongPtr(myHWND, GWLP_HWNDPARENT, myOwnerHWND);
Full explanation:
Despite Cody's answer being great, it does not quite answer the exact question.
The exact question is: "How to display a window that does not appear in the taskbar, yet appears only on one virtual desktop?
As Cody explained, there are several ways to remove the taskbar button for a window. However, there is only one way among them that makes it display on only one virtual desktop at the same time.
If you include the flag WS_EX_APPWINDOW in your extended style, it will force the window to show in the taskbar. That's why it must be cleared in this case.
If you include the flag WS_EX_TOOLWINDOW in your extended style, it will force the window not to show in the taskbar, but will force the window to be shown on all virtual desktops. Thus it's not an option either here.
Finally, if your window has neither flags, it will show in the taskbar if and only if it does not have an owner. Either way, it will not force itself on all virtual desktops. Hence, the solution is to have neither flags but to set an owner.
Add WS_EX_NOACTIVATE to the ex styles of the window.
https://learn.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles
A top-level window created with this style does not become the
foreground window when the user clicks it. The system does not bring
this window to the foreground when the user minimizes or closes the
foreground window. The window should not be activated through
programmatic access or via keyboard navigation by accessible
technology, such as Narrator. To activate the window, use the
SetActiveWindow or SetForegroundWindow function. The window does not
appear on the taskbar by default. To force the window to appear on the
taskbar, use the WS_EX_APPWINDOW style.

Constraining draggable child windows within parent window?

Please take a look at this screenshot:
As you can see, the "Executable modules" and "Threads" child windows are free to roam about in the sandbox-like "Themida" parent window, and if they get dragged past the edge the overflow simply gets hidden. How can I create this effect?
That is a Multiple Document Interface (MDI) application. The containing window, with the dark grey background is the MDI client window, and the windows inside are the MDI child windows.
The use of MDI has been discouraged by Microsoft for many years so you may wish to think twice about using it in a new application.
Simply set the window style to WS_CHILD, and the window will be confined in the parent client rectangle.
You can do this during window creation, or after using SetWindowLongPtr() and GetWindowLongPtr():
SetWindowLongPtr(hwnd, GWL_STYLE, WS_CHILD | GetWindowLongPtr(hwnd, GWL_STYLE));
P.S. You don't need to create an MDI application to have this behavior.

How do you have a window that has no icon in the tasktray?

I found the windows style WS_EX_TOOLWINDOW but this changes the title bar. Is there a way to not have the tasktray icon but keep the normal window titlebar?
You usually do want to do this if you have added an alternate means to restore the window - for example placing an icon in the notification tray.
The usual way of ensuring the taskbar does not display your window is to create it with a hidden parent window. Whenever a window has a parent, the parent window is used to create the button - hidden windows are not shown on the taskbar.
Also, WS_EX_APPWINDOW should be removed as that performs the opposite hint to the shell and forces the window onto the taskbar even if it would otherwise not have been shown.

How do I display a CFormView in a mainframe?

I created an SDI MFC app without the doc/view support. The MFC template gives me an app with a blank window (And a menu, etc)
I want to show my CFormView object on that main window. (Based on a dlg made in the gui editor)
How do I do that? CreateWindow and showwindow don't seem to be all that is needed. All the web pages I find seem to talk about MDI and other stuff that is not in my app.
This view is never going to change. It will have one list box control on it and that is all. How do I get a new form view to appear?
Additionally, how do I get a floating window with one control on it to appear as well? (DLG boxes and DoModal() will not work for me here.)
Give your CFormView the WS_CHILD style
Create it as a MODELESS dialog with the app window as the parent window
resize it to fit the parent's client area, or resize the parent to fit it.
The WS_CHILD style is not a default style for a dialog template, but you can add it.
this will cause the dialog to show up inside the client area of the main frame window you when create it.
You may also want to add a call to IsDialogMessage() to your message pump. This is needed get the TAB key to behave the way you expect it do in a dialog.
Edit ----
I'm not an MFC programmer, so I can only guess how you would go about this in MFC.
Presumably you still have dialog templates, so you would go into your .RC file
and remove the WS_POPUP and add the WS_CHILD style to your template declaration. like this:
IDD_WHATEVER DIALOG DISCARDABLE 0, 0, 275, 217
STYLE DS_MODALFRAME | DS_3DLOOK | WS_CHILD | WS_VISIBLE
CAPTION "General"
FONT 8, "MS Sans Serif"
BEGIN
// etc
END
Modeless dialogs are created in Win32 by using CreateDialog rather than DialogBox, in
MFC by using Create() rather than DoModal().