我按了键盘,为什么不触发WM_KEYDOWN事件呢?
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject); private
{ Private declarations }
public
procedure smproc(var message:TMessage);
message WM_KEYDOWN;
Procedure llxporc(var message:TMessage);
message WM_LLX;
{ Public declarations }
end;procedure TForm1.smproc(var message:TMessage);
begin
showmessage('show bu cuolai');
end;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject); private
{ Private declarations }
public
procedure smproc(var message:TMessage);
message WM_KEYDOWN;
Procedure llxporc(var message:TMessage);
message WM_LLX;
{ Public declarations }
end;procedure TForm1.smproc(var message:TMessage);
begin
showmessage('show bu cuolai');
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TForm1 = class(TForm)
private
{ Private declarations }
procedure WMKEYDOWN(var AMsg: TMessage); message WM_KEYDOWN;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.WMKEYDOWN(var AMsg: TMessage);
begin
ShowMessage('Key Down');
end;end.
var
ShiftState: TShiftState;
Form: TCustomForm;
begin
Result := True;
Form := GetParentForm(Self);
if (Form <> nil) and (Form <> Self) and Form.KeyPreview and
TWinControl(Form).DoKeyDown(Message) then Exit;
with Message do
begin
ShiftState := KeyDataToShiftState(KeyData);
if not (csNoStdEvents in ControlStyle) then
begin
KeyDown(CharCode, ShiftState);
if CharCode = 0 then Exit;
end;
end;
Result := False;
end;procedure TWinControl.WMKeyDown(var Message: TWMKeyDown);
begin
if not DoKeyDown(Message) then inherited;
UpdateUIState(Message.CharCode);
end;