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

发布于 2024-11-13 21:27:37 字数 1008 浏览 4 评论 0原文

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

ShowWindow(Handle, SW_MINIMIZE);

除了窗口不是最小化自身(到任务栏),而是图标化 :

在此处输入图像描述

窗口没有父子关系:

在此处输入图像描述

如何最小化任务栏窗口?


更新:

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

在此处输入图像描述

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

在此处输入图像描述

这当然是 Delphi 的产物 (5);因为我试图解决另一个问题

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

如何最小化任务栏窗口?

i have a window that i want to minimize (to the taskbar), so i call 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_APPWINDOW window style and/or ensuring the window has no owner:

enter image description here

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

enter image description here

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

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

How do i minimize a window to the taskbar?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱花落人离去 2024-11-20 21:27:37

任务栏上的图标是应用程序(句柄)的图标,而不是 MainForm 的图标。

使用:

Application.Minimize;

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

这适用于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;

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

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

对于此表单,ShowWindow(Handle, SW_MINIMIZE); 应该可以工作。它还在最小化或恢复时提供 Windows 的默认缩放功能。

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

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:

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 Visible property of this Form to True and hide the Application in the project file:

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.

(Tested with D5 & D7 on XP and W7)

放肆 2024-11-20 21:27:37

一个超级简单的解决方案是禁用 FORM 上的最小化图标
[对象检查器]-[表单属性]-[边框图标]-[biMinimize]
仍然可以通过单击任务栏上的应用程序图标来最小化和恢复应用程序

在此处输入图像描述

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

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文