• Welcome to PlanetSquires Forums.
 

Change textbox at creation

Started by BudDurland, August 07, 2008, 11:21:05 AM

Previous topic - Next topic

BudDurland

Depending on an the user option value passed to FORMNAME_SHOW, I'd like to be able to set the %ES_PASSWORD attribute of a text box.  Is that possible?

TechSupport

Hi Bud,

Yes, that is possible. You can change the style at runtime but you also need to change/set the password character when you do that. Check out the sample code below:




Function AddStyleToControl (hCtrl As Long, StyletoAdd As Long) As Long
  SetWindowLong hCtrl, %GWL_STYLE, (GetWindowLong (hCtrl,%GWL_STYLE) Or StyleToAdd)
End Function

Function RemoveStyleFromControl (hCtrl As Long, StyletoRemove As Long) As Long
  SetWindowLong hCtrl, %GWL_STYLE, (GetWindowLong (hCtrl,%GWL_STYLE) And (Not StyleToRemove))
End Function


'--------------------------------------------------------------------------------
Function FORM1_COMMAND1_BN_CLICKED ( _
                                   ControlIndex     As Long,  _  ' index in Control Array
                                   hWndForm         As Dword, _  ' handle of Form
                                   hWndControl      As Dword, _  ' handle of Control
                                   idButtonControl  As Long   _  ' identifier of button
                                   ) As Long
   
   AddStyleToControl HWND_FORM1_TEXT1, %ES_PASSWORD
   
   ' 42 is the ascii value for asterisk "*"
   SendMessage HWND_FORM1_TEXT1, %EM_SETPASSWORDCHAR, 42, 0
   FF_Control_Redraw HWND_FORM1_TEXT1
   
End Function


'--------------------------------------------------------------------------------
Function FORM1_COMMAND2_BN_CLICKED ( _
                                   ControlIndex     As Long,  _  ' index in Control Array
                                   hWndForm         As Dword, _  ' handle of Form
                                   hWndControl      As Dword, _  ' handle of Control
                                   idButtonControl  As Long   _  ' identifier of button
                                   ) As Long

   RemoveStyleFromControl HWND_FORM1_TEXT1, %ES_PASSWORD

   ' Remove the password character as well by setting it to null
   SendMessage HWND_FORM1_TEXT1, %EM_SETPASSWORDCHAR, 0, 0
   FF_Control_Redraw HWND_FORM1_TEXT1

End Function


BudDurland