Page 1 of 1

Get / set cursor position in SpinGadget

Posted: Mon Jun 15, 2020 2:59 pm
by paulr
Is it possible to get and set the cursor position in a SpinGadget? I've only seen examples for a StringGadget so far, and they don't seem applicable.

Re: Get / set cursor position in SpinGadget

Posted: Mon Jun 15, 2020 3:07 pm
by RASHAD
If you are using Windows I maybe able to do it

Re: Get / set cursor position in SpinGadget

Posted: Mon Jun 15, 2020 3:20 pm
by paulr
I am.

Re: Get / set cursor position in SpinGadget

Posted: Mon Jun 15, 2020 3:27 pm
by RASHAD
OK :P

Code: Select all

Procedure setCaretPos(gadID,Pos)
  SendMessage_(gadID, #EM_SETSEL,Pos,Pos)
EndProcedure

If OpenWindow(0, 0, 0, 400, 300, "SpinGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  SpinGadget     (0, 10, 10, 80, 25, 0, 100,#PB_Spin_Numeric )
  eHwnd = GetWindow_(GadgetID(0),#GW_HWNDFIRST)
  SetGadgetState(0,100)
  
  ButtonGadget(1,10,260,100,25,"Set Caret")

  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Quit = 1
     
      Case #WM_LBUTTONDOWN
        If GetActiveGadget() = 0
          GetCaretPos_(p.POINT)
          Pos = SendMessage_(eHwnd,#EM_CHARFROMPOS,0,p\y<<16+p\x)
          Debug pos
        EndIf
       
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            GetCaretPos_(p.POINT)
            Pos = SendMessage_(eHwnd,#EM_CHARFROMPOS,0,p\y<<16+p\x)
            Debug pos
            
          Case 1
            SetActiveGadget(0)
            setCaretPos(eHwnd,2)
            
        EndSelect
    EndSelect
  Until Quit = 1

EndIf

Re: Get / set cursor position in SpinGadget

Posted: Tue Jun 16, 2020 11:11 am
by paulr
That's great, thank you very much!