Delphi7使用控件CoolTrayIcon时如何做到程序启动就最小化到托盘

本文介绍了在Delphi7中使用第三方控件CoolTrayIcon,让程序在启动时自动最小化到托盘的方法。通过分析CoolTrayIcon的函数和代码调试,找到了在窗体创建后调用HideMainForm()无效的原因,并提供了解决方案,包括在工程文件中添加特定代码以实现所需功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

学习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;

好吧,我们看到这里应该知道了吧。如果你还不知道,可以对它设置断点调试,你就会发现函数声明的语句根本就没有进去。也就是说Application.MainForm根本没有创建。这就意味着你要在创建了窗体的情况下才能调用该函

DELPHI7下好用的托盘控件,安装简单,版本进度如下:TCoolTrayIcon, ver. 2.3.0 - ver. 2.3.0: Various minor bugs fixed: 1) Calling the ShowMainForm and HideMainForm methods before the main form was created would crash the app. Fixed thanks to James Legg. 2) The tooltip would give trouble if it was 64 chars. Thanks to Toms Baugis and Teus de Jong. 3) The popup menu would not close itself auto- matically if the StartMinimized property was true. Thanks to Ingo Krueger, Chris Witt, and Reister HansJoerg. - ver. 2.2.2: When there was more than one form visible the taskbar icon would not hide when the main form was minimized. Fixed. - ver. 2.2.1: Fixed a popup menu bug. Also fixed a bug which meant D2 and D3 users could not compile the component. Added more icon animations in the demo. Thanks to Daniele Gervasoni for the "tray graph". - ver. 2.2.0: IconIndex is now a property, allowing you to specify an icon at run-time. The OnCycle event is changed so it returns the index to the next icon that will display when cycling. Finally, I fixed a bug that caused the taskbar icon not to display itself when MinimizeToTray was true. Thanks to Lorenz Graf for pointing it out to me. - ver. 2.1.4: The main form will no longer show itself untimely after the form's BorderStyle property is changed. Thanks to Thomas Reimann. - ver. 2.1.3: Fixed a bug that caused the main form not to display itself (how embarassing). - ver. 2.1.2: I *finally* found the bug that would cause some compound controls (like controls on notebook pages or tab sheets) not to display properly when StartMinimized was true. Incidently, this also means that TForm.Position now works. Also fixed a minor bug that caused modal forms owned by the main form to appear behind the main form when the popup menu appeared (thanks to Arash Ramin). - ver. 2.1.1: Added notification method to properly detect whether the associated popup menu and imagelist are deleted. Thanks to
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值