当我获取 GetWindowPlacement
时,WINDOWPLACEMENT::showCmd
似乎始终为 1,即 SW_SHOWNORMAL
。
有谁知道为什么会这样,是否更新了?有谁知道这个变量是由应用程序本身维护的还是由操作系统维护的?
我在 Windows 7 上运行它。
我用它来实现与 this thread 中提到的相同目的: 我正在尝试撤消以前显示的隐藏窗口,而不将隐藏窗口存储在内存中(隐藏/显示将在不同的运行 session 中调用)或磁盘上。
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)的输出:
003D0642
BEFORE: 0
AFTER: 1
000B0682
BEFORE: 0
AFTER: 1
00060CD0
BEFORE: 0
AFTER: 1
我正在尝试使用 GetWindowPlacement
来区分始终隐藏的窗口和之前显示的窗口。即使对于始终隐藏的窗口,它似乎也永远不会为 0。
最佳答案
调用 GetWindowPlacement
后,showCmd
只有三个可能的值。
来自 GetWindowPlacement
上的 MSDN 文档(强调我的):
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
时,您要求获取其位置信息的窗口似乎处于最大化或最小化之外的状态。
我怀疑你真正要找的是 IsWindowVisible
.
关于c++ - WINDOWPLACEMENT 的 showCmd...总是 1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16945930/