图形(image,Line)组件中如何获得方向键消息?wm_keydown不起作用,wm_keyup又可以! (200分)

  • 主题发起人 主题发起人 wen
  • 开始时间 开始时间
W

wen

Unregistered / Unconfirmed
GUEST, unregistred user!
新作image,及Line组件,要求在运行时可以用keyboard改变大小,如(shift+left 改变width).
目前不能正确:Tab,up,down,left,right方向键,一按以上几个键就失去焦点.其它键可以获取.
问题是,方向键与普遍字符键有什么不同?为什么按方向键时不能取得wm_keydown消息?
请问各位大侠!
 
真的沒人知道??
 
把Form的KeyPriview=true,捕捉Form消息,因为image不是继承自TWincontrol,

所以不能接受消息(也就是无Handle属性)
 
看清楚先,這image組件是我新的,改變了繼承關系.只是Tab,up,down,left,right幾個鍵
不能獲取的.
 
贴一段代码,不知道对你是否有用
procedure CMDialogKey(var Msg: TCMDialogKey); message CM_DIALOGKEY;
.............................................
//通过方向键控制控件的移动
procedure TDesignForm.CMDialogKey(var Msg: TCMDialogKey);
var
ShiftState: TShiftState;
tmp_x,tmp_Y:integer;
begin
ShiftState := KeyDataToShiftState(Msg.KeyData);
case Msg.CharCode of
VK_UP: //处理上箭头键按下,向上移动当前选定控件
begin
if FocusObject=nil then exit;
if (FocusObject<>DesignForm) and (FocusObject<>image1) then
begin
Tmp_Y:=(FocusObject as TGraphicControl).Top;
DEC(Tmp_Y,N);
(FocusObject as TGraphicControl).Top:=Tmp_Y;
RepDgnForm.now_Y.Caption:=IntToStr(Tmp_Y);
Tmp_Y:=Atest.Top;
DEC(Tmp_Y,N);
Atest.Top:=Tmp_Y;
end;
end;
VK_DOWN: //处理下箭头键按下,向下移动当前选定控件
begin
if FocusObject=nil then exit;
if (FocusObject<>DesignForm) and (FocusObject<>image1) then
begin
Tmp_Y:=(FocusObject as TGraphicControl).Top;
INC(Tmp_Y,N);
(FocusObject as TGraphicControl).Top:=Tmp_Y;
RepDgnForm.now_Y.Caption:=IntToStr(Tmp_Y);
Tmp_Y:=Atest.Top;
INC(Tmp_Y,N);
Atest.Top:=Tmp_Y;
end;
end;
VK_LEFT: //处理左箭头键按下,向左移动当前选定控件
begin
if FocusObject=nil then exit;
if (FocusObject<>DesignForm) and (FocusObject<>image1) then
begin
Tmp_X:=(FocusObject as TGraphicControl).Left;
DEC(Tmp_X,N);
(FocusObject as TGraphicControl).Left:=Tmp_X;
RepDgnForm.now_X.Caption:=IntToStr(Tmp_X);
Tmp_X:=Atest.Left;
DEC(Tmp_X,N);
Atest.Left:=Tmp_X;
end;
end;
VK_RIGHT: //处理右箭头键按下,向右移动当前选定控件
begin
if FocusObject=nil then exit;
if (FocusObject<>DesignForm) and (FocusObject<>image1) then
begin
Tmp_X:=(FocusObject as TGraphicControl).Left;
INC(Tmp_X,N);
(FocusObject as TGraphicControl).Left:=Tmp_X;
RepDgnForm.now_X.Caption:=IntToStr(Tmp_X);
Tmp_X:=Atest.Left;
INC(Tmp_X,N);
Atest.Left:=Tmp_X;
end;
end;
end;
inherited;//要调用缺省的处理
end;
 
这个问题前面讨论过,DELPHI屏蔽了WM_KEYDOWN消息,你要用CN_KEYDOWN消息来代替
你可以这样写:
Procedure WMKeydown(Var Msg: TMessage);Message CN_KEYDOWN;
即可解决你所提出的问题,要详细了解这个问题你可以跟踪一下DELPHI的程序,我记不清
消息分派在哪个单元中了
 
发送自己的消息,
 
多人接受答案了。
 
后退
顶部