c++ - What message is sent when you minimize a window?
问题描述
I'm catching WindowProc
and looking for WM_SYSCOMMAND
/ SC_MINIMIZE
, but it only fires the message when I minimize the window by clicking in its taskbar icon.
When I click in the window's minimize button the message isn't fired.
switch (Msg)
{
case WM_SYSCOMMAND:
switch (wParam)
{
case SC_MINIMIZE:
{
OutputDebugStringW(L"Window minimized!");
//return TRUE;
}
}
break;
}
I noticed that my window was not sending the WM_SIZE
message, then while searching i have found this:
By default, the DefWindowProc function sends the WM_SIZE and WM_MOVE messages to the window. The WM_SIZE and WM_MOVE messages are not sent if an application handles the WM_WINDOWPOSCHANGED message without calling DefWindowProc. It is more efficient to perform any move or size change processing during the WM_WINDOWPOSCHANGED message without calling DefWindowProc.
I confirmed that its sending WM_WINDOWPOSCHANGED
when i try to minimize by clicking in the minimize button.
case WM_WINDOWPOSCHANGING:
tagWINDOWPOS * wp = reinterpret_cast<tagWINDOWPOS *>(lParam);
wp->x = ...;
wp->y = ...;
wp->cx = ...;
wp->cy = ...;
LPARAM lp = reinterpret_cast<LPARAM>(wp);
I have tried to set x, y, cx, cy
values to the current ones, but the window still got minimized.
解决方案
当窗口大小改变时,WM_SIZE
消息被发送到窗口;如果该大小更改是为了最小化窗口,那么wParam
参数将为SIZE_MINIMIZED
. (这WM_SIZE
也将在WM_SYSCOMMAND
/SC_MINIMIZE
组合之后发送,因此您可以检测到最小化操作,无论是什么用户操作触发了它。)
因此,您的代码WndProc
将遵循以下几行:
switch (Msg) {
case WM_SIZE:
switch (wParam) {
case SIZE_MINIMIZED:
OutputDebugStringW(L"Window minimized!");
// return TRUE;
break;
//...
}
break;
//...
}
推荐阅读
- c# - 在 C# 中实现莫顿 Z 曲线的有效性
- python - 如何将元组拆分为两个列表?
- c - C中的字符赋值
- django - 将表单查询字符串(自定义查询集)传递给 Django Detailview
- mysql - sha256_password 已弃用警告填充日志
- entity-framework - 使用 Pomelo NUGET 包在带有实体框架和 MariaDB 的 blob 列表上尝试 SaveChanges 时出现 SocketException
- php - 将 POST 数据从 NodeJs 发送到 PHP Symfony 5
- sql - 理解 Sum(1) sum(2) sum(3)
- javascript - 检查值类型作为对象数组中的对象 - Javascript
- r - 跨数据集的 ggplot 密度图列表