[comp.windows.ms] no-echo input

matts@microsoft.UUCP (Matt SAETTLER) (05/29/90)

In article <102@bohra.cpg.oz> ejp@bohra.cpg.oz.au (Esmond Pitt) writes:
]I asked this a while ago but apparently it didn't get transmitted upstream.
]
]Is it possible to accept input without echo (e.g. password fields) under:
]
]	(1) MS-Windows
]	(2) PM
]
]and if so, how?
]
]Thanks for your help.

Windows 3.0 defines the edit control attribute ES_PASSWORD.  I believe
that this replace typed characters with '*' in the display.

-----------------------------------------------------------------------
	Matt Saettler			I speak for myself, or so I'm told.

williams@umaxc.weeg.uiowa.edu (Kent Williams) (05/30/90)

In article <102@bohra.cpg.oz> ejp@bohra.cpg.oz.au (Esmond Pitt) writes:
>I asked this a while ago but apparently it didn't get transmitted upstream.
>
>Is it possible to accept input without echo (e.g. password fields) under:
>
>	(1) MS-Windows
>	(2) PM
>
>and if so, how?
>
I know <0 about programming for (1) or (2), but if you don't have a no-echo
option on input, you can set the foreground and background colors the same.
This is a trick I started using on CP/M 80 machines!




--
Kent Williams                    'Look, I can understand "teenage mutant ninja 
williams@umaxc.weeg.uiowa.edu    turtles", but I can't understand "mutually 
williams@herky.cs.uiowa.edu      recursive inline functions".' - Paul Chisholm

gpsteffler@tiger.uwaterloo.ca (Glenn Steffler) (05/31/90)

In article <102@bohra.cpg.oz> ejp@bohra.cpg.oz.au (Esmond Pitt) writes:
>I asked this a while ago but apparently it didn't get transmitted upstream.
>
>Is it possible to accept input without echo (e.g. password fields) under:
>
>	(1) MS-Windows
>	(2) PM
>
>and if so, how?
I can give you a hint for Windows:

An easy way to get no-echo input is to capture the edit control message that
informs you of a new key press.  Simply acknowledge the key stroke, but 
replace it with an 'x' or whatever...

I don't have the SDK in front of me, but I believe the EN_ messages notify
the program of any edit control changes.  Just use a SetWindowText() command
to set the text to all 'x's (for the number of char's entered).

----
Co-Op Scum

rommel@lan.informatik.tu-muenchen.dbp.de (Kai-Uwe Rommel) (05/31/90)

>In article <102@bohra.cpg.oz> ejp@bohra.cpg.oz.au (Esmond Pitt) writes:
>>I asked this a while ago but apparently it didn't get transmitted upstream.
>>
>>Is it possible to accept input without echo (e.g. password fields) under:
>>
>>	(1) MS-Windows
>>	(2) PM
>>
>>and if so, how?
>I can give you a hint for Windows:

Under MS Windows I needed a password field with NO echo at all and used
window subclassing for it and it works fine. Change the callback
function for the edit control in the WM_INITDIALOG message and replace
it by your own which handles WM_CHAR itself and passes other messages to
the previous one (you have to remember the address of the original
callback function). The GetWindowLong() and SetWindowLong() calls are
used to replace the callback function's address and get the old one.
There is also a symbolic constant (don't heve it in mind) for the
parameter to these two calls for the callback function.

This should be possible for PM too, but I did not yet need it and
therefore did not try it but the MS-Windows solution works fine.

In the WM_CHAR message you can either replace the character by '*' or
'x' or whatever you want, remember the ortiginal character and pass the
'*' etc. to the original callback function or simply catch the WM_CHAR
and the edit control will stay empty all the time.

Kai Uwe Rommel
Munich
rommel@lan.informatik.tu-muenchen.dbp.de

paul@cscnj.UUCP (Paul Moody) (06/01/90)

 >In article <102@bohra.cpg.oz> ejp@bohra.cpg.oz.au (Esmond Pitt) writes:
 >>I asked this a while ago but apparently it didn't get transmitted upstream.
 >>
 >>Is it possible to accept input without echo (e.g. password fields) under:
 >>
 >>	(1) MS-Windows

Here is a simple code fragment for windows 2.x. As has been stated
3.0 includes ES_PASSWORD for this function.

In the NORMAL dialog function for the dialog where the password
is requested, add the following entry:

	case WM_CTLCOLOR:	
		if(HIWORD(lParam) == CTLCOLOR_EDIT) /* an edits color */
		{
			HWND	hEdit = GetDlgItem(hDlg, MYPASSWORDEDIT);
			if(LOWORD(lParam) == hEdit) 
			{
				wReturnCode = (WORD)GetStockObject(WHITE_BRUSH);
				SetTextColor(wParam, RGB(255, 255, 255));
				return wReturnCode;
			}
		}
		break;

Note: you MUST return an hBrush if you process the WM_CTLCOLOR message.
This brush is used for the background of the control. Dont call 
UnrealizeObject for stock objects.



-- 
Paul Moody			UUCP: rutgers!cscnj!paul 
Computer Sciences Corporation
# the opinions expressed are entirely imaginary			#

dave@motto.UUCP (David Brown) (06/04/90)

In article <102@bohra.cpg.oz> ejp@bohra.cpg.oz.au (Esmond Pitt) writes:
>I asked this a while ago but apparently it didn't get transmitted upstream.
>
>Is it possible to accept input without echo (e.g. password fields) under:
>
>	(1) MS-Windows
>	(2) PM
>
>and if so, how?

I asked Microsoft this question for Presentation Manager a while ago, and
received the following response:

    Under OS/2 version 1.2 the edit control now has a new class style. 
    It is ES_UNREADABLE and causes all input characters to be echoed to
    the screen as asterisks, i.e. '*'.  This was obviously designed for
    password fields.

I am still waiting for my copy of 1.2, so I haven't tried this yet.

---
David C. Brown		|  uunet!mnetor!motto!dave
Motorola Canada, Ltd.	|  416-499-1441 ext 3708
Communications Division	|  "Of course I'm above average!  Who isn't?"

gords@cognos.UUCP (Gord Smith) (06/07/90)

In article <1129@cscnj.UUCP> paul@cscnj.UUCP (Paul Moody) writes:
> >In article <102@bohra.cpg.oz> ejp@bohra.cpg.oz.au (Esmond Pitt) writes:
> >>I asked this a while ago but apparently it didn't get transmitted upstream.
> >>Is it possible to accept input without echo (e.g. password fields) under:
> >>    (1) MS-Windows
>In the NORMAL dialog function for the dialog where the password
>is requested, add the following entry:

This was a great tip (Thanks!), but (pet peeve flame on):

WHY, oh why, oh why do programmers (and people who write how-to-program-Windows
books) always seem to assume that the background is white and that text is
black?  These types of programs look really silly if the user has selected
different colors in the control panel (e.g. I've got dark blue on light blue).

Here's my modified version of the code which takes into account the user's
color setup:

In the WM_INITDIALOG message, add the line:

BkBrush = (WORD)CreateSolidBrush(GetSysColor(COLOR_WINDOW));

Add the following case:

    case WM_CTLCOLOR:    
        if(HIWORD(lParam) == CTLCOLOR_EDIT &&
                GetDlgItem(hDlg, MYPASSWORDEDIT) == LOWORD(lParam)) 
        {
            SetBkColor(wParam, GetSysColor(COLOR_WINDOW));
            SetTextColor(wParam, GetSysColor(COLOR_WINDOW));
            return BkBrush;
        }
        break;

In the WM_DESTROY message for the dialog box add the line:

DeleteObject(BkBrush);

We use a global brush that we have around for the background color, so I don't
need to create or nuke it everytime the dialog is run.

-- 
D. Gordon Smith         Voice: (613) 738-1338 ext 6118       P.O. Box 9707
Cognos Incorporated       FAX: (613) 738-0002                3755 Riverside Dr.
uucp: gords@cognos.uucp || uunet!mitel!sce!cognos!gords      Ottawa, Ontario
"Nothing ventured, nothing capital gained!"                  CANADA  K1G 3Z4

michaelt@microsoft.UUCP (Michael THURLKILL) (06/11/90)

In article <134@motto.UUCP> dave@motto.UUCP (David Brown) writes:
>In article <102@bohra.cpg.oz> ejp@bohra.cpg.oz.au (Esmond Pitt) writes:
>>I asked this a while ago but apparently it didn't get transmitted upstream.
>>
>>Is it possible to accept input without echo (e.g. password fields) under:
>>
>>	(1) MS-Windows
>>	(2) PM
>>
>>and if so, how?
>
You could always do this by sub-classing the edit control. (You would
trap WM_CHAR messages, save the characters in your own buffer, and pass
an asterisk, space or other character to the original wndproc.)

Windows 3 has a new edit control style, ES_PASSWORD, that makes this all
very easy. By default an asterisk will be displayed, rather than the 
character typed. You can change the character displayed by sending the
control the EM_SETPASSWORDCHAR message.

As noted in a previous posting, a similar mechanism is provided in 
OS/2 1.2.

Mike Thurlkill

Disclaimer: These are my opinions. They should be in no way misconstrued
as being correct or in any way related to my employer.