问题描述
限时送ChatGPT账号..当我执行 get GetWindowPlacement
时,WINDOWPLACEMENT::showCmd
似乎总是 1,即 SW_SHOWNORMAL
.
When I do a get GetWindowPlacement
, the WINDOWPLACEMENT::showCmd
seems to be always 1, which is SW_SHOWNORMAL
.
有谁知道为什么会这样,是否更新?有谁知道这个变量是由应用程序本身维护的还是由操作系统维护的?
Does anyone know why is this so and if it is updated? Does anyone know if this variable is maintained by the application itself or by the operating system?
我在 Windows 7 上运行这个.
I am running this on Windows 7.
我使用它来实现与 此线程:我正在尝试撤消先前显示的隐藏窗口,而不将隐藏窗口存储在内存中(隐藏/显示将在不同的运行会话中调用)或磁盘上.
I am using this to achieve the same purpose as mentioned in this thread: I am trying to undo hidden windows that were previously shown without storing the hidden windows in memory (hide/show will be called in different run sessions) or on disk.
void hide(const unsigned int pid){
std::list<HWND> windowList = getWindowbyPID(pid);
for(std::list<HWND>::iterator it = windowList.begin(); it != windowList.end(); it++){
if(IsWindowVisible(*it)){ std::cout << "Hid WIN#" << *it << std::endl; ShowWindow(*it,SW_HIDE); }
}
}
void show(const unsigned int pid){
std::list<HWND> windowList = getWindowbyPID(pid);
for(std::list<HWND>::iterator it = windowList.begin(); it != windowList.end(); it++){
//if(IsWindowVisible(*it)){ ShowWindow(*it,SW_SHOW); }
WINDOWPLACEMENT wp;
wp.length = sizeof(wp);
wp.showCmd = 0; // Just to clear showCmd before reading.
std::cout << *it << std::endl;
std::cout << "BEFORE: " << wp.showCmd << std::endl;
GetWindowPlacement(*it,&wp);
std::cout << "AFTER: " << wp.showCmd << std::endl;
}
}
隐藏hwnd#00060CD0
后我做的一个例子的输出(notepad.exe的pid):
Output of one example that I did (pid of notepad.exe) after hiding hwnd#00060CD0
:
003D0642
BEFORE: 0
AFTER: 1
000B0682
BEFORE: 0
AFTER: 1
00060CD0
BEFORE: 0
AFTER: 1
我正在尝试使用 GetWindowPlacement
来区分始终隐藏的窗口和之前显示的窗口.即使对于始终隐藏的窗口,它似乎也永远不会为 0.
I am trying to use GetWindowPlacement
to differentiate the windows that were always hidden and the windows that were previously shown. It never seems to be 0 even for windows that were always hidden.
推荐答案
调用 GetWindowPlacement
后,showCmd
只有三个可能的值.
There are only three possible values of the showCmd
after calling GetWindowPlacement
.
来自关于 GetWindowPlacement
(强调我的):
此函数检索到的 WINDOWPLACEMENT 的标志成员始终为零.如果hWnd参数标识的窗口最大化,则showCmd成员为SW_SHOWMAXIMIZED.如果窗口最小化,showCmd 是 SW_SHOWMINIMIZED.否则,它是 SW_SHOWNORMAL.
The flags member of WINDOWPLACEMENT retrieved by this function is always zero. If the window identified by the hWnd parameter is maximized, the showCmd member is SW_SHOWMAXIMIZED. If the window is minimized, showCmd is SW_SHOWMINIMIZED. Otherwise, it is SW_SHOWNORMAL.
因此,当您调用 GetWindowPlacement
时,您请求放置信息的窗口似乎处于非最大化或最小化状态.
Therefore, it appears that the window you're asking for placement info on is in a state other than maximized or minimized when you're calling GetWindowPlacement
.
我怀疑您实际上在寻找的是IsWindowVisible
.
I'd suspect what you're actually looking for is IsWindowVisible
.
这篇关于WINDOWPLACEMENT 的 showCmd... 总是 1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论