Date: 02-16-2022
Return to Index
created by gbSnippets
'By default, a textbox highlights all text when it gets focus by using
'TAB, or simply when the textbox has focus at program startup.
'Many programmers want the text to be unselected on startup.
'Primary Code:
'Using POST ensures that the unselect message is sent to the end
'of the message queue. Using SEND can sometimes not work because
'of the sequence of messages that occur during startup.
Case %WM_INITDIALOG
PostMessage GetDlgItem(hDlg, 100), %EM_SETSEL, -1, 0
'Compilable Example: (Jose Includes)
#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,"I'm NOT selected!", 50,10,100,20, style&
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local hTextBox as DWord
Select Case CB.Msg
Case %WM_INITDIALOG
PostMessage GetDlgItem(hDlg, 100), %EM_SETSEL, -1, 0 'remove and textbox will be highlighted
End Select
End Function
'gbs_00135
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm