Bookstore

Recent

Author Topic: Backspace key on smartphone  (Read 7547 times)

skoro

  • New member
  • *
  • Posts: 5
Backspace key on smartphone
« on: March 11, 2010, 06:47:54 pm »
Hi!
I have simple form with TEdit component and TMenu. Pressing Backspace key on TEdit cause to hide app instead to delete char in TEdit. Digging WinAPI I known that it smartphone feature and to get work proper you must handle SHSendBackToFocusWindow message but how I can handle WinAPI messages in TForm component?
PS: I am use native lazarus WinCE components, not KOL-CE

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Backspace key on smartphone
« Reply #1 on: March 12, 2010, 11:42:40 am »
It's a function, not a message:

http://msdn.microsoft.com/en-us/library/bb431757.aspx

I'm not sure where the routine should be called however

skoro

  • New member
  • *
  • Posts: 5
Re: Backspace key on smartphone
« Reply #2 on: March 14, 2010, 06:43:36 pm »
Solved. Just for history. Invoke below form as
Code: [Select]
frmResolver.Show I see that
Code: [Select]
ShowModal not stable with this code.
Also, on form must be TMenu, thus in all TEdit component Backspace on smartphone worked as usual: delete char, not close form.
Code: [Select]
unit formResolver;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  ExtCtrls, Menus, Buttons, StdCtrls;

type
  TfrmResolver = class(TForm)
    appMenu: TMainMenu;
    appMenuClose: TMenuItem;
    btnResolve1: TBitBtn;
    btnResolve2: TBitBtn;
    editResIpAddr: TEdit;
    editResHostname: TEdit;
    editIpAddr: TEdit;
    editHostname: TEdit;
    stHostname: TStaticText;
    stIpAddr: TStaticText;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
  public
  end;

var
  frmResolver: TfrmResolver;

implementation

uses Windows, aygshell;

var
    OldWndProc: WNDPROC;

{$R *.lfm}

procedure SHSendBackToFocusWindow(uMsg: UINT; wp: WPARAM; lp: LPARAM) external 'aygshell' index 97;

function WndCallback(Ahwnd: HWND; uMsg: UINT; wParam: WParam; lParam: LParam): LRESULT; stdcall;
begin
  if uMsg = WM_HOTKEY then begin
    if HIWORD(lParam) = VK_ESCAPE then begin
      SHSendBackToFocusWindow(uMsg, wParam, lParam);
      Exit;
    end;
  end;
  Result := CallWindowProc(OldWndProc, Ahwnd, uMsg, wParam, lParam);
end;

procedure TfrmResolver.FormShow(Sender: TObject);
begin
  editHostname.SetFocus;
end;

procedure TfrmResolver.FormCreate(Sender: TObject);
var
  mbi: SHMenuBarInfo;
begin
  mbi.hwndMB := SHFindMenuBar(frmResolver.Handle);
  if mbi.hwndMB <> 0 then
     SendMessage(mbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_ESCAPE,
       MAKELPARAM(SHMBOF_NODEFAULT or SHMBOF_NOTIFY, SHMBOF_NODEFAULT or SHMBOF_NOTIFY)
     );
  OldWndProc := Windows.WNDPROC(SetWindowLong(Self.Handle, GWL_WNDPROC, PtrInt(@WndCallback)));
end;

end.

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3541
Re: Backspace key on smartphone
« Reply #3 on: July 24, 2010, 02:21:50 pm »
Just for the record: The calling convention you used it wrong, it should be cdecl in WinCE, not stdcall. This can cause all kinds of problems.

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 168
    • http://www.jvdw.nl
Re: Backspace key on smartphone
« Reply #4 on: July 24, 2010, 02:46:17 pm »
@skoro:

What happens if you use ShowModal?

I see no problems?

kr,
John