代码改变世界

Win32 窗口篇(4)

  Clingingboy  阅读(3397)  评论(3编辑  收藏  举报

 

 

1.16 如何实现图片窗口

 

1.17 如何实现动画窗口

The AnimateWindow function enables you to produce special effects when showing or hiding windows. There are four types of animation: roll, slide, collapse or expand, and alpha-blended fade.

 

//显示动画窗口
AnimateWindow(500, AW_BLEND);

 

1.18 如何获得桌面窗口

GetDesktopWindow:
This function returns a handle to the desktop window. The desktop window covers the entire screen. The desktop window is the area on top of which all icons and other windows are painted.

 

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);
}

 

1.19 如何使桌面所有窗口最小化

用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);
}

 

1.20 如何获得任务栏窗口

同上方法

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);
}

 

1.21 如何显示或隐藏任务栏

用IsWindowVisible判断窗体是否隐藏,然后用ShowWindow方法隐藏和显示窗体

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);
    }    
}

效果如下:隐藏后就没有任务栏了

image

1.22 如何枚举桌面所有顶层窗口

编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示