如何在delphi中实现窗体图标缩小到任务栏中

china_lyz 2002-01-22 10:56:55
...全文
79 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
aft_st_sd 2002-01-22
  • 打赏
  • 举报
回复
同意taxi(游少爷)

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,ShellAPI, Menus;
const
WM_TrayMessage=WM_User+100;
type
TForm1 = class(TForm)
pmTray: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure WMSysCommand(var Msg: TMessage);message WM_SYSCOMMAND;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
protected
procedure AppMinimized(Sender: TObject);
procedure WMTrayMessage(var msg:TMessage);message WM_TrayMessage;
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
NID:TNotifyIconData;

implementation

{$R *.DFM}

{ TForm1 }

procedure TForm1.AppMinimized(Sender: TObject);
begin
NID.cbSize:=SizeOf(TNotifyIconData);
NID.hIcon:=Application.Icon.Handle;
//NID.szTip:= '彩虹2.0 Beta ';
NID.uCallbackMessage:=WM_TrayMessage;
NID.uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
NID.uID:=0;
NID.Wnd:=Handle;
Shell_NotifyIcon(NIM_ADD,@NID);
ShowWindow(Application.Handle,SW_Hide);
end;

procedure TForm1.WMTrayMessage(var msg: TMessage);
var
p:TPoint;
begin
if msg.LParam=WM_LButtonDown then
begin
ShowWindow(Application.Handle,SW_Show);
Application.Restore;
end
else if msg.LParam=WM_RButtonDown then
begin
GetCursorPos(p);
pmTray.Popup(p.x,p.y);
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMinimize:=AppMinimized;
AppMinimized(nil);
end;

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

procedure TForm1.N1Click(Sender: TObject);
begin
ShowWindow(Application.Handle,SW_Show);
Application.Restore;
end;
40Star 2002-01-22
  • 打赏
  • 举报
回复
用samples->trayicon
taxi 2002-01-22
  • 打赏
  • 举报
回复
这个问题已经问烂了,搜一下吧。

5,392

社区成员

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

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