如何检测我的应用程序最小化? [英] How could I detect when my application is minimized?

查看:159
本文介绍了如何检测我的应用程序最小化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序具有启用最小化任务栏的通知区域的选项。为了这个工作,我需要一个可靠的方法来检测用户何时最小化应用程序。

I have a program with an option to enable minimizing to the taskbar's notification area. In order for this to work, I need a reliable way of detecting when the user has minimized the application.

如何在C ++应用程序中使用Windows API

How can I do that using the Windows API in a C++ application?

推荐答案

当用户最小化窗口时(使用标题栏上的框或通过选择最小化从系统菜单),您的应用程序将收到 WM_SYSCOMMAND 消息。该消息的 wParam 参数将包含值 SC_MINIMIZE ,其指示正在请求的系统命令的特定类型。在这种情况下,你不关心 lParam

When the user minimizes the window (either using the box on the title bar, or by selecting the "Minimize" option from the system menu), your application will receive a WM_SYSCOMMAND message. The wParam parameter of that message will contain the value SC_MINIMIZE, which indicates the particular type of system command that is being requested. In this case, you don't care about the lParam.

所以你需要设置一个消息映射侦听 WM_SYSCOMMAND 消息,并将 wParam 设置为 SC_MINIMIZE 。收到此类邮件后,您应该执行代码以最小化对任务栏通知区域的应用,并返回0(表示您已处理邮件)。

So you need to set up a message map that listens for a WM_SYSCOMMAND message with the wParam set to SC_MINIMIZE. Upon receipt of such a message, you should execute your code to minimize your application to the taskbar notification area, and return 0 (indicating that you've processed the message).

我不知道你使用的是什么GUI框架。示例代码对于不同的工具包可能看起来非常不同。这里是你可能在一个直接的Win32 C应用程序中使用:

I'm not sure what GUI framework you're using. The sample code could potentially look very different for different toolkits. Here's what you might use in a straight Win32 C application:

switch (message)
{
case WM_SYSCOMMAND:
    if ((wParam & 0xFFF0) == SC_MINIMIZE)
    {
        // shrink the application to the notification area
        // ...

        return 0;
    }
    break;
}

这篇关于如何检测我的应用程序最小化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆