你是说放在右下角的托盘里把?
要用两个api函数
1.使程序不出现在windows下面的状态栏中:
用setwindowlong()
2.将图标放入托盘:
用shell_notifyicon()
要用两个api函数
1.使程序不出现在windows下面的状态栏中:
用setwindowlong()
2.将图标放入托盘:
用shell_notifyicon()
解决方案 »
- delphi连接SQL数据库,编译出错,请问问题出在那里?
- 关于intraWeb的IWMemo在页面使用IWTemplateProcessorHTML时无法控制大小的问题
- 关于StringGrid控件如何返回黑选的多行序列号和内容
- 請問有沒有辦法用編程模擬按下已打開的IE網頁上的某一按鈕?
- 想用EXCEL做套打,不知道可行否?
- 对如何实现第二光标感兴趣的朋友请进来:
- 怎样在DBGrid中动态增加字段名?
- 一个数据库的问题。
- 还有爱分的高手吗?偶是牛虻,来帮偶呀!!!!!!!!!!!
- 急急,大家有没有好的控件包
- 用ado的控件 能实现 Ttable那样的cacheupdate功能吗?
- 送分的弱智sql问题,请大家帮帮忙
请问两个API函数怎样加入最小化的命令中?一定给分。请教教。
setwindowlong(application,handle,gwl_exstyle,ws_ex_toolwindow);
第二个挺麻烦的,除了用这个函数,还有做相关的鼠标点击的消息处理,你最好还是找找相关资料把
最好用showwindow()
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;implementationprocedure 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;end.
调用方法 Tfrm_main = class(TForm)
ilStatus: TImageList;
private
{ Private declarations }
public
{ Public declarations }
procedure On_My_Notifyicon(var mess:TMESSAGE);Message MYWM_NOTIFYICON;
end;Var
NewIcon:TIcon;
begin
NewIcon:=TIcon.Create;
ilStatus.GetIcon(0,NewIcon);
Icon_Add (Self.WindowHandle,Self.caption,NewIcon);
NewIcon.Free;
end;
procedure Tfrm_main.On_My_Notifyicon(var mess: TMESSAGE);
begin
inherited;
case Mess.lParam of
WM_LBUTTONDBLCLK,
WM_LBUTTONUP,
WM_RBUTTONUP: frm_main.Show;
end;
end;
2.不在任务栏显示图标用这个:
ShowWindow(Application.Handle,SW_HIDE);我常用的方法是:在窗口上放一个:TApplicationEvent 一个:TRxtrayicon在ApplicationEvent的OnMinimize事件中:
ShowWindow(Application.Handle,SW_HIDE);
在Rxtrayicon的OnClick事件中:
Application.Restore;
ShowWindow(Application.Handle,SW_SHOW);
Application.BringToFront;
----SYSTRAY ICON就是在WINDOWS 95桌面系统下边状态栏右边的区域,通常这里有输入法和时间的小图标。程序中增加使用该功能时,须在USES中添加`SHELLAPI`。添加图标时需要的函数是: Shell_NotifyIconA,它需要2个参数,一个参数是`TNotifyIconDataA`的结构,该结构如下:
TNOTIFYICONDATAA = record
cbSize: DWORD;
Wnd: HWND;
uID: UINT;
uFlags: UINT;
uCallbackMessage: UINT;
hIcon: HICON;
szTip: array [0..63] of AnsiChar;
end;----cbSize是该结构的长度;Wnd是调用Shell_NotifyIconA函数的窗口的Handle;uID是用户自定义的一个数值,在uCallbackMessage参数指定的消息中使用;uCallbackMessage是一个参数,当添加的图标上出现鼠标事件时,系统向Wnd参数指定的窗口发送一个消息,该消息的Msg参数是uCallbackMessage,该消息的wParam参数是uID,该消息的lParam参数是鼠标事件的Msg值。这样应用程序可使用几个图标,但只用一个消息处理函数,通过wParam参数决定处理哪一个图标的消息。uFlags是该结构中哪些项目有效,若有NIF_MESSAGE则uCallbackMessage参数是有效的;若有NIF_ICON则hIcon参数是有效的;若有NIF_TIP则szTip参数有效。----uCallbackMessage是发送到Wnd参数所指定的窗口的消息。hIcon是出现系统状态栏的图标的Handle。----szTip是当鼠标停留在系统状态栏图标上时,出现的提示。----该结构添好后,可调用Shell_NotifyIconA函数,格式为:Shell_NotifyIconA(dwMessage:
DWORD;lpData:PNotifyIconDataA)
dwMessage取值为
NIM_ADD:增加一个新图标
NIM_MODIFY:修改一个已有的图标
NIM_DELETE:删除一个已有的图标
----下面给出一个演示程序,该程序有两个按钮、一个弹出式菜单和一个Image构件。一个按钮用于添加图标,一个按钮用于删除图标,Image构件内有一个图标(从Delphi自带的图标中装入),在图标上用鼠标右键单击时,会弹出一个菜单。程序中自定义一个消息处理函数处理系统状态栏图标消息。
--------------------------------------------------------
unit Unit1;interfaceuses
Windows, Messages, SysUtils,
Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ShellApi, ExtCtrls, Menus;const mymsg=wm_user+1;iid=100;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Image1: TImage;
PopupMenu1: TPopupMenu;
a1: TMenuItem;
b1: TMenuItem;
c1: TMenuItem;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
procedure mymessage(var message:
tmessage);message mymsg;
public
{ Public declarations }
end;
var
Form1: TForm1;ntid:tnotifyicondataa;implementation{$R *.DFM}procedure TForm1.mymessage(var message:tmessage);
var mypt:tpoint;
begin
inherited;
if message.lparam=wm_rbuttonup then begin
getcursorpos(mypt);
popupmenu1.popup(mypt.x,mypt.y);end;
message.Result:=0;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ntid.cbSize:=sizeof(tnotifyicondataa);
ntid.Wnd:=handle;
ntid.uID:=iid;
ntid.uFlags:=nif_icon+nif_tip+nif_message;
ntid.uCallbackMessage:=mymsg;
ntid.hIcon:=image1.Picture.Icon.handle;
ntid.szTip:=`asdf`;
shell_notifyicona(NIM_ADD,@ntid);
end;procedure TForm1.Button2Click(Sender: TObject);
begin
ntid.cbSize:=sizeof(tnotifyicondataa);
ntid.Wnd:=handle;
ntid.uID:=iid;
ntid.uFlags:=nif_icon+nif_tip+nif_message;
ntid.uCallbackMessage:=mymsg;
ntid.hIcon:=image1.Picture.Icon.handle;
ntid.szTip:=`asdf`;
shell_notifyicona(NIM_DELETE,@ntid);
end;end.
找一个叫LMD的控件包,里面有一个控件,使用起来简单得很。