Windows如何强制“最小化" Windows操作系统?桌面快捷方式打开状态? [英] How does Windows force "minimized" state from a desktop shortcut?
问题描述
我有一个旨在最小化系统托盘的应用程序.那里没有问题.
I have an application that is designed to minimize to the system tray. No issues there.
我遇到的问题是,当我设置可执行文件的桌面快捷方式并启动它时,我无法确定Windows正在做什么以强制最小化状态,例如:
The problem I am having is that I cannot determine what Windows is doing to force the minimized state when I set up a desktop shortcut to that executable and launch it, such as:
我将一些调试输出放入窗体的构造函数中,并通过快捷方式启动.我没有命令行参数,而WindowState
的检查结果为Normal
.然而,该应用程序开始最小化到任务栏.
I put some debug outputs in the form's constructor and launched via the shortcut. I get no command line arguments and a check of WindowState
yields Normal
. Yet the app starts minimized to the taskbar.
但是,这很麻烦:我希望它开始最小化到系统托盘,就像在屏幕上显示表单并且用户将其最小化一样.当然,并非总是如此,只是在使用最小化"快捷方式时,或者在用户单击表单上的最小化"时.
However, that's the rub: I want it to start minimized to the system tray, just as it would if the form were on-screen and the user minimized it. Not all the time, just when a "minimize" shortcut is used, or when the user clicks Minimize on the form, of course.
出于好奇...我的初始测试存在缺陷,因为我签入了构造函数.将测试放在Load
方法中会产生一个Minimized
状态,然后我可以对此状态做出反应并调用我的代码以执行最小化托盘"操作.
for the curious...my initial testing was flawed because I checked in the constructor. Placing the test in the Load
method produced a Minimized
state, to which I could then react and call my code to perform the "minimize-to-tray".
推荐答案
Windows正在使用最小化主窗口的参数启动该过程.
Windows is starting the process with parameters to minimize the main window.
In C#, you can do the same by setting WindowStyle (MSDN) at ProcessStartInfo
for use in Process.Start()
.
在原生世界中,您将使用 CreateProcess(MSDN) API并传递
In the native world, you would use the CreateProcess (MSDN) API and pass a STARTUPINFO, setting wShowWindow
to SW_MINIMIZE
.
要查询窗口状态,请使用 Form.WindowState .
To query the window state, use GetWindowInfo (MSDN), look at dwStyle
and check if WS_MINIMIZE
is set. In C#, this should be in Form.WindowState.
这篇关于Windows如何强制“最小化" Windows操作系统?桌面快捷方式打开状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!