在 C++ 中最大化窗口时出现问题
我的程序需要任意最大化当前桌面上的任何窗口。我通过调用 ShowWindow(hWnd, SW_MAXIMIZE) 来实现此目的,其中 hWnd 是我想要最大化的窗口的 HWND。当该行代码执行时,相关窗口(此处为记事本)如下所示:
一切看起来都很好,除了窗口没有正确定位这一事实之外,即窗口似乎低了几个像素,并且标题栏看起来不像应有的那样“被压扁”。与单击最大化按钮时的外观相比,问题显而易见:
有谁知道为什么会这样行为发生了,我能做些什么来解决它?
My program needs to arbitrarily maximize any window on the current desktop. I achieve this by calling ShowWindow(hWnd, SW_MAXIMIZE)
, where hWnd is the HWND
of the window I want to maximize. When that line of code executes, the window in question (here, Notepad) looks like this:
Everything seems fine, except for the fact that the window has not been positioned correctly, i.e. the window seems to be a few pixels to low, and the title bar does not look "squashed" like it should. Compared to how it should look when the maximize button is clicked, the problem is clearly visible:
Does anyone know why this behaviour occurs, and what I can do to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
告诉窗口最大化自身可能会绕过程序在通过系统菜单命令最大化时所做的一些内部调整。要模拟单击最大化按钮,请向其发送
SC_MAXIMIZE
命令:Telling the window to maximize itself might bypass some internal adjustments that the program makes when it maximizes via a system menu command. To emulate clicking on the maximize button, send it a
SC_MAXIMIZE
command:使用 SetWindowPos() 的另一种方法;例如你得到了 HWND handleWnd;
所以你得到了之前的位置,将窗口放在 Z 之上并显示
Antoher way to use SetWindowPos(); For example you got HWND handleWnd;
So you got your previous position, place window on top of Z and show