Solved

Dynamically changing an edit control to/from password mode

Posted on 1998-04-08
4
510 Views
Last Modified: 2013-11-20
How can I dynamically change an edit control in my dialog box to and from password mode (ES_PASSWORD style set)? At first glance it seems easy, use ModifyStyle. But that does not work. Nor does using GetWindowLong and SetWindowLong. The style gets set, but the edit control remains unchanged (ie does not display as a password if the ES_PASSWORD style was not set at creation).

Kevin Lussier
klussier@redcreek.com
0
Comment
Question by:klussier
4 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1317553
Certain styles cannot be changed dynamically. In this case, you will have to create two controls, one that is a password and the other not. Then you can switch between them by making sure the text in both is the same and hiding one and showing the other (ShowWindow(WS_VISIBLE)).
0
 

Expert Comment

by:dipesh042997
ID: 1317554
I think whenever you want to have a input in password form, Call SetPasswordChar('*') function of CEdit class and when you want it in normal mode call SetPasswordchar() function without any paramemter or with zero. So it will show all input as it is entered.
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1317555
thui's answer would work, but isn't a good solution. dipesh's answer is the way to go--you should ask him to resubmit it so you can give him the points he deserves.

.B ekiM

0
 

Accepted Solution

by:
directG earned 100 total points
ID: 1317556
A password control simply substitutes asterisks in place of chars. Thus, I think that if you don't want to use two controls (see thui) you could use a simple edit control (without ES_PASSWORD style) and write a routine that displays asterisks in place of normal chars. Doing so you cannot edit text in password mode, however. If you don't care, you can set the readonly style when switching from normal to password mode.
Alternatively, i think the only thing you can do, is to subclass CEdit and derive a class CTextPwdEdit that intercept keystrokes and display asterisks. I think that it doesn't worth the effort, however. Think about it: the solution proposed by thui is, i think, the most general even if appears artificial at a first glance.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
not able to insert into temp table 68 169
Process filename extension 3 196
ASCII Non-Printable characters/codes and their HTML equivalents 6 132
format the code in java 6 102
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question