Date: 02-16-2022
Return to Index
created by gbSnippets
'It's sometimes useful to have a textbox highlight the text when the control
'receives focus. The default action of a textbox is to highlight all text if it
'gets focus after TABing, but not if a control gains focus by being clicked on
'by the mouse.
'Both methods (Send or Post) will work
Control Send hDlg, %ID_TextBox, %EM_SetSel, 0, -1
Control Post CB.Hndl, CB.Ctl, %EM_SETSEL, 0, -1
'Compilable Example: (Jose Includes)
'Uses the %EM_SetSel to select all text in the textbox, when selected by TABing or by mouse
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
Global hDlg As Dword
Function PBMain() As Long
Local style&
style& = %WS_TabStop Or %WS_Border Or %ES_Left Or %ES_AutoHScroll Or %ES_MultiLine Or %ES_NoHideSel Or %ES_WantReturn
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add TextBox, hDlg, 100,"Light me up!", 10,10,100,20, style&
Control Add TextBox, hDlg, 200,"No, me first!!", 10,40,100,20, style&
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_Command
Select Case CB.Ctlmsg
Case %EN_SetFocus
Select Case CB.Ctl
Case 100,200
Control Post CB.Hndl, CB.Ctl, %EM_SETSEL, 0, -1
End Select
End Select
End Select
End Function
'gbs_00280
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm