学习Delphi时,使用了第3方控件CoolTrayIcon。CoolTrayIcon的功能很强大,能够将程序添加进托盘,省去了我们再编写代码来实现托盘。但是在看搜CoolTrayIcon的时候,发现好多朋友在求如何让程序在启动就最小化多托盘的方法。但是貌似都不曾成功过。笔者摸索了一下,成功实现了。
找原因
首先我们来看一下CoolTrayIcon的功能函数:根据CoolTrayIcon的使用实例来看,CoolTrayIcon提供了函数HideMainForm()。好吧我们如果在FromCreat里面如果调用该函数会发现没有任何反应。为什么呢?我们接着跟踪这个函数看一下它的声明:
procedure TCoolTrayIcon.HideMainForm;
begin
if Owner is TWinControl then // Owner might be of type TService
if Application.MainForm <> nil then
begin
// Hide the form itself (and thus any child windows)
Application.MainForm.Visible := False;
{ Hide application's TASKBAR icon (not the tray icon). Do this AFTER
the main form is hidden, or any child windows will redisplay the
taskbar icon if they are visible. }
HideTaskbarIcon;
end;
end;
好吧,我们看到这里应该知道了吧。如果你还不知道,