miodrag
miodrag

Reputation: 99

custom control sensing accelchar

I'm trying to figure how to make my custom control (based on static text) respond to accelerator key (delphi, which i use, names it accelchar) press. By responding i mean adding some code. Best i came up with is processing WM_SYSKEYUP and checking the caption and the character code manually. I suspect there must be a simpler and more reliable solution.

Upvotes: 0

Views: 143

Answers (1)

GolezTrol
GolezTrol

Reputation: 116190

You say your control is based on TStaticText. If you peek into TStaticText (or its ancestor, TCustomStaticText actually), you will see a message handler that handles the default behavior of focusing another control:

procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;

In its implementation, you can see how it verifies its own state:

if (FFocusControl <> nil) and Enabled and ShowAccelChar and
  IsAccel(Message.CharCode, Caption) then

In the base implmentation, the focuscontrol will be focused when that if is entered, but in your implementation, you can simply make a new message handler, with that same if in it, and add your own implementation to it.

Upvotes: 0

Related Questions