Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dynamically changing an edit control to/from password mode

Posted on 1998-04-08
4
Medium Priority
?
530 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

704 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