Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CEdit question (should be easy)

CEdit question (should be easy)

Scheduled Pinned Locked Moved C / C++ / MFC
questiondebugging
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RobJones
    wrote on last edited by
    #1

    Hey, I have no idea why this isn't working but I am trying to simply toggle between ES_PASSWORD on a edit control with in a dialog. I have tried Get/SetWindowLong and ModifyStyle and neither seem to work... Here is a sniplet of my code. What am I doing wrong?

    void CActivationDlg::OnBnClickedCMask()
    {
    	UpdateData(TRUE);
    
    	m_bMask = m_bMask ? TRUE : FALSE;
    
    	DWORD dwStyle = GetWindowLong(m_cKey.GetSafeHwnd(), GWL_STYLE);
    
    	if(!m_bMask) // Remove password mask
    	{
    		TRACE("Remove PW mask\n");
    		
    		dwStyle &= ~ES_PASSWORD;
    		SetWindowLong(m_cKey.GetSafeHwnd(),
    						GWL_STYLE,
    						dwStyle);
    	}
    	else		// Add password mask
    	{
    		TRACE("Add PW mask\n");
    
    		dwStyle |= ES_PASSWORD;
    		SetWindowLong(m_cKey.GetSafeHwnd(),
    						GWL_STYLE,
    						dwStyle);
    	}
    
    	m_cKey.Invalidate();
    	
    	UpdateData(FALSE);
    }
    

    Thanks in advance! Rob Whoever said nothing's impossible never tried slamming a revolving door!

    D D 2 Replies Last reply
    0
    • R RobJones

      Hey, I have no idea why this isn't working but I am trying to simply toggle between ES_PASSWORD on a edit control with in a dialog. I have tried Get/SetWindowLong and ModifyStyle and neither seem to work... Here is a sniplet of my code. What am I doing wrong?

      void CActivationDlg::OnBnClickedCMask()
      {
      	UpdateData(TRUE);
      
      	m_bMask = m_bMask ? TRUE : FALSE;
      
      	DWORD dwStyle = GetWindowLong(m_cKey.GetSafeHwnd(), GWL_STYLE);
      
      	if(!m_bMask) // Remove password mask
      	{
      		TRACE("Remove PW mask\n");
      		
      		dwStyle &= ~ES_PASSWORD;
      		SetWindowLong(m_cKey.GetSafeHwnd(),
      						GWL_STYLE,
      						dwStyle);
      	}
      	else		// Add password mask
      	{
      		TRACE("Add PW mask\n");
      
      		dwStyle |= ES_PASSWORD;
      		SetWindowLong(m_cKey.GetSafeHwnd(),
      						GWL_STYLE,
      						dwStyle);
      	}
      
      	m_cKey.Invalidate();
      	
      	UpdateData(FALSE);
      }
      

      Thanks in advance! Rob Whoever said nothing's impossible never tried slamming a revolving door!

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Are you sure the ES_PASSWORD style can be un/set at runtime? Some styles are unchangeable.


      "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

      "There is no death, only a change of worlds." - Native American Proverb

      R 1 Reply Last reply
      0
      • D David Crow

        Are you sure the ES_PASSWORD style can be un/set at runtime? Some styles are unchangeable.


        "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

        "There is no death, only a change of worlds." - Native American Proverb

        R Offline
        R Offline
        RobJones
        wrote on last edited by
        #3

        You might be right... I did notice on MSDN that some of the other styles state if changes need to be made after creation use the SetWindowLong function, unfortunately it doesn't say anything about ES_PASSWORD, it probably can't be changed with ease... DOH! Thanks, Rob Whoever said nothing's impossible never tried slamming a revolving door!

        D 1 Reply Last reply
        0
        • R RobJones

          You might be right... I did notice on MSDN that some of the other styles state if changes need to be made after creation use the SetWindowLong function, unfortunately it doesn't say anything about ES_PASSWORD, it probably can't be changed with ease... DOH! Thanks, Rob Whoever said nothing's impossible never tried slamming a revolving door!

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Would it be feasible to create two of the same controls, one with the style and one without? Then at runtime you could just show/hide the appropriate control.


          "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

          "There is no death, only a change of worlds." - Native American Proverb

          R 1 Reply Last reply
          0
          • D David Crow

            Would it be feasible to create two of the same controls, one with the style and one without? Then at runtime you could just show/hide the appropriate control.


            "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

            "There is no death, only a change of worlds." - Native American Proverb

            R Offline
            R Offline
            RobJones
            wrote on last edited by
            #5

            Yeah I could have just done that... Instead I have removed the old control and created a new one. If anyone is interested this is the code. Most of this code is from the SuperPad MSDN example for changing word wrap...

            void CActivationDlg::OnBnClickedCMask()
            {
            	UpdateData(TRUE);
            
            	m_bMask = m_bMask ? TRUE : FALSE;
            
            	// preserve original control's state.
            	CFont* pFont = m_cKey.GetFont();
            	int nLen = m_strKey.GetLength();
            	TCHAR* pSaveText = new TCHAR[m_strKey.GetLength()+1];
            	GetWindowText(pSaveText, nLen+1);
            
            	DWORD dwStyle = GetWindowLong(m_cKey.GetSafeHwnd(), GWL_STYLE);
            
            	if(!m_bMask) // Remove password mask
            		dwStyle &= ~ES_PASSWORD;
            	else		// Add password mask
                    dwStyle |= ES_PASSWORD;
            
            	// create new edit control with appropriate style and size.
            	CActivationDlg* pParent = (CActivationDlg*)m_cKey.GetParent();
            	
            	CRect rect;
            	m_cKey.GetWindowRect(rect);
            	pParent->ScreenToClient(rect);
            
            	UINT nID = m_cKey.GetDlgCtrlID();
            
            	HWND hWnd = ::CreateWindowEx(WS_EX_CLIENTEDGE, _T("edit"), NULL, dwStyle,
            		rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
            		pParent->m_hWnd, (HMENU)nID, AfxGetInstanceHandle(), NULL);
            
            	if (hWnd == NULL)
            	{
            		delete[] pSaveText;
            		return;
            	}
            
            	// set the window text to nothing to make sure following set doesn't fail
            	m_cKey.SetWindowText(NULL);
            
            	// restore visual state
            	::SetWindowText(hWnd, pSaveText);
            	delete[] pSaveText;
            	if (pFont != NULL)
            	{
            		ASSERT(pFont->m_hObject != NULL);
            		::SendMessage(hWnd, WM_SETFONT, (WPARAM)pFont->m_hObject, 0);
            	}
            
            	// detach old window, attach new
            	SetDlgCtrlID(nID+1);
            	HWND hWndOld = m_cKey.Detach();
            	::SetWindowLong(hWndOld, GWL_WNDPROC, (LONG)*GetSuperWndProcAddr());
            	ASSERT(m_cKey.m_hWnd == NULL);
            	m_cKey.SubclassWindow(hWnd);
            	ASSERT(m_cKey.m_hWnd == hWnd);
            
            	UINT nTabStops = 7;
            	m_cKey.SetTabStops(nTabStops);
            
            	m_cKey.GetClientRect(&rect);
            	m_cKey.SetWindowPos(NULL, 0, 0, 0, 0,
            		SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_SHOWWINDOW);
            	
            	m_cKey.UpdateWindow();
            
            	// destroy old
            	::SetWindowPos(hWndOld, NULL, 0, 0, 0, 0,
            		SWP_HIDEWINDOW|SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|
            		SWP_NOZORDER);
            	::DestroyWindow(hWndOld);
            
            	UpdateData(FALSE);
            }
            

            Whoever said nothing's impossible never tried slamming a revolving door! -- modified at 6:45 Wednesday 1st March, 2006

            1 Reply Last reply
            0
            • R RobJones

              Hey, I have no idea why this isn't working but I am trying to simply toggle between ES_PASSWORD on a edit control with in a dialog. I have tried Get/SetWindowLong and ModifyStyle and neither seem to work... Here is a sniplet of my code. What am I doing wrong?

              void CActivationDlg::OnBnClickedCMask()
              {
              	UpdateData(TRUE);
              
              	m_bMask = m_bMask ? TRUE : FALSE;
              
              	DWORD dwStyle = GetWindowLong(m_cKey.GetSafeHwnd(), GWL_STYLE);
              
              	if(!m_bMask) // Remove password mask
              	{
              		TRACE("Remove PW mask\n");
              		
              		dwStyle &= ~ES_PASSWORD;
              		SetWindowLong(m_cKey.GetSafeHwnd(),
              						GWL_STYLE,
              						dwStyle);
              	}
              	else		// Add password mask
              	{
              		TRACE("Add PW mask\n");
              
              		dwStyle |= ES_PASSWORD;
              		SetWindowLong(m_cKey.GetSafeHwnd(),
              						GWL_STYLE,
              						dwStyle);
              	}
              
              	m_cKey.Invalidate();
              	
              	UpdateData(FALSE);
              }
              

              Thanks in advance! Rob Whoever said nothing's impossible never tried slamming a revolving door!

              D Offline
              D Offline
              Dan McCormick
              wrote on last edited by
              #6

              <rant> ES_PASSWORD - totally useless, don't know why it exists. </rant> I had this same problem until I found (after much digging) the easy way. Check out: CEdit::SetPasswordChar[^] From the documentation: Parameters ch Specifies the character to be displayed in place of the character typed by the user. If ch is 0, the actual characters typed by the user are displayed. Apparently if an Edit control has ES_PASSWORD set when it is created (or subclassed or... lordy, who knows exactly when), MFC calls SetPasswordChar() with a value of '*'. ES_PASSWORD does not seem to be a true window style attribute, but can the documentation point that out in an obvious manner? Nooooo! :mad: Anyway, see if that won't give you a cleaner solution. It's working well for us in our shop. Just remember... Offer void where prohibited. Your mileage may vary. Later, Dan Remember kids, we're trained professionals.
              Don't try this at home!

              R 2 Replies Last reply
              0
              • D Dan McCormick

                <rant> ES_PASSWORD - totally useless, don't know why it exists. </rant> I had this same problem until I found (after much digging) the easy way. Check out: CEdit::SetPasswordChar[^] From the documentation: Parameters ch Specifies the character to be displayed in place of the character typed by the user. If ch is 0, the actual characters typed by the user are displayed. Apparently if an Edit control has ES_PASSWORD set when it is created (or subclassed or... lordy, who knows exactly when), MFC calls SetPasswordChar() with a value of '*'. ES_PASSWORD does not seem to be a true window style attribute, but can the documentation point that out in an obvious manner? Nooooo! :mad: Anyway, see if that won't give you a cleaner solution. It's working well for us in our shop. Just remember... Offer void where prohibited. Your mileage may vary. Later, Dan Remember kids, we're trained professionals.
                Don't try this at home!

                R Offline
                R Offline
                RobJones
                wrote on last edited by
                #7

                WOW! :-) Thanks, I'll give that a shot when I get into work. Rob Whoever said nothing's impossible never tried slamming a revolving door!

                1 Reply Last reply
                0
                • D Dan McCormick

                  <rant> ES_PASSWORD - totally useless, don't know why it exists. </rant> I had this same problem until I found (after much digging) the easy way. Check out: CEdit::SetPasswordChar[^] From the documentation: Parameters ch Specifies the character to be displayed in place of the character typed by the user. If ch is 0, the actual characters typed by the user are displayed. Apparently if an Edit control has ES_PASSWORD set when it is created (or subclassed or... lordy, who knows exactly when), MFC calls SetPasswordChar() with a value of '*'. ES_PASSWORD does not seem to be a true window style attribute, but can the documentation point that out in an obvious manner? Nooooo! :mad: Anyway, see if that won't give you a cleaner solution. It's working well for us in our shop. Just remember... Offer void where prohibited. Your mileage may vary. Later, Dan Remember kids, we're trained professionals.
                  Don't try this at home!

                  R Offline
                  R Offline
                  RobJones
                  wrote on last edited by
                  #8

                  Worked like a charm!!! Thanks, that is much cleaner! Rob Whoever said nothing's impossible never tried slamming a revolving door!

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups