PureBasic Forum
http://forums.purebasic.com/english/

Custom SpinGadget() [Windows]
http://forums.purebasic.com/english/viewtopic.php?f=12&t=72264
Page 1 of 1

Author:  RASHAD [ Mon Feb 11, 2019 6:29 pm ]
Post subject:  Custom SpinGadget() [Windows]

- Using WinCallBack()
This is the best
Code:
Global max,min

Procedure WinCB(hWnd, uMsg, wParam, lParam)
  Result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_NOTIFY
      *updn.NM_UPDOWN = lParam
      status = Val(GetGadgetText(0))
      If status <= max
        If *updn\iDelta < 0
            status + 1
        Else
            status - 1
        EndIf
      EndIf     
      If status > max
        status = max
      EndIf
      If status < min
        status = min
      EndIf
      SetGadgetText(0,Str(status)) 

  EndSelect
  ProcedureReturn result
EndProcedure

max = 50
min = -50

LoadFont(0,"consolas",14)
OpenWindow(0, 100, 100, 400, 300, "SpinGadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ContainerGadget(1,10,10,84,32,#PB_Container_Flat)
  TextGadget(0,0,0,60,30,"",#SS_CENTER|#SS_CENTERIMAGE| #SS_NOTIFY)
  SetGadgetColor(0,#PB_Gadget_BackColor,$FFFFFF)
  SetGadgetColor(0,#PB_Gadget_FrontColor,$0000FF)
  SetGadgetFont(0,FontID(0))
  hSpin = CreateWindowEx_(0,"msctls_updown32","",#WS_CHILD| #WS_VISIBLE,64,0,40,30,GadgetID(1),1,GetModuleHandle_(0),0)
CloseGadgetList()
SetWindowCallback(@WinCB())
SetGadgetText(0, "0")
Repeat
    EventID.l = WaitWindowEvent()
    If EventID = #PB_Event_CloseWindow
        Quit = 1
    EndIf
Until Quit = 1
End


- Using SubClass
Code:
Global OldProc,hSpin

Procedure SpinSC(hWnd, uMsg, wParam, lParam)
  result = CallWindowProc_(OldProc, hWnd, uMsg, wParam, lParam)
  Select uMsg
    Case #WM_LBUTTONDOWN
        If lparam >> 16 > 10
          status = Val(GetGadgetText(0))
          If status > 0
            status - 1
            SetGadgetText(0, Str(status))
          EndIf
        Else
          status = Val(GetGadgetText(0))
          If status < 100
            status + 1
            SetGadgetText(0, Str(status))
          EndIf
        EndIf

  EndSelect
  ProcedureReturn result
EndProcedure

LoadFont(0,"consolas",14)
OpenWindow(0, 100, 100, 400, 300, "SpinGadget", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ContainerGadget(1,10,10,84,32,#PB_Container_Flat)
  TextGadget(0,0,0,60,30,"",#SS_CENTER|#SS_CENTERIMAGE| #SS_NOTIFY)
  SetGadgetColor(0,#PB_Gadget_FrontColor,$0000FF)
  SetGadgetFont(0,FontID(0))
  hSpin = CreateWindowEx_(0,"msctls_updown32","",#WS_CHILD| #WS_VISIBLE,64,0,40,30,GadgetID(1),1,GetModuleHandle_(0),0)
CloseGadgetList()
OldProc = SetWindowLongPtr_(hSpin, #GWL_WNDPROC, @SpinSC())
SetGadgetText(0, "50")
Repeat
    EventID.l = WaitWindowEvent()
    If EventID = #PB_Event_CloseWindow
        Quit = 1
    EndIf
Until Quit = 1
End

Author:  Kwai chang caine [ Wed Feb 13, 2019 10:36 am ]
Post subject:  Re: Custom SpinGadget() [Windows]

Nice !!! Both works :D
Thanks for sharing 8)

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/