如何最小化一个窗口到任务栏?(即不图标化) [英] How to minimize a window to the taskbar? (i.e. not iconify)
问题描述
我有一个要最小化的窗口(到任务栏),所以我调用 ShowWindow
:
ShowWindow(Handle, SW_MINIMIZE);
除了不是最小化自身(到任务栏),窗口是图标化:
窗口没有父级:
如何将窗口最小化到任务栏?
<小时>更新:
.p>
但这不应该影响这个问题.我正在调用 ShowWindow(..., SW_MINIMIZE)
API,而不是最小化窗口 Windows 是 iconifying 应用程序.
如何将窗口最小化到任务栏?
任务栏上的那个图标是Application(Handle)的图标,而不是MainForm的图标.
用途:
Application.Minimize;
但是从你的两个链接中,我知道你已经知道了……duh ;)
这适用于 MainForm:
TForm1 = 类(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 那么显示窗口(句柄,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屋!