Solved

Dynamically changing an edit control to/from password mode

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

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: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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 we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

623 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