Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide A Console C++ Program From Taskbar

I have a little console game that calls another console app. Something like Winamp's many windows (main and playlist). The thing is when I call two for example console windows the programs opened in the taskbar get too many, I don't need to open the windows separately, I want only the main window to stay in the taskbar and when I click on it, it and all its child apps to pop up.

P.S. I am familiar with ShowWindow ( GetConsoleWindow(), SW_HIDE );, but it hides the window as well and I want it to be hidden only from the taskbar.

like image 566
Bonnev Avatar asked Apr 15 '13 15:04

Bonnev


2 Answers

Thanks to Captain Obvlious and some research, the following code:

ITaskbarList *pTaskList = NULL;
HRESULT initRet = CoInitialize(NULL);
HRESULT createRet = CoCreateInstance( CLSID_TaskbarList,
                                      NULL,
                                      CLSCTX_INPROC_SERVER,
                                      IID_ITaskbarList,
                                      (LPVOID*)&pTaskList );

if(createRet == S_OK)
{

    pTaskList->DeleteTab(GetConsoleWindow());

    pTaskList->Release();
}

CoUninitialize();

with included ShObjIdl.h works great!

Note: You should get S_OK as a value in initRet and createRet!

like image 59
Bonnev Avatar answered Sep 20 '22 19:09

Bonnev


The only way I am aware of to accomplish this on a console window is to use the shell interface ITaskbarList.

hr = CoCreateInstance(
    CLSID_TaskbarList,
    NULL,
    CLSCTX_INPROC_SERVER,
    IID_ITaskbarList,
    reinterpret_cast<void**>(&taskbar));
if(!FAILED(hr))
{
    // Remove the icon from the task bar
    taskbar->DeleteTab(GetConsoleWindow());
    // Release it
    taskbar->Release();
}
like image 33
Captain Obvlious Avatar answered Sep 19 '22 19:09

Captain Obvlious