Page 1 of 1

Force ES_PASSWORD style on Edit control

Posted: 11 Jul 2017, 22:22
by Sam_
I'm having trouble forcing an edit control to use the ES_PASSWORD (0x20) style. As a simple test I open a blank notepad window, type a few lines of gibberish, and run

Code: Select all

ControlGet, ControlHwnd, Hwnd, , Edit1, Untitled - Notepad
Control, Style, +0x20, , ahk_id %ControlHwnd%
But the control's contents are not obfuscated as I would expect. Forcing the window/control to be redrawn

Code: Select all

WinSet, Redraw, , Untitled - Notepad
WinMove, Untitled - Notepad, , 10, 10
WinHide, Untitled - Notepad
WinShow, Untitled - Notepad
doesn't seem to help either. Other styles (like ES_CENTER 0x1) work as expected. I feel like this should be super simple. What am I missing?

Re: Force ES_PASSWORD style on Edit control

Posted: 11 Jul 2017, 22:54
by Masonjar13
MSDN Edit Control Styles wrote:This style is valid only for single-line edit controls.
Edit Control Styles

Re: Force ES_PASSWORD style on Edit control

Posted: 12 Jul 2017, 12:33
by Sam_
Masonjar13 wrote:
MSDN Edit Control Styles wrote:This style is valid only for single-line edit controls.
Edit Control Styles
That possibility had occurred to me, but running

Code: Select all

Control, Style, -0x4, , ahk_id %ControlHwnd%	; Turn off ES_MULTILINE style
first doesn't help either. I've even tried playing around with Window Detective, but still can't get a 3rd-party Edit control to take on and apply the ES_PASSWORD style.

Re: Force ES_PASSWORD style on Edit control

Posted: 12 Jul 2017, 12:54
by Sam_
If notepad is complicating the issue, here is an example with AHK.
Using GuiControl works as expected:

Code: Select all

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
ControlGet, ControlHwnd, Hwnd, , Edit1, ahk_class AutoHotkeyGUI
;MsgBox % ControlHwnd
Return

Show()
{
	Global
	Gui, Submit, NoHide
	If Checkbox1
		{
		GuiControl, -Password, Edit1
		;Control, Style, -0x20, , ahk_id %ControlHwnd%
		}
	Else
		{
		GuiControl, +Password, Edit1
		;Control, Style, +0x20, , ahk_id %ControlHwnd%
		}
}
but Control does not:

Code: Select all

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
ControlGet, ControlHwnd, Hwnd, , Edit1, ahk_class AutoHotkeyGUI
;MsgBox % ControlHwnd
Return

Show()
{
	Global
	Gui, Submit, NoHide
	If Checkbox1
		{
		;GuiControl, -Password, Edit1
		Control, Style, -0x20, , ahk_id %ControlHwnd%
		}
	Else
		{
		;GuiControl, +Password, Edit1
		Control, Style, +0x20, , ahk_id %ControlHwnd%
		}
}
What am I missing here?