有朋友在工做中须要获得托盘窗口,请我帮忙,因而我就简单地写下来了。想一想或许对你们有帮助,因此我就转到这里来,希望能帮到你。小程序
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
若是代码能够正常工做并能帮到你,这段代码是我本身写的。若是不能正常工做,对不起,我也不知道是谁写的。程序