如何最小化任务栏的窗口?(即不图标化) [英] How to minimize a window to the taskbar? (i.e. not iconify)

查看:30
本文介绍了如何最小化任务栏的窗口?(即不图标化)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

ShowWindow(Handle, SW_MINIMIZE);

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

窗口没有父级:

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

<小时>

更新:

.>

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

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

解决方案

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

使用:

Application.Minimize;

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

这适用于 MainForm:

TForm1 = class(TForm)私人的程序 WMSysCommand(var Msg: TWMSysCommand);消息 WM_SYSCOMMAND;受保护过程 CreateParams(var Params: TCreateParams);覆盖;...过程 TForm1.CreateParams(var Params: TCreateParams);开始继承 CreateParams(Params);与参数做开始ExStyle := ExStyle 或 WS_EX_APPWINDOW;WndParent := GetDesktopWindow;结尾;结尾;过程 TForm1.WMSysCommand(var Msg: TWMSysCommand);开始如果 Msg.CmdType = SC_MINIMIZE 那么ShowWindow(句柄,SW_MINIMIZE)别的遗传;结尾;

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

Application.Initialize;Application.CreateForm(TForm1, Form1);ShowWindow(Application.Handle, SW_HIDE);应用程序运行;

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

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

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:

The window is unparented:

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:

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

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?

解决方案

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)

这篇关于如何最小化任务栏的窗口?(即不图标化)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆