windows 如何最小化任务栏的窗口?(即不是图标化)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6228966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:59:13  来源:igfitidea点击:

How to minimize a window to the taskbar? (i.e. not iconify)

windowsdelphiwindows-7delphi-5windows-95

提问by Ian Boyd

i have a window that i want to minimize (to the taskbar), so i call ShowWindow:

我有一个我想最小化(到任务栏)的窗口,所以我调用ShowWindow

ShowWindow(Handle, SW_MINIMIZE);

Except that rather than minimizing itself (to the taskbar), the window is iconified:

除了将自身最小化(到任务栏)之外,窗口被图标化

enter image description here

在此处输入图片说明

The window is unparented:

该窗口是无父级的:

enter image description here

在此处输入图片说明

How do i minimize a window to the taskbar?

如何最小化任务栏的窗口?



Update:

更新:

Following some advice from 2002, i try setting the WS_EX_APPWINDOWwindow style and/or ensuring the window has no owner:

遵循 2002 年的一些建议,我尝试设置WS_EX_APPWINDOW窗口样式和/或确保窗口没有所有者:

enter image description here

在此处输入图片说明

Unfortunately, that changes the behavior of my (Delphi) application because there is now twotaskbar icons for my application, rather than one:

不幸的是,这改变了我的(Delphi)应用程序的行为,因为我的应用程序现在有两个任务栏图标,而不是一个:

enter image description here

在此处输入图片说明

This, of course, is an artifact of Delphi (5); and because i was trying to solve another issue.

这当然是德尔福的神器(5);因为我试图解决另一个问题

But that shouldn't affect this question. i'm calling the ShowWindow(..., SW_MINIMIZE)API, and rather than minimize the window Windows is iconifyingthe application.

但这不应该影响这个问题。我正在调用ShowWindow(..., SW_MINIMIZE)API,而不是最小化窗口,Windows 正在图标化应用程序。

How do i minimize a window to the taskbar?

如何最小化任务栏的窗口?

回答by NGLN

That icon on the taskbar is the icon of the Application (Handle) rather than that of the MainForm.

任务栏上的那个图标是应用程序(句柄)的图标,而不是主窗体的图标。

Use:

用:

Application.Minimize;

Edit:But out of both your links, I understand you knew that already...duh ;)

编辑:但是从你的两个链接中,我知道你已经知道了......呃;)

This works for the MainForm:

这适用于 MainForm:

TForm1 = class(TForm)
private
  procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
protected
  procedure CreateParams(var Params: TCreateParams); override;

...

procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  with Params do
  begin
    ExStyle := ExStyle or WS_EX_APPWINDOW;
    WndParent := GetDesktopWindow;
  end;
end;

procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
begin
  if Msg.CmdType = SC_MINIMIZE then
    ShowWindow(Handle, SW_MINIMIZE)
  else
    inherited;
end;

And to hide Application.Handle from the taskbar (to only have a taskbar icon for the MainForm): set the Visibleproperty of this Form to Trueand hide the Application in the project file:

并从任务栏隐藏 Application.Handle(只有 MainForm 的任务栏图标):Visible将此表单的属性设置为True并隐藏项目文件中的应用程序:

Application.Initialize;
Application.CreateForm(TForm1, Form1);
ShowWindow(Application.Handle, SW_HIDE);
Application.Run;

For this form, ShowWindow(Handle, SW_MINIMIZE);shóuld work. It also provides for the default zooming-feature of Windows when minimizing or restoring.

对于这种形式,ShowWindow(Handle, SW_MINIMIZE);应该有效。它还在最小化或恢复时提供 Windows 的默认缩放功能。

(Tested with D5 & D7 on XP and W7)

(在 XP 和 W7 上用 D5 和 D7 测试)

回答by Erez Amir

A super simple solution is to disable the minimize icon on the FORM
[Object inspector]-[Form properties]-[Border icons]-[biMinimize]
The application can still be minimized and restore by clicking on the APPLICATION icon at the taskbar

一个超级简单的解决方法是禁用FORM上的最小化图标
【对象检查器】-【窗体属性】-【边框图标】-【biMinimize】
点击任务栏上的APPLICATION图标仍然可以最小化和恢复应用程序

enter image description here

在此处输入图片说明