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.