如何在MFC中捕获WM_SHOWWINDOW命令

发布于 2024-12-02 21:30:52 字数 265 浏览 0 评论 0原文

每当显示对话框时我都尝试执行一些操作。就像我们有无模式对话框,并且我们在单击某些按钮时隐藏/显示对话框。但是每当显示对话框时我们都需要执行一些操作。我已添加 WM_SHOWWINDOW 消息,但控件未进入 OnShowWindow(BOOL bShow, UINT nStatus) 函数内部。

我们使用 ShowWindow(SW_HIDE) 和 ShowWindow(SW_SHOW) 函数来隐藏/显示对话框 请建议一些如何实现这一目标的指示。

预先感

谢穆克什

I am trying to do some action whenever dialog box is Shown. Its like we have modalless dialog, and we are hinding/showing the dialog on some button click. But we we need to perfomr some action whenever dialog is shown. I have added the WM_SHOWWINDOW message but control is not coming inside of OnShowWindow(BOOL bShow, UINT nStatus) function.

We are using ShowWindow(SW_HIDE) and ShowWindow(SW_SHOW) function to hide/show dialog box
Please suggest some pointer how to achieve that.

Thanks in advance

Mukesh

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你好,陌生人 2024-12-09 21:30:52

我使用记事本和 Spy++ 使用以下代码对此进行了测试:

#include <Windows.h>

int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) {
  HWND hwnd = FindWindow(NULL, L"Untitled - Notepad");
  ShowWindow( hwnd, SW_HIDE );
  Sleep(4000);
  ShowWindow( hwnd, SW_SHOW );
  return ERROR_SUCCESS;
}

为了隐藏窗口,您应该获得 WM_SHOWWINDOW、WM_WINDOWPOSCHANGING,最后是 WM_WINDOWPOSCHANGED。

为了显示窗口,目标没有收到 WM_SHOWWINDOW,但仍然收到 WM_WINDOWPOSCHANGING 和 WM_WINDOWPOSCHANGED。

您可以处理 WM_WINDOWPOSCHANGED 并检查 WINDOWPOS 中 SWP_HIDEWINDOW/SWP_SHOWWINDOW 的标志。

I tested this with notepad and Spy++ with the following code:

#include <Windows.h>

int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) {
  HWND hwnd = FindWindow(NULL, L"Untitled - Notepad");
  ShowWindow( hwnd, SW_HIDE );
  Sleep(4000);
  ShowWindow( hwnd, SW_SHOW );
  return ERROR_SUCCESS;
}

For hiding the window, you should be getting WM_SHOWWINDOW, WM_WINDOWPOSCHANGING, then finally WM_WINDOWPOSCHANGED.

For showing the window, the target did not receive WM_SHOWWINDOW, but still got WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED.

You could handle WM_WINDOWPOSCHANGED and check the flags in WINDOWPOS for SWP_HIDEWINDOW/SWP_SHOWWINDOW.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文