How can I determine when my application is minimized?

I have a program with the ability to include minimization in the notification area of โ€‹โ€‹the taskbar. For this to work, I need a reliable way to detect when the user has minimized the application.

How to do this using the Windows API in a C ++ application?

+4
source share
4 answers

When the user minimizes the window (either using the field in the title bar or selecting "Minimize" in the system menu), your application will receive WM_SYSCOMMAND . The wParam parameter of this message will contain an SC_MINIMIZE value that indicates the specific type of system command requested. In this case, you do not care about lParam .

So, you need to configure a message card that listens for the WM_SYSCOMMAND with wParam set to SC_MINIMIZE . After receiving such a message, you must execute your code to minimize your application in the notification area of โ€‹โ€‹the taskbar, and return 0 (indicating that you have processed the message).

I am not sure which GUI you are using. Sample code can potentially be very different for different toolkits. Here is what you can use in a direct Win32 C application:

 switch (message) { case WM_SYSCOMMAND: if ((wParam & 0xFFF0) == SC_MINIMIZE) { // shrink the application to the notification area // ... return 0; } break; } 
+4
source

I think you are looking for WM_SIZE. When you get this, check wParam to get the specifics. Here is the MSDN page.

WM_SIZE

0
source

You can check the size of the area returned with GetClientRect - if the zero value is minimized, it works for me, but it may not work in all cases.

0
source

That IsIconic should define, but it does not work consistently for me. (Oh, for a consistent definition of this ...)

0
source

Source: https://habr.com/ru/post/1339314/


All Articles