怎么将程序编写成最小化时到任务栏的右下角(显示时间的地方)(20分)

  • 主题发起人 主题发起人 shine_yzl
  • 开始时间 开始时间
S

shine_yzl

Unregistered / Unconfirmed
GUEST, unregistred user!
[?]各位高人,我想编写一个TIMER控件但是没办法做到最小化时到任务栏的右下角,请帮忙!
 
Google上搜索以下关于“托盘”的程序,你这个问题的解决例程一大堆。
 
CoolTrayIcon
http://www.delphibyte.com/download/softdown.php?softid=454&url=http://61.132.118.165/soft/delphi/Delphi3/trayicon311.zip
 
c++Builder中有个控件能实现这个功能:
Samples板中的TrayIcon。
在C++Builder目录下还有这个控件的原代码。
如果要目录可以问我要。
 
uses ShellApi;
原函数声明如下:
function Shell_NotifyIcon(dwMessage:DWORD;lpData:PNotifyIconData);Bool:stdCall
下面是我写的相关的代码,可以实现托盘,仅供参考:
注意:图标是在当前工程目录下。
program MainproTray;

uses
Windows,
Forms,
TrayU in 'TrayU.pas' {MainFrm};

{$R *.RES}

begin
Application.Initialize;

Application.CreateForm(TMainFrm, MainFrm);
Application.ShowMainForm:=false;
//if false,MainFrm not visible 在任务栏中不出现
Application.Run;
end.
//////////////////////
unit TrayU;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,ShellApi,
Menus, jpeg, ExtCtrls;
const
WM_SHOWINFO=WM_USER+1;
ICON_ID=1;
type
TMainFrm = class(TForm)
PopupMenu1: TPopupMenu;
Open1: TMenuItem;
Exit1: TMenuItem;
Image1: TImage;
procedure Open1Click(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure InstallIcon;
procedure ShowInfoClick(var Msg:TMessage);message WM_SHOWINFO;
private
{ Private declarations }
myIcon:TIcon;
protected

public
{ Public declarations }


end;

var
MainFrm: TMainFrm;
//IconData:TNotifyIconData;
implementation



{$R *.DFM}

procedure TMainFrm.Open1Click(Sender: TObject);
begin
MainFrm.Show;
//在任务栏隐藏
ShowWindow(Application.Handle,SW_HIDE);
end;

procedure TMainFrm.Exit1Click(Sender: TObject);
begin
//Shell_NotifyIcon(NIM_DELETE,@IconData);
Application.ProcessMessages;
Application.Terminate;
end;

procedure TMainFrm.FormCreate(Sender: TObject);

begin
//BorderIcons:=[biSystemMenu];

InstallIcon;
ShowWindow(MainFrm.Handle,SW_HIDE);
end;

procedure TMainFrm.FormClose(Sender: TObject; var Action: TCloseAction);
var
IconData:TNotifyIconData;
begin
IconData.cbSize:=sizeof(IconData);
IconData.Wnd:=Handle;
IconData.uID:=ICON_ID;
Shell_NotifyIcon(NIM_DELETE,@IconData);
myIcon.Free;
//Action:=caNone;
//MainFrm.Hide;
end;


procedure TMainFrm.ShowInfoClick(var Msg: TMessage);
var
p:TPoint;
begin
if Msg.LParam=WM_LBUTTONDOWN then
begin
MainFrm.Show;
//ShowWindow(Application.Handle,SW_HIDE);
end;
if Msg.LParam=WM_RBUTTONDOWN then
begin
GetCursorPos(p);
PopupMenu1.Popup(p.x,p.y);
end;
end;

procedure TMainFrm.InstallIcon;
var
IconData:TNotifyIconData;

begin
myIcon:=TIcon.Create;
myIcon.LoadFromFile('NormalIcon.ico'); //使用自己定义的图标

with IconData do
begin

cbSize:=sizeof(IconData);
//Wnd:=Handle;ok
Wnd:=MainFrm.Handle;
//Wnd:=Application.Handle; //Application.Handle why not?
uID:=ICON_ID;
uFlags:=NIF_MESSAGE+NIF_ICON+NIF_TIP;
uCallBackMessage:=WM_SHOWINFO;
//hIcon:=LoadIcon(hInstance,'NormalIcon');
//hIcon:=Application.Icon.Handle;
hIcon:=myIcon.Handle;
StrPCopy(szTip,'myTrayIcon');
end;
Shell_NotifyIcon(NIM_ADD,@IconData);
end;

end.
 
1.用楼上的方法
2.rxlib里的控件RxTrayIcon
 
多人接受答案了。
 
后退
顶部