Solved

Dynamically changing an edit control to/from password mode

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

706 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now