Freak's tip updated for the latest PureBasic (v5.61):
Code: Select all
#Window_0 = 0
;- Gadget Constants
;
#Gadget_1 = 0
#original = 1
#start = 2
Procedure Open_Window_0()
If OpenWindow(#Window_0, 402, 160, 293, 79, "New window ( 0 )", #PB_Window_SystemMenu)
TextGadget(#Gadget_1, 10, 10, 100, 30, "Enter String and select a piece:")
StringGadget(#original, 110, 10, 170, 20, "this is a little test")
ButtonGadget(#start, 110, 40, 70, 20, "make bold")
EndIf
EndProcedure
Open_Window_0()
Repeat
Event = WaitWindowEvent()
If event = #PB_Event_Gadget And EventGadget() = #start
original.s = GetGadgetText(#original) ; get strings from Gadget
new.s = ""
; get selected position from #original Gadget
SendMessage_(GadgetID(#original), #EM_GETSEL, @startpos.l, @endpos.l)
new = Left(original, startpos) ; unselected part on the left
new + "<B>" ; bold mark
new + Mid(original, startpos+1, endpos-startpos) ; marked text
new + "</B>" ; unbold mark
new + Right(original, Len(original)-endpos) ; unselected part on the right
SetGadgetText(#original, new) ; set new text
; set selection again (3 characters right of original position, because we
; added the <b>
SendMessage_(GadgetID(#original), #EM_SETSEL, startpos+3, endpos+3)
SetActiveGadget(#original) ; activate Gadget again
EndIf
Until Event = #PB_Event_CloseWindow