我在Project-Options中装入自己定义的图标,运行程序时任务栏中显示的是相应的图标,但是右边的托盘中显示的不是我所定义的图标,好像只有固定几种,怎么才能显示我定义的图标呢?
解决方案 »
- CXGRID 日期问题
- adoquery 参数设置,请高手指教,在线等
- 追溯TStrings,TStringList 的Create .不理解,还望高手指点
- 高手到哪里去了啊?[悬赏100分]
- 关于年度精华贴
- 求大家帮个忙:Delphi7中的Internet页上怎么没有TServerSocket和TClientSocket组件?
- 紧急! :-( 关于ServerSocket和ClientSocket之间通信的问题!!!
- delphi7 radiogroup组中 怎么知道有没有被选中呢? 如何取消radiogroup组中被选中的radiobutton
- c++ vs object pascal...
- 大家注意!!!!!救命呀。。。我用 D6 存了 D5 的工程
- 有关TTreeView的问题
- ActiveForm的问题!
搜一下,你就能发现一些。unit unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Forms, //Dialogs,
StdCtrls, Menus, Controls, ShellApi; //加上ShellApiconst
{自定义消息,当小图标捕捉到鼠标事件时Windows向回调函数发送此消息}
MYTRAY_MESSAGE = WM_USER + 100; //托盘图标返回消息type
TMainForm = class(TForm) TrayPopMenu: TPopupMenu;
pop1: TMenuItem;
pop2: TMenuItem;
N3: TMenuItem;
popExit: TMenuItem;
//窗口事件
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure FormPaint(Sender: TObject);
//弹出菜单事件
procedure popExitClick(Sender: TObject); private
{ Private declarations }
TrayIconData : TNotifyIconData; //定义托盘图标结构
//托盘消息处理事件
procedure MyTrayMessage(var message:TMessage);message MyTRAY_MESSAGE;
public
{ Public declarations }
end;var
MainForm: TMainForm;implementation{$R *.DFM}
// 窗口事件
//----------------------------------------------------------------
procedure TMainForm.FormCreate(Sender: TObject);
{var
ZAppName: array[0..127] of char;
Hold: String;
Found: HWND;
}
begin
//建立托盘图标
TrayIconData.cbSize := sizeof(TrayIconData); //TrayIconData变量的字节数
TrayIconData.Wnd := Handle; //主窗口句柄
TrayIconData.uID := 1; //内部标识,可设为任意数
TrayIconData.hIcon := Icon.Handle;
//要加入的图标句柄,可任意指定,此处为在Tform中Icon属性中指定的图标
//TrayIconData.hIcon := Application.Icon.Handle;
//此句使用了程序的图标,和上句程序有区别,下句亦可,但推荐使用上句,这样图标加
//入到托盘中时图标不会走样。
//TrayIconData.hIcon := LoadIcon(0,IDI_APPLICATION);
TrayIconData.szTip := '系统托盘示例程序'; // 图标的提示信息,即黄色的Hint
TrayIconData.uCallbackMessage := CDROMTRAY_MESSAGE; //回调函数消息
TrayIconData.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; //指明哪些字段有效
{将程序的窗口样式设为TOOL窗口,可避免在任务条上出现}
SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
//向托盘中添加图标
Shell_NotifyIcon(NIM_ADD, @TrayIconData);end;
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
TrayIconData.cbSize := sizeof(TrayIconData); //TrayIconData变量的字节数
TrayIconData.uID := 1; //内部标识,与加入小图标时的数一致
TrayIconData.Wnd := Handle; //主窗口句柄
//TrayIconData.uFlags := 0;
Shell_NotifyIcon(NIM_DELETE, @TrayIconData); //去掉小图标end;
//------------------------------------------------------------------
//托盘消息处理事件
//------------------------------------------------------------------
procedure TMainForm.CDRomTrayMessage(var message: Tmessage);
var
CursorPos : TPoint;begin
//在这里处理用户点击托盘图标事件,可以根据WM_MOUSEMOVE消息的不同情况产生不同的
//回应,例如区别对待单击和双击等等
case message.lParam of
//
//WM_LBUTTONDOWN :
//mcisendstring( pchar(cdromStatus),nil,0,handle);
//if not Busy then begin //ShowWindow(Handle, SW_SHOW ); WM_RBUTTONDOWN :
begin
GetCursorPos(CursorPos);
SetForegroundWindow(handle);
//此句作用是当程序失去焦点时,弹出菜单也随之消失。
Application.ProcessMessages;
//取得光标当前位置
TrayPopMenu.Popup( CursorPos.x ,CursorPos.y );
PostMessage(Application.MainForm.Handle, WM_NULL, 0, 0);
end;
end;end;
//----------------------------------------------------------//弹出菜单事件
//----------------------------------------------------------
procedure TMainForm.popExitClick(Sender: TObject);
begin
Close;
end;
//----------------------------------------------------------procedure TMainForm.FormPaint(Sender: TObject);
begin
Hide;
end;end.
http://www.8860.net/delphicode/dispdoc.asp?id=64
Busy: Boolean = false;
procedure TForm1.OnIconNotify(var Message: TMessage);
var
Mousepos: TPoint;
begin
if not Busy then
begin
Busy := true;
if Message.LParam=WM_LBUTTONDBLCLK then
form1.Visible := true;
end;
if Message.LParam = WM_RBUTTONDBLCLK then
begin
Mousepos := mouse.CursorPos;
popupmenu1.Popup(mousepos.X,mousepos.Y);
end;
Busy := false;
end;procedure TForm1.FormCreate(Sender: TObject);
var
nid: TNotifyIconData;
begin
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.Wnd := Handle; // 主窗口句柄
nid.uID := 0; // 内部标识,可设为任意数
nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?
nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?nid.szTip := 'This is a test application'; // 提示字符串
nid.uCallbackMessage := MY_MESSAGE; // 回调函数消息
nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有?if not Shell_NotifyIcon(NIM_ADD, @nid) then begin
ShowMessage('Failed!');
Application.Terminate;
end;
end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
nid: TNotifyIconData;
begin
nid.cbSize := sizeof(nid); // nid变量的字节数
nid.uID := 0; //内部标识,与加入小图标时的数一致
nid.Wnd := Handle; //主窗口句柄
Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标
end;procedure TForm1.Min(var Message: TMessage);
begin
if message.WParam = SC_MINIMIZE then
begin
form1.Visible := false;
ShowWindow(application.Handle,sw_Hide);
end
else if message.WParam = $F012 then
begin end
else
Inherited;
end;procedure TForm1.exit1Click(Sender: TObject);
begin
close;
end;procedure TForm1.about1Click(Sender: TObject);
begin
form1.Visible := true;
ShowWindow(application.Handle,sw_show);
end;procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
Mousepos: TPoint;
begin
if button = mbright then
begin
Mousepos := mouse.CursorPos;
popupmenu1.Popup(mousepos.X,mousepos.Y);
end;
end;试试!!!
然后处理自定义的消息