简单问题,进来拿分吧!(100分)

  • 主题发起人 主题发起人 cjianwen
  • 开始时间 开始时间
C

cjianwen

Unregistered / Unconfirmed
GUEST, unregistred user!
我想写了个hotkey控件,但非可视控件怎么处理WM_HOTKEY消息呢?

好像只有窗体可以处理该消息,望高手指点!
 
把全局的键盘事件统统截获,用一个ApplicationEvents控件,响应OnMessage方法,搞定!

procedure TForm_Main.ApplicationEvents_MainMessage(var Msg: tagMSG;
var Handled: Boolean);
begin
if (Msg.message=WM_KEYDOWN) then
begin
//检查键盘状态
GetKeyboardState(KS);
if KeyboardStateToShiftState(KS) <> [] then
Exit;
//处理全局键盘事件
case Msg.wParam of
8: //Backspace
begin
if (self.Edit_Board.Focused() = false) then
self.Init();
Exit;
end;
116: //F5
begin
self.Init();
Exit;
end;
end;
end;
 
我是说要写成控件,如果不用控件我也可以实现的,现在基本上已经解决了上面的那个问题,但又出现了新问题,如果想让一个属性显示A到Z,F1到F12,应该用什么类型,枚举?
 
第一个问题可以通过owner的Handle解决消息问题
第二个问题应该定义一个枚举类型 楼主可以参考一下TColor的定义
TColor = -$7FFFFFFF-1..$7FFFFFFF;
const
clScrollBar = TColor(COLOR_SCROLLBAR or $80000000);
clBackground = TColor(COLOR_BACKGROUND or $80000000);
clActiveCaption = TColor(COLOR_ACTIVECAPTION or $80000000);
clInactiveCaption = TColor(COLOR_INACTIVECAPTION or $80000000);
clMenu = TColor(COLOR_MENU or $80000000);
clWindow = TColor(COLOR_WINDOW or $80000000);
clWindowFrame = TColor(COLOR_WINDOWFRAME or $80000000);
clMenuText = TColor(COLOR_MENUTEXT or $80000000);
clWindowText = TColor(COLOR_WINDOWTEXT or $80000000);
clCaptionText = TColor(COLOR_CAPTIONTEXT or $80000000);
clActiveBorder = TColor(COLOR_ACTIVEBORDER or $80000000);
clInactiveBorder = TColor(COLOR_INACTIVEBORDER or $80000000);
clAppWorkSpace = TColor(COLOR_APPWORKSPACE or $80000000);
clHighlight = TColor(COLOR_HIGHLIGHT or $80000000);
clHighlightText = TColor(COLOR_HIGHLIGHTTEXT or $80000000);
clBtnFace = TColor(COLOR_BTNFACE or $80000000);
clBtnShadow = TColor(COLOR_BTNSHADOW or $80000000);
clGrayText = TColor(COLOR_GRAYTEXT or $80000000);
clBtnText = TColor(COLOR_BTNTEXT or $80000000);
clInactiveCaptionText = TColor(COLOR_INACTIVECAPTIONTEXT or $80000000);
clBtnHighlight = TColor(COLOR_BTNHIGHLIGHT or $80000000);
cl3DDkShadow = TColor(COLOR_3DDKSHADOW or $80000000);
cl3DLight = TColor(COLOR_3DLIGHT or $80000000);
clInfoText = TColor(COLOR_INFOTEXT or $80000000);
clInfoBk = TColor(COLOR_INFOBK or $80000000);

clBlack = TColor($000000);
clMaroon = TColor($000080);
clGreen = TColor($008000);
clOlive = TColor($008080);
clNavy = TColor($800000);
clPurple = TColor($800080);
clTeal = TColor($808000);
clGray = TColor($808080);
clSilver = TColor($C0C0C0);
clRed = TColor($0000FF);
clLime = TColor($00FF00);
clYellow = TColor($00FFFF);
clBlue = TColor($FF0000);
clFuchsia = TColor($FF00FF);
clAqua = TColor($FFFF00);
clLtGray = TColor($C0C0C0);
clDkGray = TColor($808080);
clWhite = TColor($FFFFFF);
clNone = TColor($1FFFFFFF);
clDefault = TColor($20000000);
 
先把
self.KeyPreview := true;消息就往下走了
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部