我能够出的最高分了,请教2个Delphi的小问题

dancebird 2000-09-04 10:02:00
1:如何让程序缩为一个图标显示在WINDOWS任务条的右下方?就像foxmail最小化后一样。
2:如何通过一个事件从WINDOWS任务条的右下方激活程序?
...全文
356 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
alin 2000-09-05
  • 打赏
  • 举报
回复
源代码送上,比用控件好多了
unit un_Notifyicon;

interface

uses shellapi, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;

const IDC_STATIC = -1;
IDC_LOAD =101;
IDC_UNLOAD =102;
IDC_DEMO =103;
IDC_NOTIFY =104;
IDC_TIP =201;
IDC_ICONFILENAME =202;
MYWM_NOTIFYICON =WM_APP +125;


procedure SetIconStatus(WinHandle,IcnoStatus:Integer;Const DispStr:String;ilStatus:TImageList);
procedure Icon_ADD (hdlg:integer;strin:String;iconname:Ticon);
procedure Icon_CHANGE (hdlg:integer;strin:String;iconname:TIcon);
procedure Icon_DELETE (hdlg:integer);


var
ptnd:pnotifyicondataa;
Isexisted :boolean;

implementation

procedure Icon_ADD (hdlg:integer;strin:String;iconname:TIcon);
begin
if not Isexisted then
try
new (ptnd);
ptnd.cbsize:=sizeof(TNOTIFYICONDATAA);
strPcopy(ptnd.szTip,strin);
ptnd.uCallbackMessage:=MYWM_NOTIFYICON;
ptnd.uFlags:=NIF_MESSAGE or NIF_ICON or NIF_TIP;
Ptnd.uID:=IDC_NOTIFY;
Ptnd.hIcon:=iconname.Handle;
Ptnd.Wnd:=hdlg;
Shell_notifyIcona(NIM_ADD,ptnd);
dispose(ptnd);
isexisted:=true;
finally
end;
end;

procedure Icon_CHANGE (hdlg:integer;strin:String;iconname:TIcon);
begin
if Isexisted then
try
new (ptnd);
ptnd.cbsize:=sizeof(TNOTIFYICONDATAA);
strPcopy(ptnd.szTip,strin);
ptnd.uCallbackMessage:=MYWM_NOTIFYICON;
ptnd.uFlags:=NIF_MESSAGE or NIF_ICON or NIF_TIP;
Ptnd.uID:=IDC_NOTIFY;
Ptnd.hIcon:=Iconname.Handle;
Ptnd.Wnd:=hdlg;
Shell_notifyIcona(NIM_MODIFY,ptnd);
dispose(ptnd);
isexisted:=true;
finally
end;
end;
procedure Icon_DELETE (hdlg:integer);
begin
if Isexisted then
try
new (ptnd);
ptnd.cbsize:=sizeof(TNOTIFYICONDATAA);
ptnd.uCallbackMessage:=MYWM_NOTIFYICON;
ptnd.uFlags:=NIF_MESSAGE or NIF_ICON or NIF_TIP;
Ptnd.uID:=IDC_NOTIFY;
Ptnd.Wnd:=hdlg;
Shell_notifyIcona(NIM_DELETE,ptnd);
dispose(ptnd);
isexisted:=false;
finally
end;
end;

procedure SetIconStatus(WinHandle,IcnoStatus:Integer;Const DispStr:String;ilStatus:TImageList);
Var
NewIcon:TIcon;
Begin
NewIcon:=TIcon.Create;
ilStatus.GetIcon(IcnoStatus,NewIcon);
Icon_Change (WinHandle,DispStr,NewIcon);
NewIcon.Free;
End;

调用方法:

uses un_Notifyicon;

type

TfrmMain = class(TForm)
ImageList1: TImageList;
PopupMenu1: TPopupMenu;
public
{ Public declarations }
Procedure On_My_Notifyicon(var mess:TMESSAGE);Message MYWM_NOTIFYICON;
end;

procedure TfrmMain.FormCreate(Sender: TObject);
Var
NewIcon:TIcon;
begin
NewIcon:=TIcon.Create;
ImageList1.GetIcon(0,NewIcon); //取第一个图标
Icon_Add (frmMain.WindowHandle,Self.caption,NewIcon); //在右下角加入图标
NewIcon.Free;
end;

procedure TfrmMain.FormDestroy(Sender: TObject); //释放
begin
Icon_DELETE(frmMain.WindowHandle);
end;

Procedure TfrmMain.On_My_Notifyicon(var mess:TMESSAGE);
Begin
inherited;
case Mess.lParam of
WM_LBUTTONDBLCLK,
WM_LBUTTONUP,
WM_RBUTTONUP:
Begin
PopupMenu1.Popup(screen.width-80,screen.height); //PopupMenu1是你加入的菜单,你自已自定内容吧
End;
end;
End;

bruce_zhao 2000-09-05
  • 打赏
  • 举报
回复
最简单的方法是用Rxlib控件包中的TrayIcon控件,只需两三句话就能搞定,Rxlib控件包的最新版本是2.75,可到我的主页:http://delphis.yeah.net 上去下载。
126分问这个问题确实太可惜了一点。
dragongong 2000-09-05
  • 打赏
  • 举报
回复
这问题不是很多人都问过了吗?白白化了126分,挺可惜的,啧啧!
gxlzx 2000-09-05
  • 打赏
  • 举报
回复
我给你发两个程序,自己慢慢看吧。
dancebird 2000-09-05
  • 打赏
  • 举报
回复
谢谢大家的热心,我把126分分别给了大家:)
Hibin 2000-09-05
  • 打赏
  • 举报
回复
请参考C:\Program Files\Borland\Delphi5\Source\Vcl\ScktSrvr例子
netsong 2000-09-05
  • 打赏
  • 举报
回复
在formcreat中:
nd: NotifyIconData;
//填充NotifyIconData记录型变量nd
hs:=loadicon(hInstance, 'MainIcon'); //关联你的icon:MainIcon
nd.cbSize := sizeof(NotifyIconData);
nd.Wnd := handle;
nd.uID := 0;
nd.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
nd.uCallbackMessage := WM_TRAYNOTIFY;
nd.hIcon := hs;
//在任务栏状态区添加图标
Shell_NotifyIcon(NIM_ADD, @nd);

动态改变图标:
hs:=loadicon(hInstance,'OtherIcon');//将图标换为OtherIcon;
nd.hIcon := hs;
Shell_NotifyIcon(NIM_MODIFY, @nd);

将图标从任务栏状态区删除
Shell_NotifyIcon(NIM_DELETE, @nd);


自定义响应图标的消息:
Const WM_TRAYNOTIFY=WM_USER+1;
加入响应该消息的函数:
procedure TFormfychatmain.WndProc(var Msg: TMessage);
var
pt:TPOINT;
iconID: integer;
begin
if msg.Msg = WM_TRAYNOTIFY then
begin
iconID := msg.WParam; // wParam参数为图标的uID,lParam参数为鼠标事件的类型
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 //修改提示信息
information:='Little Icon';
StrPLCopy(nd.szTip, information, 20);
Shell_NotifyIcon(NIM_MODIFY, @nd);
end;
WM_LBUTTONDBLCLK: //鼠标左键双击
begin
popupmenu1.Popup(pt.x,pt.y); //弹出一个popmenu
end;
WM_RBUTTONDBLCLK: //鼠标右键双击
begin
end;
end; //end case
end
else //调用父类的WndProc方法处理其它消息
inherited;
end;

PoolD 2000-09-04
  • 打赏
  • 举报
回复
通过WinAPI函数Shell_NotifyIcon可以在任务栏中加入图标。
0. 首先要自定义一个消息。
const
wm_IconMessage = wm_User + 1000; //用户自定义消息
1. 加入图标:
var
nid: TNotifyIconData;
begin
nid.cbSize := sizeof(nid);
nid.wnd := Form1.Handle;
nid.uID := 1000; //应该是可以随便设置的。
nid.uCallbackMessage := wm_IconMessage; //在鼠标对任务栏图标操作时返回的消息。
nid.hIcon := Application.Icon.Handle; //显示在任务栏上的图标句柄
nid.szTip := 'this is the SystemTray Icon'; //任务栏图标的提示信息。
nid.uFlags := nif_Message or nif_Icon or nif_tip;
Shell_NotifyIcon(NIM_ADD, @nid); //添加图标
end;
2. 修改图标的属性,只需要修改nid的值,然后Shell_NotifyIcon(NIM_MODIFY, @nid);
3. 去处图标,Shell_NotifyIcon(NIM_DELETE, @nid);
4. 响应事件,也就是响应wm_IconMessage

procedure IconTrayAct(var Msg: TMessage); message WM_IconMessage;

Msg的LParam是具体的消息,如WM_LButtonDown等。

可以
case Msg.LParam of
WM_LButtonDown : Act1;
WM_RButtonUp : Act2;
end;

还有不明白的地方,发信至poold@china.com



kill_kill01 2000-09-04
  • 打赏
  • 举报
回复
用控件,或用API:Shell_Notifoy

5,386

社区成员

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

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