Edit box control password maks character becomes asterisk? Topic is solved

Report problems with documented functionality
User avatar
Scoox
Posts: 125
Joined: 11 May 2014, 09:12
Location: China

Edit box control password maks character becomes asterisk?

16 Dec 2016, 22:36

Please run the following code:

Code: Select all

#NoEnv
#SingleInstance Force

M := 10
Gui, Margin, %M%, %M%
Gui, Font, s16
Gui, Add, Edit, Password vEdit1 w200, Hello world
Gui, Add, Checkbox, -Checked vCheckbox1 gShow wp, Show password
Gui, Show
Return

Show()
{
	Global
	Gui, Submit, NoHide
	If Checkbox1
		GuiControl, -Password, Edit1
	Else
		GuiControl, +Password, Edit1
		;GuiControl, +Password●, Edit1 ;Problem 1: Default bullet character not used unless explicitly specified
	GuiControl,, Edit1, %Edit1% ;Problem 2: control not updated unless manually re-written or mouse pointer passes over it
}
I see two problems here:

1) Enabling/disabling the Password option doesn't immediately update the Edit box control. The control is not refreshed until the mouse is positioned over it. This can be remedied by re-writing something to the Edit control, as in this example.

2) The password mask character, which by default is a black circle or "bullet", becomes an asterisk once the Password option is manipulated by means of the GuiControl command. Check and uncheck the checkbox to see what happens to the Edit1 control. The workaround is to explicitly force the bullet character.

Thanks!
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: Edit box control password maks character becomes asterisk?

17 Dec 2016, 01:17

No. 2 appears to be intentional, but only because no fix was available at the time.
script_gui.cpp wrote:

Code: Select all

					// Don't know how to achieve the black circle on XP *after* the control has
					// been created.  Maybe it's impossible.  Thus, provide default since otherwise
					// pass-char will be removed vs. added:
					if (!aOpt.password_char)
						aOpt.password_char = '*';
					SendMessage(aControl.hwnd, EM_SETPASSWORDCHAR, (WPARAM)aOpt.password_char, 0);
AutoHotkey had no Unicode support at the time, and MSDN does not indicate what encoding the EM_SETPASSWORDCHAR message's parameter should have. Simply replacing aOpt.password_char with 9679 would not have worked.

Some recent experimentation revealed that the message expects ANSI if SendMessageA() is used and Unicode if SendMessageW() is used. So basically, it just needs to send the message with SendMessageW() and the bullet character, and it will work even on ANSI builds.

Your workaround relies on being able to include the bullet character in a string, which is impossible on ANSI builds. As an alternative, you can call SendMessageW via DllCall.

Although obviously Chris (the author of that code) was aware that XP did not use * by default, MSDN incorrectly says otherwise:
If an edit control is created with the ES_PASSWORD style, the default password character is set to an asterisk (*).
Source: EM_SETPASSWORDCHAR message (Windows)
Scoox wrote:Enabling/disabling the Password option doesn't immediately update the Edit box control. The control is not refreshed until the mouse is positioned over it.
This is another point where MSDN is apparently incorrect:
When an edit control receives the EM_SETPASSWORDCHAR message, the control redraws all visible characters using the character specified by the wParam parameter. If wParam is zero, the control redraws all visible characters using the characters typed by the user.
Source: EM_SETPASSWORDCHAR message (Windows)
If "When" was replaced with "At some time after", it would be correct.
User avatar
Scoox
Posts: 125
Joined: 11 May 2014, 09:12
Location: China

Re: Edit box control password maks character becomes asterisk?

17 Dec 2016, 07:00

Thank you Lexicos!

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 59 guests