把程序最小化并把图标放在状态栏: Shell_NotifyIconShell_NotifyIcon( DWORD dwMessage, PNOTIFYICONDATA pnid); dwMessage Message value to send. This parameter can be one of these values: NIM_ADD Adds an icon to the status area. NIM_DELETE Deletes an icon from the status area. NIM_MODIFY Modifies an icon in the status area. pnid Address of a NOTIFYICONDATA structure. The content of the structure depends on the value of dwMessage. 调用该函数后可以调用SetWindowlong函数把状态栏的显示去掉, 然后再把窗口的显示移出屏幕(只要把程序的Form移出能见到的地方,例如设置它的 Left:=screen.width+100).
Shell_NotifyIconShell_NotifyIcon( DWORD dwMessage,
PNOTIFYICONDATA pnid); dwMessage
Message value to send. This parameter can be one of these values: NIM_ADD Adds an icon to the status area.
NIM_DELETE Deletes an icon from the status area.
NIM_MODIFY Modifies an icon in the status area. pnid
Address of a NOTIFYICONDATA structure. The content of the structure depends on the value of dwMessage. 调用该函数后可以调用SetWindowlong函数把状态栏的显示去掉,
然后再把窗口的显示移出屏幕(只要把程序的Form移出能见到的地方,例如设置它的
Left:=screen.width+100).
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,shellapi,commctrl, Menus, ImgList;
const
ICON_ID=1;
ICONEVENT=WM_USER+1;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
ImageList1: TImageList;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure setcolor(Textcolor,textbkcolor:integer);
procedure installIcon;
procedure uninstallicon;
procedure iconclick(var message:Tmessage);message ICONEVENT;
public
function GetDesktopListViewHandle:THandle;
{ Public declarations }
end;var
Form1: TForm1;
earthicon:TIcon;
implementation
function Tform1.GetDesktopListViewHandle():THandle;
begin
result:=findwindow('progman',nil);
result:=getwindow(result,GW_CHILD);
result:=getwindow(result,GW_CHILD);
end;
{$R *.dfm}
procedure TForm1.setcolor(textcolor,textbkcolor:integer);
var
desk_hd:THandle;
begin
desk_hd:=getdesktoplistviewhandle;
listview_settextcolor(desk_hd,textcolor);
listview_settextbkcolor(desk_hd,textbkcolor);
listview_redrawitems(desk_hd,0,listview_getitemcount(desk_hd));
end;
procedure Tform1.installIcon ;
var
icondata:TNotifyIconData;
Apppath:string;
begin
apppath:=extractfiledir(application.ExeName );
earthicon:=Ticon.Create ;
earthicon.Handle:=form1.Icon.Handle ;
icondata.cbSize :=sizeof(icondata);
icondata.Wnd :=handle;
icondata.uID :=ICON_ID;
icondata.uFlags :=NIF_ICON or NIF_MESSAGE or NIF_TIP;
icondata.uCallbackMessage :=ICONEVENT;
icondata.hIcon :=earthicon.Handle ;
icondata.sztip:='更换桌面';
shell_notifyicon(NIM_ADD,@icondata);
end;
procedure Tform1.uninstallicon ;
var
icondata:Tnotifyicondata;
begin
icondata.cbSize :=sizeof(icondata);
icondata.Wnd :=Handle;
icondata.uID :=ICON_ID;
shell_notifyicon(NIM_DELETE,@icondata);end;
procedure Tform1.iconclick(var message:Tmessage);
var
p:Tpoint;
begin
if (message.LParam =WM_LBUTTONDOWN) then begin
getcursorpos(p);
popupmenu1.Popup(p.X,p.Y );
end;