You mean the icon in the taskbar when the application is running? Why would you even be concerned about that? An MFC application has a dialog or window that is visible to the user then why not the icon in the task bar?

OK, for the sake of answering the question, when creating your main window (with CreateWindowEx API and not with CreateWindow macro), include in the extended window style the WS_EX_TOOLWINDOW. But you'll have title bar which is awkward for a main window. If you are using a dialog box as your main window, find in the dialog box's properties any property that corresponds to that extended style. In VC++ 6, it was a checkbox button in the extended window style page. In VC2010, it is a boolean property.

ITaskbarIcon interface give's you more control on what appears on the taskbar.

I use the following and link to "Shell32" and "Ole32":

    #include <windows.h>
    #include <shobjidl.h>

    const GUID CLSID_TaskbarList = {0x56FDF344, 0xFD6D, 0x11D0, {0x95, 0x8A, 0x00, 0x60, 0x97, 0xC9, 0xA0, 0x90}};
    const GUID IID_ITaskbarList = {0x56FDF342, 0xFD6D, 0x11D0, {0x95, 0x8A, 0x00, 0x60, 0x97, 0xC9, 0xA0, 0x90}};
    const GUID IID_ITaskbarList2 = {0x602D4995, 0xB13A, 0x429b, {0xA6, 0x6E, 0x19, 0x35, 0xE4, 0x4F, 0x43, 0x17}};
    const GUID IID_ITaskList3 = {0xEA1AFB91, 0x9E28, 0x4B86, {0x90, 0xE9, 0x9E, 0x9F, 0x8A, 0x5E, 0xEF, 0xAF}};


    void ShowTaskbarIcon(HWND WindowHandle)
    {
        ITaskbarList* TaskListPtr;
        CoInitialize(nullptr);
        long Result = !CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_SERVER, IID_ITaskbarList, reinterpret_cast<void**>(&TaskListPtr));
        if (Result) TaskListPtr->AddTab(WindowHandle);
        TaskListPtr->Release();
        CoUninitialize();
    }

    void HideTaskbarIcon(HWND WindowHandle)
    {
        ITaskbarList* TaskListPtr;
        CoInitialize(nullptr);
        long Result = !CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_SERVER, IID_ITaskbarList, reinterpret_cast<void**>(&TaskListPtr));
        if (Result) TaskListPtr->DeleteTab(WindowHandle);
        TaskListPtr->Release();
        CoUninitialize();
    }

Edited 3 Years Ago by triumphost

Ugh! Got myself corrected by triumphost. I meant ITaskbarList. But I want to point two lines in your post that may cause an access violation error: These are on lines 16 and 26.

Edited 3 Years Ago by RonalBertogi

Comments
Yeah forgot to put that in the if statement. Thanks :D
This article has been dead for over six months. Start a new discussion instead.