Post by metro on Mar 31, 2018 4:32:28 GMT -5
Progress Bars are controls that tell you user how much of a progress is complete. There are little bars (wink,wink) that advance depending on the level of completion. The color of these bars depends on the system settings. See the code below for an example.
calldll #comctl32, "InitCommonControls", r As void 'Typical initialization of controls
pbar=CreateWindow(hwnd(#main),"msctls_progress32","",1342177280,5,55,145,23) 'pbar will be the handle of the progress bar.
for i = 1 to 10000 'CreateWindow(handle,classname,caption,style,x,y,width,height)
call Progressbar.setpos pbar, int((i/10000*100)) 'This is to slow it down. You can experiment with other formulas.
scan 'Check for user input such as pressing Cancel, or closing the window. This is important.
next i
[cancel]
[main.quit]
close #main
end
function CreateWindow(hWnd,class$,caption$,style,x,y,w,h)
class$=class$+chr$(0) : caption$=caption$+chr$(0)
calldll #user32, "GetWindowLongA",hWnd as ulong,_ 'Get instance of hWnd (the handle of the window)
_GWL_HINSTANCE as long,hInst as long '
calldll #user32, "CreateWindowExA",_ 'The function is CreateWindowExA, but it is also used for controls.
exstyle as long,class$ as ptr,caption$ as ptr,_ 'These variables and the ones in the rest of the call are determined when the function is called (up above)
style as long,x as long,y as long,w as long,_
h as long,hWnd as ulong,0 as long,hInst as long,0 as long,_
CreateWindow as ulong 'The handle of the progress bar is returned if the operation is a success.
'If not, it's null (0).
end function 'In this case, the result is passed directly into CreateWindow, which is the name of the function, and therefore is passed into the variable pbar (^)
sub Progressbar.setpos handle,pos
calldll #user32, "SendMessageA",_
handle as ulong,1026 as long,_
pos as long,0 as long,_
r as long
end sub
sub Progressbar.setrange handle,startp,endp
if endp<startp then t=endp:endp=startp:startp=t
calldll #user32, "SendMessageA",_
handle as ulong,1025 as long,_
startp as long,endp as long,_
r as long
end sub
function Progressbar.getpos(handle)
calldll #user32, "SendMessageA",_
handle as ulong,1032 as long,_
0 as long,0 as long,_
Progressbar.getpos as long
end function