program Project1;
uses windows, messages, sysutils;
{$R *.res}
var wnd, Instance, Handle : hwnd;
WindowClass : TWndClass;
msg : TMsg;
Procedure Close;
begin
UnRegisterHotKey(Handle, vk_f1);
UnRegisterHotKey(Handle, vk_f2);
UnRegisterHotKey(Handle, vk_f3);
UnRegisterHotKey(Handle, vk_f4);
Halt(255);
end;
function GetWMPHandle: hwnd;
begin
result := FindWindow('WMPlayerApp', nil);
result := FindWindowEx(result, 0, 'WMPAppHost', 'WMPAppHost');
if result = 0 then result := Findwindow(nil,'Windows Media Player');
end;
function WindowProc (Hwn,msg,wpr,Ipr: longint): longint; stdcall;
begin
wnd := GetWMPHandle;
if Msg=WM_KEYDOWN then
if Wpr=WM_Destroy then Close;
if msg=WM_HOTKEY then
case Wpr of
1: if wnd <> 0 then SendMessage(wnd,WM_APPCOMMAND,0,$C0000);
2: if wnd <> 0 then SendMessage(wnd,WM_APPCOMMAND,0,$B0000);
3: if wnd <> 0 then SendMessage(wnd,WM_APPCOMMAND,0,$E0000);
4: Close;
end;
result:=defwindowproc(hwn,msg,wpr,Ipr);
end;
begin
instance :=GetModuleHandle(nil);
WindowClass.style:=CS_HRedraw or CS_VRedraw;
WindowClass.HbrBackground:= color_btnface;
WindowClass.Hcursor:=LoadCursor(0,IDC_ARROW);
WindowClass.Lpfnwndproc:=@windowproc;
WindowClass.LpszClassName:='DX';
WindowClass.Hinstance:=Instance;
RegisterClass (WindowClass);
Handle:=CreateWindowEx (0,'DX', '' , WS_POPUP, 1,1, 200, 200,0,0,Instance, nil);
RegisterHotKey(Handle, 1, 0, vk_f1);
RegisterHotKey(Handle, 2, 0, vk_f2);
RegisterHotKey(Handle, 3, 0, vk_f3);
RegisterHotKey(Handle, 4, 0, vk_f4);
//ShowWindow(Handle,SW_SHOW);
//UpdateWindow(Handle);
while (GetMessage(msg, 0, 0, 0)) do
begin
translatemessage (msg) ;
dispatchmessage (msg);
end;
end.