拦截消息处理过程 program Project1; uses Forms messages wintypes winprocs Unit1 in 'UNIT1.PAS' {Form1}; {$R *.RES} var OldWndProc: TFarProc; function NewWndProc(hWndAppl: HWnd; Msg wParam: Word; lParam: Longint): Longint; export; begin NewWndProc := 0; { Default WndProc return value } NewWndProc := CallWindowProc(OldWndProc hWndAppl Msg wParam lParam); end; begin Application.CreateForm(TForm1 Form1); OldWndProc := TFarProc(GetWindowLong(Application.Handle GWL_WNDPROC)); SetWindowLong(Application.Handle GWL_WNDPROC longint(@NewWndProc)); Application.Run; end.win消息一般用hook做的,例如key,mouse
不用那么麻烦,你在窗口的OnKeyDown事件中写入如下类似的代码: procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key=VK_LWIN//VK_LWIN是左Win键,VK_RWIN是右Win键 then begin //你的处理代码 end; end;
program Project1;
uses
Forms
messages
wintypes
winprocs
Unit1 in 'UNIT1.PAS' {Form1};
{$R *.RES}
var
OldWndProc: TFarProc;
function NewWndProc(hWndAppl: HWnd; Msg
wParam: Word;
lParam: Longint): Longint; export;
begin
NewWndProc := 0; { Default WndProc return value }
NewWndProc := CallWindowProc(OldWndProc
hWndAppl
Msg
wParam
lParam);
end;
begin
Application.CreateForm(TForm1
Form1);
OldWndProc := TFarProc(GetWindowLong(Application.Handle
GWL_WNDPROC));
SetWindowLong(Application.Handle
GWL_WNDPROC
longint(@NewWndProc));
Application.Run;
end.win消息一般用hook做的,例如key,mouse
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=VK_LWIN//VK_LWIN是左Win键,VK_RWIN是右Win键
then begin
//你的处理代码
end;
end;