selecting text field text

BlitzPlus Forums/BlitzPlus Programming/selecting text field text

Is there a way to select text field text so that the text is automatically highlighted? Such as maybe HighlightTextFieldText(txtfield,offset,characters), where txtfield is the textfield gadget handle, offset is the position to start, and characters is the amount of characters to highlight from the offset. Any help would be appreciated.

Here you go ...

; Highlight Text in edit control

; userlibs
; ************************
; .lib "user32.dll"
; SendMessage%(hwnd,msg,wParam,mParam):"SendMessageA"
; ************************

win = CreateWindow("Highlight TextField text",176,193,244,123,Desktop(),16+1)
tf  = CreateTextField(20,20,200,20,win,0)
bt  = CreateButton("Highlight text",70,60,100,22,win)
SetGadgetText tf,"Hello World"


Repeat
	ev=WaitEvent()
	Select ev
		Case $803 ; close [X]
			Exit
		Case $401 ;gadgethit
			If EventSource()=bt HighlightTextFieldText tf
	End Select
Forever

End


; highlight characters in an 'edit control'
Function HighlightTextFieldText(gad,offs=0,numchars=-1)
	Local EM_SETSEL=$b1
	ActivateGadget gad
	SendMessage QueryObject(gad,1),EM_SETSEL,offs,numchars+offs
End Function


NOTE:
Using the HighlightTextFieldText() without the offset and numchars parameters will highlight all text in the field.

Thanks a lot, that really helped!

[Edit] 100th post!