UpDownGadget New Function

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

UpDownGadget New Function

Post by BackupUser »

Code updated for 5.20+

Restored from previous forum. Originally posted by Keith.

Hi,

I've just created a UpDown Gadget because the SpinGadget() dosent look 100%
like the ones you see in windows allthought it is the real thing. but the one
I've created looks like the ones you see in applications made in VB, C++,
Delphi etc. Heres the code its a Procedure because I dont know any C or ASM so
I cant make a library.

Code: Select all

Procedure UpDownGadget(ID, Window, X,Y,W,Val,Min,Max)
  StringGadget(ID,X,Y,W,20,"")
  Buddy=StringGadget(ID+1,X+2,Y+2,W-22,16,Str(Val),#PB_String_BorderLess | #PB_String_Numeric)
  DisableGadget(ID,1)
  CreateUpDownControl_(#WS_CHILD | #WS_VISIBLE | #UDS_SETBUDDYINT | #UDS_ARROWKEYS, X+W-19, Y+2, 15, 16, WindowID(Window), 1, 0, Buddy, Max, Min, Val)
EndProcedure
Thanks
Keith
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Rings.

very nice keith.go on with more such usefull stuff.
thx for sharing with us

Its a long way to the top if you wanna .....CodeGuru
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Yes, really nice code-snip example... :wink:

PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Some weeks ago somebody in the german forum
asked how to use the UpDownControl for a
reboot-window and i came up with this little
example:

Code: Select all

; Example
#UPDOWN = #WS_CHILD | #WS_VISIBLE 
If OpenWindow(0,100,100,200,45, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget,"Test") 
  If CreateGadgetList(WindowID()) 
    shwn = TextGadget(1,20,13,145,120,"Shutdown PC after 01 minute") 
    uhwn = CreateUpDownControl_(#UPDOWN,175,10,10,20,WindowID(),1,GetModuleHandle_(#NULL),shwn,0,0,1) 
  EndIf 
EndIf 
; 
; Constants
; 
#UDM_SETRANGE32 = $400+111 
#UDM_GETPOS32   = $400+114 
; 
; Set Minimum und Maximum ( 1 - 60 ) 
; 
SendMessage_(uhwn, #UDM_SETRANGE32,1,60) 
; 
; Window Callback 
; 
Procedure WindowCallback(hWindow, Message, wParam, lParam) 
Shared uhwn 
Shared pos 
Result = #PB_ProcessPureBasicEvents 
  Select Message 
     Case #WM_VSCROLL                                                  ; Vertical Scroll Message 
          If lParam = uhwn                                             ; checked only when it comes 
                                                                       ; from Window "uhwn" (UpDown Control)
             pos = SendMessage_(uhwn, #UDM_GETPOS32, 0,@pfError)       ; Get Position
                 If pfError 
                    If pos = 1                                         ; set new Gadget Text 
                                                                       ; If value is "1", add a "0"
                       SetGadgetText(1,"Shutdown PC after 01 minute")  ; before.
                    Else                                               ; "01 minute" -> "02 minutes" 
                       position$ = Str(pos) 
                       If Len(position$) < 2: position$ = "0"+position$:EndIf 
                          SetGadgetText(1,"Shutdown PC after "+position$+" minutes") 
                    EndIf 
                 EndIf 
             Result = 1 
          EndIf 
  EndSelect 
ProcedureReturn Result 
EndProcedure 
SetWindowCallback(@WindowCallback()) 
;
; Event Loop
;
Repeat 
  Select WaitWindowEvent() 
     Case #PB_EventCloseWindow 
          End 
  EndSelect 
ForEver
Maybe that helps too - as a little example.

cya,
...Danilo

(registered PureBasic user)
Post Reply