UpdateLayeredWindow、SIZE_RESTORED 和 GetClientRect 问题
我在 MFC 应用程序中设置了分层窗口。我已经设置了自己的 CDialog 派生,以允许我自定义窗口呈现方式的各个部分。一切都工作正常,直到我开始担心最小化和最大化。
如果您单击最小化或最大化,则窗口的反应与您期望的完全一样(即与不使用分层窗口时的反应完全一样)。然而,当我恢复窗口时,发生了一些非常奇怪的事情。
我的测试窗口的默认客户端矩形是 324x102。例如,当我从最小化状态恢复时,传递给 OnSize 的 cx 和 cy 是 994、550。如果我随后执行 GetClientRect(在 OnSize 内),这就是为窗口报告的大小。奇怪的是,如果我执行 GetWindowRect,我会得到正确的大小(尽管显然包括我所有的非客户区域)。
有谁知道这里发生了什么,更重要的是,我如何修复它,以便 GetClientRect 报告正确的信息?
提前致谢!
I have a layered window set up in my MFC application. I have set up my own derivation of CDialog to allow me to customise various parts of how the window is rendered. Everything works fine right up until I start worrying about minimise and maximise.
If you click minimise or maximise then the window reacts exactly as you'd expect (ie exactly as it does when NOT using a layered window). However, when I restore the window something very odd happens.
The default client rectangle for my test window is 324x102. When I restore from the minimised state, for example, the cx and cy passed to OnSize is 994, 550. If I then do a GetClientRect (within OnSize) this is the size reported for the window. Weirdly, though if i do GetWindowRect I get the correct size back (though obviously including all my non-client areas).
Does anybody have any idea what is going on here and, more importantly, how I can fix it such that GetClientRect reports the CORRECT information?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想出了一种解决这个问题的技巧。在 OnSize 和 OnMove 中,我忽略收到的 (c)x 和 (c)y,并通过 GetWindowRect 计算出所有内容。应用程序现在按预期做出反应。我已经用 [HACK] 注释标记了代码。虽然这看起来确实很奇怪,但我很想听听为什么会发生这种情况。
I have come up with a sort of hack to solve this problem. In OnSize and OnMove I ignore the (c)x and (c)y that I receive and work everything out from a GetWindowRect. The application now reacts as expected. I have marked the code with a [HACK] comment. This does seem very odd though, I'd love to hear WHY this is happening.