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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
unit MSNInfo;
interface
type
pMSNInfo = ^tMSNInfo;
tMSNInfo = record
msnPlayer:PWideChar;
msnArtist:PWideChar;
msnTitle :PWideChar;
msnAlbum :PWideChar;
end;
procedure StartMSNHook;
procedure StopMSNHook;
function GetMSNInfo:pMSNInfo;
implementation
uses windows, messages, common;
const
HWND_MESSAGE = HWND(-3);
const
MSNClassName = 'MsnMsgrUIManager';
const
hMSNWindow:THANDLE = 0;
const
RealMSNData:PWideChar = nil;
anMSNInfo:tMSNInfo =(
msnPlayer:nil;
msnArtist:nil;
msnTitle :nil;
msnAlbum :nil
);
function GetMSNInfo:pMSNInfo;
begin
if ((anMSNInfo.msnPlayer=nil) or (anMSNInfo.msnPlayer^=#0)) and
((anMSNInfo.msnArtist=nil) or (anMSNInfo.msnArtist^=#0)) and
((anMSNInfo.msnTitle =nil) or (anMSNInfo.msnTitle ^=#0)) and
((anMSNInfo.msnAlbum =nil) or (anMSNInfo.msnAlbum ^=#0)) then
result:=nil
else
result:=@anMSNInfo;
end;
procedure ClearMSNInfo;
begin
if RealMSNData<>nil then
begin
mFreeMem(RealMSNData);
RealMSNData:=nil;
end;
FillChar(anMSNInfo,SizeOf(anMSNInfo),0);
{FreeMem(anMSNInfo.msnPlayer);} //anMSNInfo.msnPlayer:=nil;
{FreeMem(anMSNInfo.msnArtist);} //anMSNInfo.msnArtist:=nil;
{FreeMem(anMSNInfo.msnTitle); } //anMSNInfo.msnTitle :=nil;
{FreeMem(anMSNInfo.msnAlbum); } //anMSNInfo.msnAlbum :=nil;
end;
procedure Split(pc:PWideChar);
var
lpc:PWideChar;
begin
// Player
anMSNInfo.msnPlayer:=pc;
while (pc^<>'\') or ((pc+1)^<>'0') do inc(pc);
pc^:=#0;
inc(pc,2);
// Type
lpc:=pc;
while (pc^<>'\') or ((pc+1)^<>'0') do inc(pc);
pc^:=#0;
inc(pc,2);
if StrCmpW(lpc,'Music')<>0 then
begin
anMSNInfo.msnPlayer:=nil;
exit;
end;
// Status
lpc:=pc;
if lpc^='0' then // stop track
begin
anMSNInfo.msnPlayer:=nil;
exit;
end;
while (pc^<>'\') or ((pc+1)^<>'0') do inc(pc);
pc^:=#0;
inc(pc,2);
// Format - just skip
while (pc^<>'\') or ((pc+1)^<>'0') do inc(pc);
pc^:=#0;
inc(pc,2);
// Artist
anMSNInfo.msnArtist:=pc;
while (pc^<>'\') or ((pc+1)^<>'0') do inc(pc);
pc^:=#0;
inc(pc,2);
// Title
anMSNInfo.msnTitle:=pc;
while (pc^<>'\') or ((pc+1)^<>'0') do inc(pc);
pc^:=#0;
inc(pc,2);
// Album
anMSNInfo.msnAlbum:=pc;
while (pc^<>'\') or ((pc+1)^<>'0') do inc(pc);
pc^:=#0;
// WMContentID - not needs
end;
function dlgMSNHook(Dialog:HWND;hMessage:uint;wParam:WPARAM;lParam:LPARAM):LRESULT; stdcall;
var
pMyCDS:PCOPYDATASTRUCT;
begin
result:=0;
case hMessage of
WM_COPYDATA: begin
pMyCDS:=PCOPYDATASTRUCT(lParam);
if pMyCDS^.dwData=1351 then // Media player info
begin
ClearMSNInfo;
Split(StrDupW(RealMSNData,PWideChar(pMyCDS^.lpData)));
end;
end;
else
result:=DefWindowProc(Dialog,hMessage,wParam,lParam);
end;
end;
procedure StartMSNhook;
var
msnClass:TWNDCLASSW;
hMSNClass:THANDLE;
begin
FillChar(msnClass,SizeOf(TWNDCLASS),0);
msnClass.hInstance :=hInstance;
msnClass.lpszClassName:=MSNClassName;
msnClass.lpfnWndProc :=@dlgMSNHook;
hMSNClass:=RegisterClassW(msnClass);
if (hMSNClass<>0) and (hMSNWindow=0) then
begin
hMSNWindow:=CreateWindowExW(0,PWideChar(hMSNClass),nil,0,1,1,1,1,HWND_MESSAGE,0,hInstance,nil);
end;
ClearMSNInfo;
end;
procedure StopMSNHook;
begin
if hMSNWindow<>0 then
begin
DestroyWindow(hMSNWindow);
hMSNWindow:=0;
ClearMSNInfo;
UnRegisterClass(MSNClassName,hInstance);
end;
end;
//finalization
// StopMSNHook;
end.
|