为什么我重载了控件的WindowProc过程,但截消息的时候就出问题了(200分)

  • 主题发起人 主题发起人 spdavid
  • 开始时间 开始时间
S

spdavid

Unregistered / Unconfirmed
GUEST, unregistred user!
OldActfrmWndProc: TWndMethod;
procedure ActfrmWndProc(var msg: TMessage);Message CN_KEYDOWN;

...

procedure TAFormX_Report.ActiveFormCreate(Sender: TObject);
begin
application.Handle := self.Handle;
OldActfrmWndProc := Spreadsheet1.WindowProc;
Spreadsheet1.windowProc := ActfrmWndProc;
end;

procedure TAFormX_Report.ActfrmWndProc(var msg: TMessage);
begin
if Msg.wParam =VK_F1 then
begin
AboutBox;
end
else if (Msg.wParam =VK_Left)or(Msg.wParam =VK_Return)or(Msg.wParam =VK_Up)or(Msg.wParam =VK_Right)or(Msg.wParam =VK_Down) then
begin
//Spreadsheet1.ActiveCell.Offset(1,1);
ShowMessage('test press!');
end
else if ((Msg.Msg = WM_RBUTTONDOWN) or (Msg.Msg = WM_RBUTTONUP)) then
begin
AboutBox;
end
else
begin
Inherited;
OldActfrmWndProc(msg);
end;
end;

但在实际操作中我按一下left键会出现二个test press!的信息框,各位知道为什么吗?
 
顶顶。拷回去试试
 
帮顶有份!![:D]
 
再顶啊大家帮帮忙啊[:(]
 
当然有两个了, 一个是WM_KEYDOWN,一个是WM_KEYUP
所以你要多加一个判断: Msg.msg=WM_KEYDOWN 或 WM_KEYUP
 
对了, 应该加个CN_BASE,所以应该是这样判断: Msg = CN_BASE + WM_KEYDOWN
[:)][:)]
 
to xiaojun:小弟初学delphi,能不能代码写详细点谢谢了
 
就是加一个条件啊:
procedure TAFormX_Report.ActfrmWndProc(var msg: TMessage);
begin
if Msg.wParam =VK_F1 then
begin
AboutBox;
end
else if (Msg = CN_BASE + WM_KEYDOWN) and ((Msg.wParam =VK_Left)or(Msg.wParam =VK_Return)or(Msg.wParam =VK_Up)or(Msg.wParam =VK_Right)or(Msg.wParam =VK_Down)) then
begin
//Spreadsheet1.ActiveCell.Offset(1,1);
ShowMessage('test press!');
end
else if ((Msg.Msg = WM_RBUTTONDOWN) or (Msg.Msg = WM_RBUTTONUP)) then
begin
AboutBox;
end
else
begin
Inherited;
OldActfrmWndProc(msg);
end;
end;
 
这个汗,我没加那个判断今天在家里电脑就好了不会执行两次,不过分还是给你吧[:)]

再次谢谢
 
后退
顶部