获得桌面窗口
void CDemoDlg::OnTest()
{
//获得桌面窗口
CWnd* pWnd = CWnd::GetDesktopWindow();
//获得窗口大小
CRect rect;
pWnd->GetClientRect(rect);
CString strText = _T("");
strText.Format(_T("桌面窗口大小:%d×%d"),
rect.Width(), rect.Height());
AfxMessageBox(strText);
}
桌面所有窗口最小化
用FindWindow方法查找名为Shell_TrayWnd的类名获取任务栏窗体,然后发送消息
void CDemoDlg::OnTest()
{
//获得任务栏窗口
CWnd* pWnd = CWnd::FindWindow(_T("Shell_TrayWnd"), NULL);
//发送ID为0x1F5(Win + M)的WM_HOTKEY消息
pWnd->SendMessage(WM_HOTKEY, 0x1F5);
}
获得任务栏窗口
void CDemoDlg::OnTest()
{
//获得任务栏窗口
CWnd* pWnd = CWnd::FindWindow(_T("Shell_TrayWnd"), NULL);
//获得窗口大小
CRect rect;
pWnd->GetClientRect(rect);
CString strText = _T("");
strText.Format(_T("任务栏窗口大小:%d×%d"),
rect.Width(), rect.Height());
AfxMessageBox(strText);
}
显示或隐藏任务栏
void CDemoDlg::OnTest1()
{
//获得任务栏窗口
CWnd* pWnd = CWnd::FindWindow(_T("Shell_TrayWnd"), NULL);
//隐藏窗口
if (pWnd->IsWindowVisible())
{
pWnd->ShowWindow(SW_HIDE);
}
}
void CDemoDlg::OnTest2()
{
//获得任务栏窗口
CWnd* pWnd = CWnd::FindWindow(_T("Shell_TrayWnd"), NULL);
//显示窗口
if (!pWnd->IsWindowVisible())
{
pWnd->ShowWindow(SW_SHOW);
}
}