Delphi 분류
델파이 : System Tray에 Icon 넣기
컨텐츠 정보
- 25,397 조회
- 0 추천
- 목록
본문
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ShellApi, Menus;
const
WM_NOTIFYICON = WM_USER + 333;
type
TForm1 = class(TForm)
PopMenu: TPopupMenu;
Show1: TMenuItem;
EXit1: TMenuItem;
procedure EXit1Click(Sender: TObject);
procedure Show1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
NotifyIcnData : TNotifyIconData;
hMainIcon : HICON;
procedure ClickTrayIcon(var msg: TMessage); message WM_NOTIFYICON;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
// System Tray에 Icon의 Event 수신
procedure TForm1.ClickTrayIcon(var msg: TMessage);
var
pt: TPoint;
begin
case msg.lparam of
WM_LBUTTONDBLCLK : Show;
WM_RBUTTONDOWN :
begin
GetCursorPos(pt);
PopMenu.Popup(pt.x, pt.y);
end;
end;
end;
procedure TForm1.EXit1Click(Sender: TObject);
begin
Application.Terminate;
end;
// Form Close 했을 때
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caNone;
Hide; // Form 숨기기
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
// System Tray에 Icon 표시
hMainIcon := LoadIcon(MainInstance, 'MAINICON');
Shell_NotifyIcon(NIM_DELETE, @NotifyIcnData);
with NotifyIcnData do
begin
cbSize := sizeof(TNotifyIconData);
Wnd := handle;
uID := 11111;
uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
uCallbackMessage := WM_NOTIFYICON;
hIcon := HMainIcon;
szTip := 'System Tray Test';
end;
Shell_NotifyIcon(NIM_ADD, @NotifyIcnData);
end;
procedure TForm1.Show1Click(Sender: TObject);
begin
Show;
end;
end.
관련자료
-
링크
댓글 0
등록된 댓글이 없습니다.