1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
|
unit Utest;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ShellApi;
const
WM_TNAEVENT = WM_USER + $1337;
type
TForm1 = class(TForm)
Button1: TButton;
OpenDialog1: TOpenDialog;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
procedure TrayMsgHandler(var Message:TMessage);message WM_TNAEVENT;
public
{ Public-Deklarationen }
end;
var
Form1 : TForm1;
str : TMemoryStream;
tray_hint : String = '';
tray : NOTIFYICONDATA;
implementation
{$R *.dfm}
(*
uses
madkernel;
*)
procedure TForm1.Button1Click(Sender: TObject);
var
gros, klein : HICON;
(*i : Integer;*)
begin
if OpenDialog1.Execute then
ExtractIconEx(PCHAR(OpenDialog1.FileName),0,gros,klein,1);
(*
for i := 0 to TrayIcons.ItemCount - 1 do
if lowercase(ExtractFilename(TrayIcons[i].Window.OwnerProcess.ExeFile)) = lowercase(ExtractFileName(OpenDialog1.FileName))
then tray_hint := TrayIcons[i].Hint;
*)
with TIcon.Create do
begin
Handle := klein;
SaveToStream(str);
Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
icon : TICON;
begin
icon := TICON.Create;
str.Seek(0,soFromBeginning);
icon.LoadFromStream(str);
with tray do
begin
cbSize := SizeOf(tray);
Wnd := Handle;
uID := 0;
uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
uCallbackMessage := WM_TNAEVENT;
if tray_hint <> '' then
StrPLCopy(szTip,tray_hint,255)
else StrPLCopy(szTip,OpenDialog1.FileName,255);
hIcon := icon.Handle;
end;
Shell_NotifyIcon(NIM_ADD,@tray);
icon.Free;
end;
procedure TForm1.TrayMsgHandler(var Message: TMessage);
begin
if Message.LParam = WM_LBUTTONDOWN then
MessageDlg('Ein Fehler ist aufgetreten', mtError, [mbOK], 0);
end;
INITIALIZATION
str := TMemoryStream.Create;
FINALIZATION
FreeAndNil(str);
Shell_NotifyIcon(NIM_DELETE,@tray);
end.
|