It is currently Sun Dec 15, 2019 12:34 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Custom SpinGadget() [Windows]
PostPosted: Mon Feb 11, 2019 6:29 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3480
- 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

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Custom SpinGadget() [Windows]
PostPosted: Wed Feb 13, 2019 10:36 am 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4548
Location: Lyon - France
Nice !!! Both works :D
Thanks for sharing 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye