简体   繁体   English

Window第一次忽略ShowWindow最小化,然后在每次之后服从

[英]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 类型:int

Controls 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 a STARTUPINFO structure . 如果启动应用程序的程序提供了STARTUPINFO结构,则在应用程序首次调用ShowWindow时将忽略此参数 Otherwise, the first time ShowWindow is called, the value should be the value obtained by the WinMain function in its nCmdShow parameter. 否则,第一次调用ShowWindow ,该值应为WinMain函数在其nCmdShow参数中获得的值。

... ...

The first time an application calls ShowWindow , it should use the WinMain function's nCmdShow parameter as its nCmdShow parameter. 应用程序第一次调用ShowWindow ,应使用WinMain函数的nCmdShow参数作为其nCmdShow参数。 Subsequent calls to ShowWindow must use one of the values in the given list, instead of the one specified by the WinMain function's nCmdShow parameter. ShowWindow后续调用必须使用给定列表中的值之一,而不是WinMain函数的nCmdShow参数指定的值。 As noted in the discussion of the nCmdShow parameter, the nCmdShow value is ignored in the first call to ShowWindow 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 the STARTUPINFO structure to show the window. 在这种情况下, ShowWindow使用STARTUPINFO结构中指定的信息来显示窗口。 On subsequent calls, the application must call ShowWindow with nCmdShow set to SW_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 the WS_VISIBLE flag set. 应用程序通过设置WS_VISIBLE标志的CreateWindow创建其主窗口。

  • Applications create their main window by calling CreateWindow with the WS_VISIBLE flag cleared, and later call ShowWindow with the SW_SHOW flag set to make it visible. 应用程序通过清除WS_VISIBLE标志的调用CreateWindow创建其主窗口,然后SW_SHOW标志设置为可见的情况下调用ShowWindow

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 窗口最小化后不恢复 - Window is not restored after minimized 在最小化时检查当前最小化的窗口是处于最大化状态还是正常状态 - Check if currently minimized window was in maximized or normal state at the time of minimization 实体框架在每次编译后第一次加载非常慢 - Entity framework very slow to load for first time after every compilation MVC 4:首次登录时,每个F5始终不起作用,只有在首次登录后才起作用 - MVC 4: Every F5 on First Time Login Always Won't Work, it will Only Work After the First Time ShowWindow(browserPtr,3)之后,窗口不接受按键 - Window do not accept key press after ShowWindow(browserPtr, 3) SetWindowPos每次将窗口移到不同位置 - SetWindowPos moves window to different position every time 那时,重定向第二种形式在C#桌面应用程序中最小化了第一种形式 - Redirect second form at that time first form is minimized in C# desktop application 重建后,C#控制台应用程序每次都无法连接SQL Server - C# Console application fail to connect SQL Server every first time after rebuild 安装后如何检查我的C#窗口应用程序是否首次运行 - how to check whether my c# window app is running first time after installation JqG​​rid第一次不显示数据,但此后可以工作 - JqGrid not displaying the data first time but works after that
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM