如何使用窗口焦点消息为Delphi屏幕键盘窗体 [英] How to use window focus messages for a Delphi on-screen keyboard form

查看:909
本文介绍了如何使用窗口焦点消息为Delphi屏幕键盘窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中需要一个内置的屏幕数字小键盘。由于各种原因,我无法使用 TMS软件或其他商业组件产品。我非常高兴看到如下所示的基于按钮的解决方案,但是我看不出如何解决焦点切换问题,点击按钮可激活键盘格式,而我失去了我想要的角色的重点控制。我的解决方案是有效的,如果我把键盘按钮在目标的形式,但我想要一个独立于表单的解决方案。有没有办法禁用按钮激活或知道焦点来自哪里,以便我可以使用像Scree.ActiveControl:=?把它放回来?



解决方案

我不知道如何创建窗口,当您点击它是不可集中的框架,所以下面的一个是没有边界。如Andreas所说,使用TSpeedButtons。

 键入
TKeypadForm = class(TForm)
SpeedButton1:TSpeedButton ;
procedure SpeedButton1Click(Sender:TObject);
private
程序CreateParams(var Params:TCreateParams);覆盖
procedure WMMouseActivate(var Message:TWMMouseActivate);消息WM_MOUSEACTIVATE;
结束

程序TKeypadForm.CreateParams(var Params:TCreateParams);
begin
继承CreateParams(Params);
Params.Style:= WS_POPUP或WS_THICKFRAME;
结束

程序TKeypadForm.WMMouseActivate(var Message:TWMMouseActivate);
begin
Message.Result:= MA_NOACTIVATE;
结束

程序TKeypadForm.SpeedButton1Click(发件人:TObject);
begin
PostMessage(GetFocus,WM_KEYDOWN,VK_NUMPAD1,MakeLong(0,MapVirtualKey(VK_NUMPAD1,0)));
结束

这里是如何显示键盘窗口

  procedure TForm18.Edit1KeyDown(Sender:TObject; var Key:Word; 
Shift:TShiftState);
begin
case
的关键字VK_RETURN:ShowWindow(KeypadForm.Handle,SW_SHOWNOACTIVATE);
VK_ESCAPE:ShowWindow(KeypadForm.Handle,SW_HIDE);
结束
结束


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?

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆