WINDOWPLACEMENT 的 showCmd... 总是 1?

编程入门 行业动态 更新时间:2024-10-26 02:28:34
本文介绍了WINDOWPLACEMENT 的 showCmd... 总是 1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-26 00:12:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1126821.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:WINDOWPLACEMENT   showCmd

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!