显示窗口后执行代码
我正在开发一个Windows应用程序,我正在其中实现整个事件循环以及类似的一切(这是有原因的)。在一个地方,我需要在显示窗口后执行一些代码。通常,当创建窗口时,我会在收到 WM_CREATE 消息时进行一些初始化。 WM_SHOWWINDOW 在窗口显示之前发送。但是,我需要在第一次显示窗口后立即执行一些代码。我似乎找不到在显示窗口后发送的通知消息。难道没有吗?
当然,我可以保留一个布尔值 - FirstRun - 指示我是否执行了我的逻辑,然后在收到 WM_ACTIVATE 时执行代码,前提是布尔值是 TRUE,然后将 FirstRun 设置为 FALSE,以便代码不执行下次我收到 WM_ACTIVATE 时,但这对我来说似乎有点不自然。
我已经很久没有在这个级别上进行过 win32 编程了,所以记不太清了。这里最好的方法是什么?
I'm working on a windows application where I'm implementing the whole event loop and everything like that myself (there's a reason for that). In one place, I need to execute some code AFTER a window is shown. Normally, when the window is created, I do some initialisation when WM_CREATE message is received. WM_SHOWWINDOW is sent just BEFORE the window is displayed. However I need to get some code executed right AFTER the window is displayed for the first time. I can't seem to find a notification message sent AFTER the window is shown. Could it be that there isn't one?
Of course, I can keep a boolean - FirstRun - indicating whether or not I had performed my logic, and then execute the code when WM_ACTIVATE is received, provided the boolean is TRUE, then set FirstRun to FALSE so that the code is not execute the next time I am receive WM_ACTIVATE, but this seems somewhat unnatural to me.
It's been ages since I did win32 programming on this level, so can't remember much of it. What is the best approach here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有特别的通知,但在很多情况下你可以使用这个技巧:
There is no special notification, but in many cases you can use this trick:
没有一个,因为这就是 WM_SHOWWINDOW 的用途。一旦该消息被传递到默认消息处理过程,就会显示该窗口。您可以做的最好的事情是使用 IsWindowVisible 通过某种计时器。
尽管必须依赖这样的东西,但您的程序设计似乎有缺陷。你想做什么?
There isn't one because that's what WM_SHOWWINDOW is for. Once that mesage is passed to the default message handling procedure, the window will be shown. The best thing you could do is poll with IsWindowVisible via some sort of timer.
Your program design seems flawed though to have to rely on something like this. What are you trying to do?
只要您自己实现整个事件循环和类似的所有内容,您就可以直接在 WinMain() 中处理它,如下所示:
As long as you are implementing the whole event loop and everything like that yourself, you can handle this directly in WinMain() like this: