ITaskbarList3

We can NOT use ITaskbarlist3 until windows has finished creation of button on taskbar.

So, we have to wait a message.

1. Get the message value

::RegisterWindowMessage("TaskbarButtonCreated");

 

2. Allow receiving message from explorer.exe and Wait windows to notify us and create intance.

// .h
class CMainDlg : public CDialogImpl<CMainDlg>
{
private:
    static const UINT m_taskbarBtnCreatedMsg;
    ITaskbarList3 *m_pTl3 = nullptr;

public:
    BEGIN_MSG_MAP(CMainDlg)
        MESSAGE_HANDLER_EX(m_taskbarBtnCreatedMsg, OnTaskbarBtnCreated)
        // other message handlers...
    END_MSG_MAP()
 
    LRESULT OnTaskbarBtnCreated(UINT uMsg, WPARAM wParam, LPARAM lParam);
};
 
const UINT CMainDlg::m_taskbarBtnCreatedMsg
               = RegisterWindowMessage("TaskbarButtonCreated"); // 1. The message which is sent by windows. Should be initialized during app's startup sequence.

// .cpp
BOOL CMainDlg::OnInitDialog(HWND hwndFocus, LPARAM lParam)
{
    // 2. Allow process to receive message from explorer.exe of LOWER priority.
    CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) };
    ChangeWindowMessageFilterEx(m_hWnd, m_taskbarBtnCreatedMsg, MSGFLT_ALLOW, &cfs);
 
    return TRUE;
}

LRESULT CMainDlg::OnTaskbarBtnCreated ( UINT uMsg, WPARAM wParam, LPARAM lParam )
{
    CoCreateInstance(CLSID_TaskbarList,             // 3. Wait for that message, and create instance.
                     NULL, 
                     CLSCTX_ALL, 
                     __uuidof(ITaskbarList3), 
                     reinterpret_cast<void **>(&m_pTl3));return 0;
}

 

 

4. Increase or decrease the taskbar progress.

m_pTl3->SetProgressValue(m_hWnd, 45, 100);          // 4. Set progress.

 

Different state:

m_pTl3->SetProgressState(m_hWnd, TBPF_NOPROGRESS);  // Clear.

 

m_pTl3->SetProgressState(m_hWnd, TBPF_INDETERMINATE);// Save the current progress, and clear the progress. 
 

m_pTl3->SetProgressValue(m_hWnd, ++i, 100); // The next time you Set "TBPF_NORMAL" will restore the progress.

 

m_pTl3->SetProgressState(m_hWnd, TBPF_ERROR);       // Red.

 

m_pTl3->SetProgressState(m_hWnd, TBPF_PAUSED);      // Yellow.

 

5. Release it and set to nullptr

m_pTl3->Release();
m_pTl3 = nullptr;

 

reference: http://www.codeproject.com/Articles/42345/Windows-7-Goodies-in-C-Taskbar-Progress-and-Status

posted @ 2012-11-13 15:23  walfud  阅读(1872)  评论(0编辑  收藏  举报