在 C++ 中最大化窗口时出现的问题 [英] Problem when maximizing window in C++

查看:35
本文介绍了在 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?

推荐答案

告诉窗口最大化自身可能会绕过程序通过系统菜单命令最大化时所做的一些内部调整.要模拟单击最大化按钮,请将其发送一个 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:

SendMessage(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);

这篇关于在 C++ 中最大化窗口时出现的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆