WH_GETMESSAGE, WH_CALLWNDPROC 훅 걸고 사용하는 원형 예제.
대충 DLL에 구겨넣고 쓰면 됨...
// 전역변수
var
gHotKeyHook, gWndProcHook: HHOOK;
// WM_HOTKEY Hook
function MsgProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
Msg: PMSG;
ModKey, VK: Integer;
begin
if nCode=HC_ACTION then begin
Msg:=PMSG(lParam);
case Msg^.message of
// Ctrl + Space
WM_HOTKEY: begin
ModKey:=LOWORD(Msg^.lParam);
VK :=HIWORD(Msg^.lParam);
if (ModKey=MOD_CONTROL) and (VK=VK_SPACE) then begin
OutputDebugString('HotKey Pressed [Ctrl+Space]');
end;
end;
end;
end;
Result:=CallNextHookEx(gHotKeyHook, nCode, wParam, lParam);
end;
// WM_WINDOWPOSCHANGING Hook
function WndProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
cwps: PCWPSTRUCT;
WinPos: PWINDOWPOS;
begin
cwps:=PCWPSTRUCT(lParam);
case cwps.message of
WM_WINDOWPOSCHANGING: begin
WinPos:=PWINDOWPOS(cwps.lParam);
OutputDebugString(Format('[WinPos] X=%d : Y=%d (cx=%d, cy=%d)', [WinPos.x, WinPos.y, WinPos.cx, WinPos.cy]));
end;
end;
Result:=CallNextHookEx(gWndProcHook, nCode, wParam, lParam);
end;
// Hook 걸기
gHotKeyHook:=SetWindowsHookEx(WH_GETMESSAGE, @MsgProc, hInstance(알아서..), 알아서..);
gWndProcHook:=SetWindowsHookEx(WH_CALLWNDPROC, @WndProc, hInstance(알아서..), 알아서..);
// Hook 뽑기
UnHookWindowsHookEx(gHotKeyHook);
UnHookWindowsHookEx(gWndProcHook);
var
gHotKeyHook, gWndProcHook: HHOOK;
// WM_HOTKEY Hook
function MsgProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
Msg: PMSG;
ModKey, VK: Integer;
begin
if nCode=HC_ACTION then begin
Msg:=PMSG(lParam);
case Msg^.message of
// Ctrl + Space
WM_HOTKEY: begin
ModKey:=LOWORD(Msg^.lParam);
VK :=HIWORD(Msg^.lParam);
if (ModKey=MOD_CONTROL) and (VK=VK_SPACE) then begin
OutputDebugString('HotKey Pressed [Ctrl+Space]');
end;
end;
end;
end;
Result:=CallNextHookEx(gHotKeyHook, nCode, wParam, lParam);
end;
// WM_WINDOWPOSCHANGING Hook
function WndProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
cwps: PCWPSTRUCT;
WinPos: PWINDOWPOS;
begin
cwps:=PCWPSTRUCT(lParam);
case cwps.message of
WM_WINDOWPOSCHANGING: begin
WinPos:=PWINDOWPOS(cwps.lParam);
OutputDebugString(Format('[WinPos] X=%d : Y=%d (cx=%d, cy=%d)', [WinPos.x, WinPos.y, WinPos.cx, WinPos.cy]));
end;
end;
Result:=CallNextHookEx(gWndProcHook, nCode, wParam, lParam);
end;
// Hook 걸기
gHotKeyHook:=SetWindowsHookEx(WH_GETMESSAGE, @MsgProc, hInstance(알아서..), 알아서..);
gWndProcHook:=SetWindowsHookEx(WH_CALLWNDPROC, @WndProc, hInstance(알아서..), 알아서..);
// Hook 뽑기
UnHookWindowsHookEx(gHotKeyHook);
UnHookWindowsHookEx(gWndProcHook);
'Delphi' 카테고리의 다른 글
[Delphi] 윈도우 스타일 문자열로 가져오기 (GWL_STYLE, GWL_EXSTYLE) (0) | 2010.06.08 |
---|---|
[Delphi] 폰트 크기 픽셀로 가져오기. (Font, Pixel) (0) | 2010.06.08 |
[Delphi] 각 OS별 NewLine 처리 (CR/LF) (0) | 2010.06.07 |
[Delphi] 실행파일 버전정보 가져오기 (0) | 2010.06.04 |
[Delphi] 문자열이 숫자로만 되어 있는지 체크 (0) | 2010.06.03 |