![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Как перехватить сообщения без KOL applet и Form.OnMessage
Psychedelic © (2006-10-13 14:22:00)Всем привет. Как можно перехватывать все сообщения (message) (WindowProc),
но БЕЗ помощи KolApplet и Form.OnMessage . Чисто в образовательных целях. Вобщем не кидая компонентов. На API в кол.
Thaddy (2006-10-13 15:13:00) [1]Better:
program Project1;
uses
Windows, Messages, kol, objects;
var
Msg: TMsg;
Handle:Hwnd;
Stream:PStream;
i:integer;
UtilWindowClass: TWndClass = (
style: 0;
lpfnWndProc: @DefWindowProc;
cbClsExtra: 0;
cbWndExtra: 0;
hInstance: 0;
hIcon: 0;
hCursor: 0;
hbrBackground: 0;
lpszMenuName: nil;
lpszClassName: 'KOLFakeUtilWindow');
function WindowProc(hWnd,Msg,wParam,lParam:Integer):hwnd; stdcall;
begin
if Msg = WM_DESTROY then PostQuitMessage(0);
Result := DefWindowProc(hWnd,Msg,wParam,lParam);
end;
begin
Handle := CreateWindowEx(WS_EX_TOOLWINDOW, UtilWindowClass.lpszClassName,
'', WS_POPUP {!0}, 0, 0, 0, 0, 0, 0, HInstance, nil);
Stream := NewWriteFilestream('c:\Test.log');
for i := 0 to 9 do
postmessage(Handle,WM_USER,i,0);
while GetMessage(Msg,0,0,0) do
begin
Stream.WriteStr(Int2Hex(msg.message,4)+' '+Int2Str(msg.wparam)+' ');
DispatchMessage(Msg);
end;
Stream.free;
end.
Thaddy (2006-10-13 15:07:00) [2]program Project1;
uses
Windows, Messages, kol, objects;
var
wClass: TWndClass;
Msg: TMsg;
Handle:Hwnd;
Stream:PStream;
i:integer;
UtilWindowClass: TWndClass = (
style: 0;
lpfnWndProc: @DefWindowProc;
cbClsExtra: 0;
cbWndExtra: 0;
hInstance: 0;
hIcon: 0;
hCursor: 0;
hbrBackground: 0;
lpszMenuName: nil;
lpszClassName: 'KOLFakeUtilWindow');
function WindowProc(hWnd,Msg,wParam,lParam:Integer):hwnd; stdcall;
begin
if Msg = WM_DESTROY then PostQuitMessage(0);
Result := DefWindowProc(hWnd,Msg,wParam,lParam);
end;
begin
wClass.lpszClassName:= 'CN';
wClass.lpfnWndProc := @WindowProc;
wClass.hInstance := hInstance;
wClass.hbrBackground:= 1;
RegisterClass(wClass);
Handle := CreateWindowEx(WS_EX_TOOLWINDOW, UtilWindowClass.lpszClassName,
'', WS_POPUP {!0}, 0, 0, 0, 0, 0, 0, HInstance, nil);
Stream := NewWriteFilestream('c:\Test.log');
for i := 0 to 9 do
postmessage(Handle,WM_USER,i,0);
while GetMessage(Msg,0,0,0) do
begin
Stream.WriteStr(Int2Hex(msg.message,4)+' '+Int2Str(msg.wparam));
DispatchMessage(Msg);
end;
Stream.free;
end.