如何取托盤窗口

  有朋友在工做中須要獲得托盤窗口,請我幫忙,因而我就簡單地寫下來了。想一想或許對你們有幫助,因此我就轉到這裏來,希望能幫到你。小程序

CWnd* GetTrayWindow()
{
    CWnd* pTrayWnd = CWnd::FindWindow(_T("Shell_TrayWnd"), NULL);
    if(pTrayWnd != NULL)
    {
        CWnd* pNotifyWnd = CWnd::FindWindowEx(pTrayWnd->m_hWnd, NULL, _T("TrayNotifyWnd"), NULL);
        if(pNotifyWnd != NULL)
        {
            CWnd* pSysPager = CWnd::FindWindowEx(pNotifyWnd->m_hWnd, NULL, _T("SysPager"), NULL);
            if(pSysPager != NULL)
            {
                return CWnd::FindWindowEx(pSysPager->m_hWnd, NULL, _T("ToolbarWindow32"), NULL);
            }
ide

            return  CWnd::FindWindowEx(pNotifyWnd->m_hWnd, NULL, _T("ToolbarWindow32"), NULL);
        }
    }
測試

    return NULL;
}
this

 

爲了驗證獲得的窗口是不是本身須要的,寫一個測試小程序,把獲得的內容繪製出來看看(其它代碼省略)。spa

void CChildView::OnPaint()
{
    CPaintDC dc(this); // 用於繪製的設備上下文
   
    CWnd* pToolbarWindow = GetTrayWindow();
    if(pToolbarWindow != NULL)
    {
        CRect rect;
        pToolbarWindow->GetClientRect(&rect);
it

        CClientDC dcWin(pToolbarWindow);
        dc.BitBlt(100, 100, rect.Width(), rect.Height(), &dcWin, 0, 0, SRCCOPY);
    }           
   
    // 不要爲繪製消息而調用 CWnd::OnPaint()
}
class

若是代碼能夠正常工做並能幫到你,這段代碼是我本身寫的。若是不能正常工做,對不起,我也不知道是誰寫的。程序

相關文章
相關標籤/搜索