string gadget and focus setting

Windows specific forum
chippy73
User
User
Posts: 59
Joined: Wed Feb 16, 2005 6:11 pm
Location: S.W.Wales

string gadget and focus setting

Post by chippy73 »

I am putting say, 5 lines of text under program control to a string gadget.

Fine it displays the 5 lines of text.

I set ActivateGadget but the cursor is at the beginning of the text on the first line.

How do I get it to appear say at the end of the text so that I can enter text manually from the keyboard?

My lines of code:-

Code: Select all

SetGadgetText(#Gadget_Form1_Editortx,textin1$)
         ActivateGadget(#Gadget_Form1_Editortx)
I think maybe SendMessage might be a clue but not sure.

Any help welcomed.

Alan
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Try this one...

Code: Select all

#Window_Main = 0 
#Gadget_Form1_Editortx = 0 
Procedure ActivateToEnd(gadID)
  ActivateGadget(gadID)
  stringLen = Len(GetGadgetText(gadID))
  SendMessage_(GadgetID(gadID), #EM_SETSEL, stringLen, stringLen)
EndProcedure

If OpenWindow(#Window_Main, 0 ,0, 300, 200, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "StringGadget") And CreateGadgetList(WindowID(0)) 
  StringGadget(#Gadget_Form1_Editortx, 10, 10, 280, 180, "", #PB_String_MultiLine) 
  For l = 0 To 4
    t$ + "Line " + Str(l) + Chr(13) + Chr(10)
    SetGadgetText(#Gadget_Form1_Editortx, t$)
  Next l
  AddKeyboardShortcut(#Window_Main, #PB_Shortcut_Control | #PB_Shortcut_R, 1) 
  ; --> call procedure to set caret to end of StringGadget
  ActivateToEnd(#Gadget_Form1_Editortx)
  Repeat 
    event = WaitWindowEvent() 
    If event = #PB_EventMenu And EventMenuID() = 1 
      txstring$ = GetGadgetText(#Gadget_Form1_Editortx) 
      SetGadgetText(#Gadget_Form1_Editortx, txstring$ + Chr(18)) 
    EndIf 
  Until event = #PB_Event_CloseWindow 
EndIf 
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
chippy73
User
User
Posts: 59
Joined: Wed Feb 16, 2005 6:11 pm
Location: S.W.Wales

Post by chippy73 »

Sparkie,

Many thanks for the solution. It works fine. It's knowing that #EM_SETSEL existed ! I knew there had to be a command somewhere to do it.

Thanks again.

Alan
Post Reply