[英]Window ignores ShowWindow Minimized the first time, then obeys every time after
I have a C# application that I am kicking off a separate win32 window from. 我有一个C#应用程序,正在启动一个单独的Win32窗口。 I'm marshaling Win32 api calls into my C# application and trying to control the win32 from that. 我将Win32 api调用编组到我的C#应用程序中,并试图从中控制win32。 I'm toggling the window from a button press to be either maximized on top of all windows always or minimized. 我要从按钮按下切换窗口,使其始终在所有窗口之上最大化或最小化。
It will show maximized, then ignore the first button press to hide, it then stays showing when I press the button again, then finally hides once I press the button a 3rd time with the same code. 它将显示为最大化,然后忽略第一次按下按钮以隐藏,然后在再次按下按钮时保持显示,然后再次以相同的代码第三次按下按钮时最终隐藏。 It behaves as desired from here on out. 从现在开始,它的行为符合预期。 I'm sure it must be some Windows flags that aren't set properly until it goes through a maximize/minimize cycle first. 我确定必须先正确设置某些Windows标记,才能首先通过最大化/最小化周期。
Here is the life cycle of the window: 这是窗口的生命周期:
Create window maximized 最大化创建窗口
A: A:
Hide: 隐藏:
target_hwnd = FindWindowHandleByCaption()
ShowWindow(target_hwnd, SW_SHOWMINIMIZED);
Show: 节目:
target_hwnd = FindWindowHandleByCaption()
ShowWindow(target_hwnd, SW_SHOWMAXIMIZED);
Goto A: 转到A:
What am I doing wrong? 我究竟做错了什么? I've been at this for hours trying various code snippets to no avail. 我已经花了几个小时尝试各种代码片段,但无济于事。
Thanks in advance! 提前致谢!
EDIT: 编辑:
Solved my problem by just doing: 通过执行以下操作解决了我的问题:
SendMessage(target_hwnd.ToInt32(), WM_SYSCOMMAND, SC_MINIMIZE, 0);
SendMessage(target_hwnd.ToInt32(), WM_SYSCOMMAND, SC_MAXIMIZE, 0);
Instead of using ShowWindow. 而不是使用ShowWindow。
Per the ShowWindow()
documentation: 根据ShowWindow()
文档:
nCmdShow 的nCmdShow
Type: int 类型:intControls how the window is to be shown. 控制窗口的显示方式。 This parameter is ignored the first time an application calls
ShowWindow
, if the program that launched the application provides aSTARTUPINFO
structure . 如果启动应用程序的程序提供了STARTUPINFO
结构,则在应用程序首次调用ShowWindow
时将忽略此参数 。 Otherwise, the first timeShowWindow
is called, the value should be the value obtained by theWinMain
function in itsnCmdShow
parameter. 否则,第一次调用ShowWindow
,该值应为WinMain
函数在其nCmdShow
参数中获得的值。... ...
The first time an application calls
ShowWindow
, it should use theWinMain
function'snCmdShow
parameter as itsnCmdShow
parameter. 应用程序第一次调用ShowWindow
,应使用WinMain
函数的nCmdShow
参数作为其nCmdShow
参数。 Subsequent calls toShowWindow
must use one of the values in the given list, instead of the one specified by theWinMain
function'snCmdShow
parameter. 对ShowWindow
后续调用必须使用给定列表中的值之一,而不是WinMain
函数的nCmdShow
参数指定的值。 As noted in the discussion of thenCmdShow
parameter, thenCmdShow
value is ignored in the first call toShowWindow
if the program that launched the application specifies startup information in the structure . 如对nCmdShow
参数的讨论中所述,如果启动应用程序的程序在结构中指定了启动信息,则在第一次调用ShowWindow
时将忽略nCmdShow
值 。 In this case,ShowWindow
uses the information specified in theSTARTUPINFO
structure to show the window. 在这种情况下,ShowWindow
使用STARTUPINFO
结构中指定的信息来显示窗口。 On subsequent calls, the application must callShowWindow
withnCmdShow
set toSW_SHOWDEFAULT
to use the startup information provided by the program that launched the application. 在后续调用中,应用程序必须使用nCmdShow
设置为SW_SHOWDEFAULT
来调用ShowWindow
,以使用启动应用程序的程序提供的启动信息。 This behavior is designed for the following situations: 此行为是针对以下情况设计的:
Applications create their main window by calling
CreateWindow
with theWS_VISIBLE
flag set. 应用程序通过设置WS_VISIBLE
标志的CreateWindow
创建其主窗口。Applications create their main window by calling
CreateWindow
with theWS_VISIBLE
flag cleared, and later callShowWindow
with theSW_SHOW
flag set to make it visible. 应用程序通过清除WS_VISIBLE
标志的调用CreateWindow
创建其主窗口,然后SW_SHOW
标志设置为可见的情况下调用ShowWindow
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.