有朋友在工作中需要得到托盤視窗,請我幫忙,于是我就簡單地寫下來了。想想或許對大家有幫助,是以我就轉到這裡來,但願能幫到你。
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);
}
return CWnd::FindWindowEx(pNotifyWnd->m_hWnd, NULL, _T("ToolbarWindow32"), NULL);
}
}
return NULL;
}
為了驗證得到的視窗是否是自己需要的,寫一個測試小程式,把得到的内容繪制出來看看(其它代碼省略)。
void CChildView::OnPaint()
CPaintDC dc(this); // 用于繪制的裝置上下文
CWnd* pToolbarWindow = GetTrayWindow();
if(pToolbarWindow != NULL)
CRect rect;
pToolbarWindow->GetClientRect(&rect);
CClientDC dcWin(pToolbarWindow);
dc.BitBlt(100, 100, rect.Width(), rect.Height(), &dcWin, 0, 0, SRCCOPY);
}
// 不要為繪制消息而調用 CWnd::OnPaint()
如果代碼可以正常工作并能幫到你,這段代碼是我自己寫的。如果不能正常工作,對不起,我也不知道是誰寫的。
本文轉自 bluebee 51CTO部落格,原文連結:http://blog.51cto.com/bluebee/286614,如需轉載請自行聯系原作者