Get / set cursor position in SpinGadget

Just starting out? Need help? Post your questions and find answers here.
paulr
User
User
Posts: 70
Joined: Sat Sep 27, 2003 2:53 pm

Get / set cursor position in SpinGadget

Post 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.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Get / set cursor position in SpinGadget

Post by RASHAD »

If you are using Windows I maybe able to do it
Egypt my love
paulr
User
User
Posts: 70
Joined: Sat Sep 27, 2003 2:53 pm

Re: Get / set cursor position in SpinGadget

Post by paulr »

I am.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Get / set cursor position in SpinGadget

Post 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
Egypt my love
paulr
User
User
Posts: 70
Joined: Sat Sep 27, 2003 2:53 pm

Re: Get / set cursor position in SpinGadget

Post by paulr »

That's great, thank you very much!
Post Reply