How to use window focus messages for a Delphi on-screen keyboard form

前端 未结 3 1941
感情败类
感情败类 2021-01-02 10:22

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

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-02 11:13

    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;
    

提交回复
热议问题