如何为 Delphi 屏幕键盘表单使用窗口焦点消息 [英] How to use window focus messages for a Delphi on-screen keyboard form
问题描述
我的应用程序需要一个内置的屏幕数字小键盘.由于各种原因,我无法使用 TMS 软件 或其他商业组件产品.我对下面显示的基于按钮的解决方案感到非常满意,但我还看不到如何解决焦点开关问题,即单击按钮会激活键盘表单并且我失去了我想要字符的焦点控制.如果我将键盘按钮保留在目标表单中,我的解决方案就可以工作,但我想要一个独立于表单的解决方案.有没有办法禁用按钮激活或知道焦点来自哪里,以便我可以使用类似 Scree.ActiveControl :=??放回去?
I need a built-in on screen numeric keypad in my Application. For various reasons I cannot use the TMS Software or other commercial component offerings. I'm very happy with a button-based solution shown below but I cannot yet see how to solve the focus switch issue where clicking the button activates the keypad form and I lose the focused control into which I wanted the characters. My solution works if I keep the keypad buttons within the target form but I would like a form-independent solution. Is there a way of disabling the button activation or knowing where the focus came from so that I can use something like Scree.ActiveControl :=?? to put it back?
推荐答案
我不知道如何创建一个点击时无法聚焦的窗口,所以下面的一个是没有边框的.正如 Andreas 所说,使用 TSpeedButtons.
I don't know how to create window with the frame which is unfocusable when you click it, so the following one is without border. And as Andreas mentioned, use TSpeedButtons.
type
TKeypadForm = class(TForm)
SpeedButton1: TSpeedButton;
procedure SpeedButton1Click(Sender: TObject);
private
procedure CreateParams(var Params: TCreateParams); override;
procedure WMMouseActivate(var Message: TWMMouseActivate); message WM_MOUSEACTIVATE;
end;
procedure TKeypadForm.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style := WS_POPUP or WS_THICKFRAME;
end;
procedure TKeypadForm.WMMouseActivate(var Message: TWMMouseActivate);
begin
Message.Result := MA_NOACTIVATE;
end;
procedure TKeypadForm.SpeedButton1Click(Sender: TObject);
begin
PostMessage(GetFocus, WM_KEYDOWN, VK_NUMPAD1, MakeLong(0, MapVirtualKey(VK_NUMPAD1, 0)));
end;
这是显示键盘窗口的方法
And here's how to show the keypad window
procedure TForm18.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_RETURN: ShowWindow(KeypadForm.Handle, SW_SHOWNOACTIVATE);
VK_ESCAPE: ShowWindow(KeypadForm.Handle, SW_HIDE);
end;
end;
这篇关于如何为 Delphi 屏幕键盘表单使用窗口焦点消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!