' Test program for custom control Progressbar include file: pgbar3d.inc

$ filename "pgbar3d3.exe"

'uses rtl32
'uses rtl64

uses WinUtil
uses pgbar3d


% ID_BUTNSTART   = 101
% ID_BUTNREVERSE = 102
% ID_OPTFAST     = 120
% ID_OPTSLOW     = 121
% ID_BAR1        = 202
% ID_BAR2        = 203
% ID_BAR3        = 204

INITCOMMONCONTROLSEXt icce
'Load the common controls library...
icce.dwSize = sizeof(INITCOMMONCONTROLSEXt)
icce.dwICC = 0xffff
InitCommonControlsEx(&icce)

char* cmdline
&cmdline=GetCommandLine()
sys hInstance = GetModuleHandle(null)

function CreateNew(string ctlclass, string Caption, sys hParent, id, int x,y,w,h, optional int Style=0, ExtStyle=0, sys lpParam=0) as sys
   sys hCtrl
   if style=0 then 
      style=WS_CHILD or WS_VISIBLE or WS_TABSTOP
   else
      style=WS_VISIBLE or style
   end if   
   hCtrl=CreateWindowEx(ExtStyle, ctlclass, Caption, Style, x,y,w,h, hParent, id, hInstance, lpParam)
   if hCtrl=null then mbox "Error: Cannot create " ctlclass
   return hCtrl
end function

sub doEvents()
   MSG tMsg   
   while PeekMessage(&tMsg, null, 0,0, PM_NOREMOVE)
      sys bRet = GetMessage (&tMsg, null, 0, 0)
      if bRet = 0 then   'WM_QUIT
        PostQuitMessage(tMsg.wParam)
        exit while 
      elseif bRet = -1 then
        'show an error message
        print "Error in doEvents"
      else
        TranslateMessage(&tMsg)
        DispatchMessage(&tMsg)
      end if
   wend
end sub


MainWindow 295,150, WS_CAPTION or WS_SYSMENU

function WndProc(sys hwnd, uint uMsg, sys wParam, lParam) as sys callback
    int i
    string txt
    static int slow
    static sys hfont
    
    select uMsg
        case WM_CREATE
           hFont=CreateFont(8,4, 0,0,0,0,0,0, ANSI_CHARSET, FALSE, FALSE, DEFAULT_QUALITY, DEFAULT_PITCH or FF_ROMAN, "MS Sans Serif")
   
           SetWindowText(hwnd, "PGBAR3D trippel-bar demo")
           CreateNew("BUTTON",   "Start",hwnd, ID_BUTNSTART,         160, 90, 110, 20)
           CreateNew("BUTTON",   "Reverse",hwnd, ID_BUTNREVERSE,      40, 90, 110, 20)
           CreateNew("BUTTON",   "Fast",hwnd, ID_OPTFAST,             50, 40, 50, 15, WS_CHILD or BS_AUTORADIOBUTTON or WS_TABSTOP or BS_NOTIFY)
           CreateNew("BUTTON",   "Slow",hwnd, ID_OPTSLOW,             50, 60, 50, 15, WS_CHILD or BS_AUTORADIOBUTTON or WS_TABSTOP or BS_NOTIFY)
           SendMessage(GetDlgItem(hwnd, ID_BUTNSTART), WM_SETFONT, hFont, true)
           SendMessage(GetDlgItem(hwnd, ID_BUTNREVERSE), WM_SETFONT, hFont, true)
           SendMessage(GetDlgItem(hwnd, ID_OPTFAST), WM_SETFONT, hFont, true)
           SendMessage(GetDlgItem(hwnd, ID_OPTSLOW), WM_SETFONT, hFont, true)                                 

           SendMessage(GetDlgItem(hwnd, ID_OPTFAST), BM_SETCHECK, true, 0)
           EnableWindow(GetDlgItem(hwnd, ID_BUTNREVERSE), false)

           CreateNew("STATIC", "", hwnd, -1,  10, 10, 270, 24,  WS_CHILD or WS_VISIBLE,  WS_EX_CLIENTEDGE)    

           CreatePGBar3D (hwnd, ID_BAR1, "",  11, 11, 89, 22,   WS_CHILD or WS_VISIBLE, 0)  'BAR1
           SendMessage (GetDlgItem(hwnd, ID_BAR1), PGB_SETMAX, 33, 0)                       'max number of steps
           SendMessage (GetDlgItem(hwnd, ID_BAR1), PGB_SETBARCOL, PGB_RED, 0)               'bar color scheme

           CreatePGBar3D (hwnd, ID_BAR2, "", 100, 11, 89, 22, WS_CHILD or WS_VISIBLE,   0)  'BAR2
           SendMessage (GetDlgItem(hwnd, ID_BAR2), PGB_SETMAX, 33, 0)                       'max number of steps
           SendMessage (GetDlgItem(hwnd, ID_BAR2), PGB_SETBARCOL, PGB_GOLD, 0)              'bar color scheme
           SendMessage (GetDlgItem(hwnd, ID_BAR2), PGB_SETTXTON, 0, 2)                      'show own text
           SendMessage (GetDlgItem(hwnd, ID_BAR2), PGB_SETTXTCOLBKG, RGB(255,255,0), 0)     'backgound text color
           SendMessage (GetDlgItem(hwnd, ID_BAR2), PGB_SETTXTCOLBAR, RGB(0,0,0), 0)         'bar text color
 
           CreatePGBar3D (hwnd, ID_BAR3, "", 189, 11, 89, 22, WS_CHILD or WS_VISIBLE,  0)   'BAR3
           SendMessage (GetDlgItem(hwnd, ID_BAR3), PGB_SETMAX, 33, 0)                       'max number of steps
           SendMessage (GetDlgItem(hwnd, ID_BAR3), PGB_SETBARCOL, PGB_GREEN, 0)             'bar color scheme

           SendMessage (GetDlgItem(hwnd, ID_BAR1), PGB_BUILDBARS, 0, 0)         'finally, build the bars - IMPORTANT!           
           SendMessage (GetDlgItem(hwnd, ID_BAR2), PGB_BUILDBARS, 0, 0)
           SendMessage (GetDlgItem(hwnd, ID_BAR3), PGB_BUILDBARS, 0, 0)

           case WM_COMMAND
              sys id=loword(wParam)
              sys event=hiword(wParam)
              
              if event=BN_CLICKED then
                select case id
                  case ID_BUTNSTART
                     EnableWindow(GetDlgItem(hwnd, ID_BUTNSTART), false)
                     for I = 1 to 100
                        slow = SendMessage(GetDlgItem(hwnd, ID_OPTSLOW), BM_GETCHECK, 0, 0)
                        if I>0 and I <= 33 then
                          SendMessage (GetDlgItem(hwnd, ID_BAR1), PGB_STEPUP, 0, 0)
                        elseif I>33 and I < 67 then
                          SendMessage (GetDlgItem(hwnd, ID_BAR2), PGB_STEPUP, 0, 0)
                        else
                          SendMessage (GetDlgItem(hwnd, ID_BAR3), PGB_STEPUP, 0, 0)
                        end if
                        txt = str(I) + "%"                      
                        SendMessage (GetDlgItem(hwnd, ID_BAR2), PGB_SETTXTBKG, txt, 1)
                        SendMessage (GetDlgItem(hwnd, ID_BAR2), PGB_SETTXTBAR, txt, 1)
                        if mod(I,2) = 0 then doEvents()
                        Sleep 5
                        if slow then Sleep 35                                    '<- if "slow" has been selected
                     next I
                     EnableWindow(GetDlgItem(hwnd, ID_BUTNREVERSE), true)        '<- enable reverse button

                  case ID_BUTNREVERSE
                     EnableWindow(GetDlgItem(hwnd, ID_BUTNREVERSE), false)
                     for I = 99 to 0 step -1
                        slow = SendMessage(GetDlgItem(hwnd, ID_OPTSLOW), BM_GETCHECK, 0, 0)
                        if I>66 then
                          SendMessage (GetDlgItem(hwnd, ID_BAR3), PGB_STEPDN, 0, 0)
                        elseif I>33 then
                          SendMessage (GetDlgItem(hwnd, ID_BAR2), PGB_STEPDN, 0, 0)
                        else
                          SendMessage (GetDlgItem(hwnd, ID_BAR1), PGB_STEPDN, 0, 0)
                        end if
                        txt = str(I) + "%"                      
                        SendMessage (GetDlgItem(hwnd, ID_BAR2), PGB_SETTXTBKG, txt, 1)
                        SendMessage (GetDlgItem(hwnd, ID_BAR2), PGB_SETTXTBAR, txt, 1)
                        if mod(I,2) = 0 then doEvents()
                        Sleep 5
                        if slow then Sleep 35                                    '<- if "slow" has been selected
                     next I
                     EnableWindow(GetDlgItem(hwnd, ID_BUTNSTART), true)          '<- enable start button
                  
                end select
              end if
              
        case WM_CLOSE
           DeleteObject(hFont)
           DestroyWindow(hwnd)
        
        case WM_DESTROY
           DeleteObject hfont
           PostQuitMessage(0)
        
        case else
           return DefWindowProc(hwnd, uMsg, wParam, lParam)
            
    end select

end function

