请教在delphi中,如何让form最小化时,缩成一个图标在屏幕右下角的状态栏上。(实现c++builder中TrayIcon1的功能)

chime 2001-05-22 02:17:00
...全文
461 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
chime 2001-05-22
  • 打赏
  • 举报
回复
要给各位加分,从管理进去了,怎么没有加分的选项。
shuyi 2001-05-22
  • 打赏
  • 举报
回复
to chime:
跟你说了去看看ShellAPI你要的效果都可以实现。
xiaogq 2001-05-22
  • 打赏
  • 举报
回复
仔细研究API函数Shell_NotifyIcon的功能,你自然明白
chime 2001-05-22
  • 打赏
  • 举报
回复
在缩小后的右下角图标点击右键,弹出一个菜单,怎么处理?
chime 2001-05-22
  • 打赏
  • 举报
回复
谢谢各位,我试了ameng007(阿门)程序和comsun(comsun)控件,是会在右下角状态栏出现图标,但还是达不到c++builder 的TrayIcon1的功能。因为最小化时状态栏会同时出现两个图标,我是要达到最小化时,只有右下角的图标,请各位指教!!!
whatname 2001-05-22
  • 打赏
  • 举报
回复
我恰好 前几天也做了这样的尝试 可以和你分享一下
和shuyi说的一样

...

uses

ShellAPI

const WM_TRAYNOTIFY=WM_USER+1;

...

public
{ Public declarations }
procedure WndProc(var Msg: TMessage); override;

var

...

nd0:NotifyIconData;
hs:LongWord;

implementation

....

procedure Tform1.FormCreate(Sender: TObject);
begin
hs:=Application.icon.Handle;

//填充NotifyIconData记录型变量nd0
nd0.cbSize := sizeof(NotifyIconData);
nd0.Wnd := handle;
nd0.uID := 0;
nd0.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
nd0.uCallbackMessage := WM_TRAYNOTIFY;
nd0.hIcon := hs;
StrPLCopy(nd0.szTip, '名字', 63);

// 在任务栏状态区添加图标
Shell_NotifyIcon(NIM_ADD, @nd0);
end;

procedure Tform1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE, @nd0);
end;


procedure Tform1.WndProc(var Msg: TMessage);
var
IconID:integer;
pt:TPOINT;
begin
if msg.Msg = WM_SIZE then
begin
if msg.wParam=SIZE_MINIMIZED then visible:=false
end
else
begin

if msg.Msg = WM_TRAYNOTIFY then
begin
{
在通知消息中,wParam参数为图标的uID,
lParam参数为鼠标事件的类型。
}
iconID := msg.WParam;
//获取鼠标的在屏幕上的位置
GetCursorPos(pt);

//通知消息的处理的基本框架结构如下:
case msg.lParam of
WM_LBUTTONDOWN:
begin
//鼠标右键被按下
end;
WM_RBUTTONDOWN:
begin
//鼠标左键被按下
end;
WM_LBUTTONUP:
begin
//释放鼠标左键
end;
WM_RBUTTONUP:
begin
//释放鼠标右键
end;
WM_MOUSEMOVE:
begin
//鼠标在图标上移动
end;
WM_LBUTTONDBLCLK:;//鼠标左键双击
begin
if visible then visible:=false
else visible:=true;
end;
WM_RBUTTONDBLCLK:
begin
//鼠标右键双击
end;
end; //end case
end
else//调用父类的WndProc方法处理其它消息
inherited;
end;
end;



summer1978 2001-05-22
  • 打赏
  • 举报
回复
下一个RX控件不就行了。
ameng007 2001-05-22
  • 打赏
  • 举报
回复
使用托盘区的关键是shellapi中的TNotifyIconData和Shell_NotifyIcon涵数。
为实现动态图标,你可以在一个ImageList中准备几幅图片,在Timer事件中用ImageList
中的图片修改托盘中的图标。以下是程序示例:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,ShellAPI,
ImgList, ExtCtrls;

const
WM_MYTRAYICONCALLBACK = WM_USER + 1000;

type

TForm1 = class(TForm)
Timer1: TTimer;
ImageList1: TImageList;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
MyTrayIcon : TNotifyIconDataA;
IconIndex : integer;
CurrentIcon : TIcon;
procedure WMMyTrayIconCallBack(var Msg : TMessage);message WM_MYTRAYICONCALLBACK;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

{ TForm1 }

procedure TForm1.WMMyTrayIconCallBack(var Msg: TMessage);
begin
case Msg.LParam of
WM_LBUTTONDBLCLK :
begin
visible := not visible;
Application.ShowMainForm := visible;
SetForegroundWindow(Application.Handle);
end;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
IconIndex := 0;
CurrentIcon := TIcon.Create;
ImageList1.GetIcon(IconIndex,CurrentIcon);
MyTrayIcon.cbSize := Sizeof(TNotifyIconDataA);
MyTrayIcon.Wnd := handle;
MyTrayIcon.uId := 1;
MyTrayIcon.uFlags := NIF_ICON OR NIF_TIP OR NIF_MESSAGE;
//MyTrayIcon.uCallbackMessage := WM_MYTRAYICONCALLBACK;
//MyTrayIcon.hIcon := Application.Icon.Handle;
MyTrayIcon.hIcon := CurrentIcon.Handle;
MyTrayIcon.szTip := '托盘示例程序';
if not Shell_NotifyIcon(NIM_ADD,@MyTrayIcon) then
ShowMessage('创建托盘图标失败!');

end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE,@MyTrayIcon);
CurrentIcon.Free;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
ImageList1.GetIcon(IconIndex,CurrentIcon);
Application.Icon := CurrentIcon;
if IconIndex < 9 then
Inc(IconIndex)
else
IconIndex := 0;

MyTrayIcon.hIcon := CurrentIcon.Handle;
if not Shell_NotifyIcon(NIM_MODIFY,@MyTrayIcon) then
ShowMessage('修改托盘图标失败!');
end;
comsun 2001-05-22
  • 打赏
  • 举报
回复
这里就有的。
http://www.csdn.net/Dev/Delphi/
系统->trayicon 控件。非常好的。
BigBen 2001-05-22
  • 打赏
  • 举报
回复
one api:shell_traynotify。
froglove 2001-05-22
  • 打赏
  • 举报
回复
可以到DELPHI深度32历险下一个构件
http://vcl.vclxx.org
chonglei 2001-05-22
  • 打赏
  • 举报
回复
我写了一个TrayIcon的构件,装一下就行了
shuyi 2001-05-22
  • 打赏
  • 举报
回复
使用use shellApI然后看帮助吧,很简单的。
bailee 2001-05-22
  • 打赏
  • 举报
回复
一言难尽

5,939

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧