Solved

Dynamically changing an edit control to/from password mode

Posted on 1998-04-08
4
503 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macro to save highlighted rows as a separate file 5 43
conditional code and condition difference 9 82
Doc'in system (example?) BA 7 110
FizzBuzz challenge 9 81
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

778 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