Recent

Author Topic: [SOLVED] TEdit Password character is different from Windows UI  (Read 3494 times)

SassyPenguin

  • New Member
  • *
  • Posts: 49
[SOLVED] TEdit Password character is different from Windows UI
« on: January 24, 2022, 02:56:36 pm »
Hello, TEdit password character set to "*", however why it does not show as rounded dot like Windows 11 does?

Didn't notice if it is same as on Windows 10, I already upgraded to Windows 11.

Delphi showed as rounded dot.
« Last Edit: January 28, 2022, 12:02:03 pm by jamestien »
Lazarus 2.2.4 (Win11, Manjaro KDE, CachyOS KDE, Linux Mint)

AlexTP

  • Hero Member
  • *****
  • Posts: 2365
    • UVviewsoft
Re: TEdit Password character is different from Windows UI
« Reply #1 on: January 24, 2022, 03:02:28 pm »
Because '*' is the default value of the TEdit.PasswordChar property.

It is the misfeature of LCL- we cannot pass there WideChar with value >$ff.

SassyPenguin

  • New Member
  • *
  • Posts: 49
Re: TEdit Password character is different from Windows UI
« Reply #2 on: January 24, 2022, 03:17:29 pm »
Because '*' is the default value of the TEdit.PasswordChar property.

It is the misfeature of LCL- we cannot pass there WideChar with value >$ff.

Thanks for the information, I found that I can use Extended ASCII code (#149 for rounded dot) to substitute.  :D It looks better now...
« Last Edit: January 24, 2022, 03:23:27 pm by jamestien »
Lazarus 2.2.4 (Win11, Manjaro KDE, CachyOS KDE, Linux Mint)

Bart

  • Hero Member
  • *****
  • Posts: 5265
    • Bart en Mariska's Webstek
Re: TEdit Password character is different from Windows UI
« Reply #3 on: January 24, 2022, 06:48:18 pm »
#149 is not a valid UTF8 string or character (all strings and chars in LCL are supposed to be UTF8), so it's kind of a miracle that this works at all.

Bart

CM630

  • Hero Member
  • *****
  • Posts: 1076
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: TEdit Password character is different from Windows UI
« Reply #4 on: January 27, 2022, 07:58:32 pm »
On one hand using ascii in the 21st century seems absurd, but on the other hand #149 occurs to be the same bullet character in CP1250...1256, and maybe even further  :o


Лазар 3,0 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

SassyPenguin

  • New Member
  • *
  • Posts: 49
Re: TEdit Password character is different from Windows UI
« Reply #5 on: January 28, 2022, 12:46:16 pm »
On one hand using ascii in the 21st century seems absurd, but on the other hand #149 occurs to be the same bullet character in CP1250...1256, and maybe even further  :o

Yea, that's just a quick solution if we don't want get dirty. Create native EDIT control and sub messaging the control with Windows API calls is another absurd method, which takes more effort.

Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   Windows,Messages, SysUtils;
  7.  
  8. {$R *.res}
  9.  
  10. const
  11.   LPSTR_APP_CLASS = 'native_EditClass';
  12.   LPSTR_APP_TITLE = 'Native Edit Control (Windows)';
  13.   ID_PASSEDIT = 100;
  14.  
  15. var
  16.   hWin: HWND;
  17.  
  18.  
  19. function CreatePasswordEdit(Handle: HWND): HWND;
  20. var
  21.   hEdit: HWND;
  22. begin
  23.   hEdit := CreateWindowEx(WS_EX_CLIENTEDGE,'EDIT',nil,WS_CHILD or WS_TABSTOP or
  24.            WS_CLIPCHILDREN or WS_VISIBLE or ES_PASSWORD,
  25.             20,20,270,23,Handle,ID_PASSEDIT,hInstance,nil);
  26.  
  27.   SendMessage(hEdit, WM_SETFONT, GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(1, 0));
  28.  
  29.   Result := hEdit;
  30. end;
  31.  
  32. function ApplicationWndProc(Handle: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
  33. begin
  34.   case uMsg of
  35.     WM_CREATE:
  36.       SetFocus(CreatePasswordEdit(Handle));
  37.     WM_SYSCOMMAND:
  38.       case LOWORD(wParam) of
  39.         SC_CLOSE:
  40.           DestroyWindow(Handle);
  41.       end;
  42.     WM_COMMAND:
  43.       case LOWORD(wParam) of
  44.         IDCANCEL:
  45.           SendMessage(Handle,WM_SYSCOMMAND,SC_CLOSE,lParam);
  46.       end;
  47.     WM_DESTROY:
  48.       begin
  49.         DestroyWindow(GetDlgItem(Handle,ID_PASSEDIT));
  50.         PostQuitMessage(0);
  51.       end;
  52.   end;
  53.   Result := DefWindowProc(Handle,uMsg,wParam,lParam);
  54. end;
  55.  
  56.  
  57. {Register windows class}
  58. function ApplicationRegisterClass(const hInst: HINST; lpWndProc: POINTER): BOOL;
  59. var
  60.   hwndCls: TWNDCLASS;
  61. begin
  62.   hwndCls.style := CS_CLASSDC;
  63.   hwndCls.lpfnWndProc := WNDPROC(lpWndProc);
  64.   hwndCls.cbClsExtra := 0;
  65.   hwndCls.cbWndExtra := 0;
  66.   hwndCls.hInstance := hInst;
  67.   hwndCls.hIcon := LoadIcon(hInst,'MAINICON');
  68.   hwndCls.hCursor := LoadCursor(0,IDC_ARROW);
  69.   hwndCls.hbrBackground := COLOR_BTNFACE+1;
  70.   hwndCls.lpszMenuName := nil; //MAKEINTRESOURCE(RES_MENU_MAIN);
  71.   hwndCls.lpszClassName := LPSTR_APP_CLASS;
  72.  
  73.   Result := (RegisterClass(hwndCls)<>0);
  74. end;
  75.  
  76. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  77. function ApplicationCreateWindows(const hInst: HINST): BOOL;
  78. begin
  79.   hWin := CreateWindow(LPSTR_APP_CLASS,LPSTR_APP_TITLE,WS_SYSMENU,
  80.                        CW_USEDEFAULT,CW_USEDEFAULT,350,150,
  81.                        0,0,hInst,nil);
  82.   if (hWin<>0) then
  83.     begin
  84.       ShowWindow(hWin,SW_SHOWNORMAL);
  85.       UpdateWindow(hWin);
  86.       Result := TRUE;
  87.     end
  88.   else
  89.     Result := FALSE;
  90. end;
  91.  
  92.  
  93. {------------------ Main window message loop--------------------}
  94. function ApplicationMessageLoop(const hInst: HINST; const hOwner: HWND): WPARAM;
  95. var
  96.   uMsg: TMSG;
  97. begin
  98.  
  99.   while GetMessage(uMsg,0,0,0) do
  100.     begin
  101.       TranslateMessage(uMsg);
  102.       DispatchMessage(uMsg);
  103.     end;
  104.   Result := uMsg.wParam;
  105. end;
  106.  
  107.  
  108.  
  109. {Program main entry}
  110. begin
  111.   if ApplicationRegisterClass(hInstance,@ApplicationWndProc) then
  112.     begin
  113.       if ApplicationCreateWindows(hInstance) then
  114.           Halt(ApplicationMessageLoop(hInstance,hWin))
  115.       else
  116.         MessageBox(hInstance,'Cannot create application window, call to CREATEWINDOW failed!','Error Starting Program',MB_ICONSTOP)
  117.     end
  118.   else
  119.     MessageBox(hInstance,'Cannot register application class, call to REGISTERCLASS failed!','Error Starting Program',MB_ICONSTOP);
  120.  
  121. end.
  122.  
  123.  
« Last Edit: January 28, 2022, 12:48:57 pm by jamestien »
Lazarus 2.2.4 (Win11, Manjaro KDE, CachyOS KDE, Linux Mint)

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1311
    • Lebeau Software
Re: [SOLVED] TEdit Password character is different from Windows UI
« Reply #6 on: January 29, 2022, 12:50:08 am »
In Delphi, when TEdit.PasswordChar is set to any value other than #0, the EDIT window is created with the ES_PASSWORD window style, and if Visual Styles are enabled and PasswordChar='*' then an EM_SETPASSWORDCHAR message is NOT ISSUED to the window, thus allowing it to display its native default (and nice looking) asterisk dots.

To rephrase - EM_SETPASSWORDCHAR is issued ONLY when Visual Styles are disabled, or the app specifies any character other than '*'.

I have not looked at LCL's implementation yet, does it do the same thing?  Or does it force EM_SETPASSWORDCHAR regardless of the environment?
« Last Edit: January 29, 2022, 12:53:22 am by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

 

TinyPortal © 2005-2018