在Delphi中定义快捷方式的“正确”方式是哪种?
发布时间:2020-12-15 04:30:15 所属栏目:大数据 来源:网络整理
导读:有很多关于如何在Delphi程序中定义ShortCut的例子,但是 他们归结为两种不同的方式: 将任何scCtrl,scShift和scAlt常量添加到键的Ord() 使用Menus.ShortCut功能 例如 Action.ShortCut := scCtrl + scShift + Ord('K');// vsAction.ShortCut := Menus.ShortCut
有很多关于如何在Delphi程序中定义ShortCut的例子,但是
他们归结为两种不同的方式: >将任何scCtrl,scShift和scAlt常量添加到键的Ord() 例如 Action.ShortCut := scCtrl + scShift + Ord('K'); // vs Action.ShortCut := Menus.ShortCut(Word('K'),[ssCtrl,ssShift]); 这两种方式之一是最好的?如果是,哪一个为什么? 解决方法
代码几乎相同,但ShortCut有一些额外的检查:
function ShortCut(Key: Word; Shift: TShiftState): TShortCut; begin Result := 0; if HiByte(Key) <> 0 then Exit; // if Key is national character then it can't be used as shortcut Result := Key; if ssShift in Shift then Inc(Result,scShift); // this is identical to "+" scShift if ssCtrl in Shift then Inc(Result,scCtrl); if ssAlt in Shift then Inc(Result,scAlt); end; 因为RegisterHotKey功能使用Virtual key codes(其值从$00到$FE)这个额外的检查是重要的. 请注意,实际的Ord函数代替Ord文档,返回smallint(带符号的Word),所以使用国家字符可以改变包含在ShortCut值的Hi字节中的修改器. 所以更好的是使用ShortCut功能. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容