Local ed As FIRELINES_DATA Ptr
if wMsg <> WM_CREATE then
@ed = GetWindowLongPtr(hWnd, 0)
end if
select case wMsg
case WM_CREATE
sys ped=Getmemory sizeof(FIRELINES_DATA)
SetWindowLongPtr(hWnd, 0, ped) 'Store the pointer for later use
...
case WM_DESTROY
if @ed
if ed.hCtlBrush then DeleteObject ed.hCtlBrush
freememory @ed
end if
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Progressbar include file, PGBAR3D.inc, version 2, version 2, for PB/DLL
' Ported to Oxygenbasic
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Public Domain, by Borje Hagsten, September 2001
' (first released in March 2001 - this is version 2)
' Feel free to use and enhance, but as always - use at own risk..
'
' LOG:
' Jan 14, 2003: Changed to DWORD for handles in some places and
' now use GetWindowLongPtr(hParent, GWL_HINSTANCE)
' to get proper instance handle at creation.
'
' NEW IN VERSION 2
' Now control looks good in 256 color mode too, thanks to own palette.
' New message, PGB_SETBARCOL replaces previous PGB_SETBARCOLMID and
' PGB_SETBARCOLEDGE. Makes it easier to set bar colors via color table,
' see messages below. New way to create control. No need to initialize
' control, just use CreatePGBar3D message directly. See sample on how
' to use it. Otherwise, trimmed code and improved some DC handling.
'
' COMMENTS:
' PGBAR3D is pretty advanced. Can also be used as label, with possibility to
' set separate text on bar/background for nice "fade in/out" effects.
' Should be quite easy
' to make changes according to the news in this version though.
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
uses corewin
'Oxygen
% DT_SINGLELINE = &H20
% DT_LEFT = &H0
% DT_CENTER = &H1
% DT_VCENTER = &H4
% DT_NOCLIP = &H100
% DT_NOPREFIX = &H800
% NUMCOLORS = 24 ' Number of colors the device supports
% RASTERCAPS = 38 ' Bitblt capabilities
% RC_PALETTE = &H00000100 ' supports a palette
% PS_SOLID = 0
% SRCCOPY = 0x00CC0020
% WM_GETFONT = 49
type SIZE
long cx
long cy
end type
macro MakeLong(lo,hi) { ( (lo) or ( (hi)<<16 ) ) }
function RGB(int r, g, b) as int
return (r + g*256 + b*65536)
end Function
function min(int a,b)
if a<b then return a
return b
end function
function max(int a,b)
if a>b then return a
return b
end function
'----------------------------------------------------------------------
'PGBAR3D
' wParam colors for %PGB_SETBARCOL message
%PGB_SILVER = 0
%PGB_RED = 1
%PGB_GREEN = 2
%PGB_BLUE = 3
%PGB_CYAN = 4 'blue-green
%PGB_VIOLET = 5 'red-blue
%PGB_GOLD = 6 'yellow
%PGB_BRONZE = 7 'brown
'custom control messages
%PGB_SETMAX = %WM_USER + 100 'wParam sets max number of steps
%PGB_STEPUP = %WM_USER + 103 'increases step while < max - wParam and lParam shall be 0
%PGB_STEPDN = %WM_USER + 104 'decreases step while > 0 - wParam and lParam shall be 0
%PGB_SETVALUE = %WM_USER + 105 'wParam sets progessbar value, lParam controls redraw
%PGB_BUILDBARS = %WM_USER + 109 'build/rebuild the scrollbars, lParam controls redraw
%PGB_REFRESH = %WM_USER + 110 'redraw the control - wParam and lParam shall be 0
%PGB_GETMAX = %WM_USER + 120 'returns max number of steps
%PGB_GETVALUE = %WM_USER + 121 'returns step value
%PGB_GETTXTON = %WM_USER + 122 'returns txtOnOff value
%PGB_GETTXTPOS = %WM_USER + 123 'returns text position in control
%PGB_GETTXTCOLBAR = %WM_USER + 124 'returns bar text color
%PGB_GETTXTCOLBKG = %WM_USER + 125 'returns background text color
%PGB_GETCOLBKG = %WM_USER + 126 'returns background color
%PGB_GETBARCOL = %WM_USER + 127 'returns bar color scheme
%PGB_GETBARDIR = %WM_USER + 128 'returns bar direction, 0:left/right 1:upside down 2:bottom/top 3:top/bottom
%PGB_GETGRADIENTDIR = %WM_USER + 129 'returns gradient direction - 0:horizontal, 1:vertical
%PGB_GETTXTANGLE = %WM_USER + 130 'returns rotated font
%PGB_SETTXTON = %WM_USER + 150 'lParam sets: 0 = no text, 1 = auto text (%), 2 = custom text
%PGB_SETTXTBAR = %WM_USER + 151 'wParam points to text text for bar, lParam controls redraw
%PGB_SETTXTBKG = %WM_USER + 152 'wParam points to text text for background, lParam controls redraw
%PGB_SETTXTPOS = %WM_USER + 153 'wParam sets text position in control
%PGB_SETTXTCOLBAR = %WM_USER + 154 'wParam sets bar text color
%PGB_SETTXTCOLBKG = %WM_USER + 155 'wParam sets background text color
%PGB_SETCOLBKG = %WM_USER + 156 'wParam sets background color, lParam controls rebuild of control
%PGB_SETBARCOL = %WM_USER + 157 'wParam sets bar color scheme, lParam controls rebuild of control
%PGB_SETBARDIR = %WM_USER + 159 'wParam sets bar direction, 0:left/right 1:upside down 2:bottom/top 3:top/bottom, lParam controls rebuild of control
%PGB_SETGRADIENTDIR = %WM_USER + 160 'wParam sets gradient direction - 0:horizontal, 1:vertical, lParam controls rebuild of control
%PGB_SETTXTANGLE = %WM_USER + 161 'wParam sets set rotated font, lParam controls rebuild of control
TYPE PGB3DDATA 'for storing control specific data in memory block
pStep AS LONG 'for tracking what step we are on
pMax AS LONG 'for storing max number of steps, usually 100 (%)
hbBack AS DWORD 'handle for background brush
barDC AS DWORD 'memCD for Progressbar
barBit AS DWORD 'handle to Progressbar bitmap
barDC2 AS DWORD 'memCD for Progressbar buffer
barBit2 AS DWORD 'handle to Progressbar buffer bitmap
memDc AS DWORD 'memCD for main buffer
hBit AS DWORD 'handle to main buffer bitmap
hRotateFont AS DWORD 'handle to rotated font style
hImageBar AS DWORD 'bar image handle
hImageBkg AS DWORD 'background image handle
direction AS LONG 'bar direction - left to right, or right to left?
gradientDir AS LONG 'gradient direction - left to right, or right to left?
txtAngle AS LONG 'store given text angle
bkgColor AS LONG 'background color
barCol AS LONG 'bar color scheme
txtColBar AS LONG 'custom text color in bar
txtColBkg AS LONG 'custom text color on background
txtOnOff AS LONG '0 = no text, 1 = auto text (%), 2 = custom text
txtPos AS LONG 'text position in control, see DrawText API..
txtBkg AS ASCIIZ * 255 'text to be painted on background, increase/decrease size to suit your needs
txtBar AS ASCIIZ * 255 'text to be painted on bar, increase/decrease size to suit your needs
PalClr(192) AS LONG 'array for color sceme used by the control
end TYPE
declare function CreateGradientBars(sys hWnd) as sys
declare function CreatePGBar3D(sys hParent, id, string txt, int vLeft,vTop,vWidth,vHeight, dword wStyle, optional dword wStyleEx=0, DlgUnits=0) as sys
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Create PGBAR3D control
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
function CreatePGBar3D(sys hParent, id, string txt, int vLeft,vTop,vWidth,vHeight, dword wStyle, optional dword wStyleEx=0, DlgUnits=0) as sys
sys hBar
WNDCLASSEX wc
string szClassName
szClassName = "PGBAR3D"
if GetClassInfoEx(GetModuleHandle(null), szClassName, &wc) = 0 then
wc.cbSize = sizeof(wc)
wc.lpfnWndProc = @PgbWndProc
wc.cbWndExtra = sizeof(sys) 'for pointer to user defined TYPE with control-specific data
wc.hInstance = GetWindowLongPtr(hParent, GWL_HINSTANCE)
wc.hCursor = LoadCursor(null, IDC_ARROW )
wc.lpszClassName = strptr szClassName
if RegisterClassEx(&wc) = null then mbox "Error: RegisterdClassEx PGBAR3D failed"
end if
if DlgUnits then
RECT rc = {0, 0, 4, 8}
MapDialogRect (hParent, @rc)
float PixelX = rc.right/4
float pixelY = rc.bottom/8
'create control using dialog units
hBar = CreateWindowEx(wStyleEx, "PGBAR3D", null, wStyle,
int(vLeft*PixelX), int(vTop*PixelY), int(vWidth*PixelX), int(vHeight*PixelY),
hParent, id, GetWindowLongPtr(hParent, GWL_HINSTANCE), null)
if hBar = 0 then mbox "Error: CreateWindowEx PGBAR3D failed"
else
'create control using pixels
hBar = CreateWindowEx(wStyleEx, "PGBAR3D", null, wStyle,
vLeft, vTop, vWidth, vHeight,
hParent, id, GetWindowLongPtr(hParent, GWL_HINSTANCE), null)
if hBar = 0 then mbox "Error: CreateWindowEx PGBAR3D failed"
end if
if hBar and len(txt) then SetWindowText(hBar, txt)
function = hBar
end function
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Progressbar procedure
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
function PgbWndProc ( sys hWnd, uint wMsg, sys wParam, lParam) as sys callback
local pgb AS PGB3DDATA PTR
'PGB3DDATA *pgb
if wMsg <> WM_CREATE then &pgb = GetWindowLongPtr(hWnd, 0) 'Get control specific data
select case wMsg
case WM_CREATE: 'store control specific data, PGB3DDATA structure, in memory
sys ppgb=Getmemory sizeof(PGB3DDATA)
if ppgb then
SetWindowLongPtr(hWnd, 0, ppgb) 'Store the pointer for later use
else
return -1 'failed to allocate memory, so return -1 to break the action
end if
sys hDC, hFontOld
int xPos, yPos
RECT rc, rcTxt
PAINTSTRUCT ps
SIZE lpSize
zstring *tp
@pgb = ppgb 'get address of PGB3DDATA structure
pgb.txtOnOff = 0 'some initial values - can be changed via custom messages
pgb.txtPos = DT_SINGLELINE OR DT_CENTER OR DT_VCENTER OR DT_NOCLIP OR DT_NOPREFIX
pgb.txtColBar = RGB(0, 0, 0)
pgb.txtColBkg = RGB(255, 255, 0)
pgb.bkgColor = RGB(128, 128, 128) 'Background color
pgb.barCol = 0
pgb.hbBack = CreateSolidBrush(pgb.bkgColor) 'Background brush
'CUSTOM CONTROL MESSAGES
case PGB_STEPUP
if pgb.pStep < pgb.pMax then 'step up while < max
pgb.pStep+=1
SendMessage hWnd, PGB_REFRESH, 0, 0 'repaint window (bar)
end if
case PGB_STEPDN
if pgb.pStep > 0 then 'step down while above 0
pgb.pStep-=1
SendMessage hWnd, PGB_REFRESH, 0, 0 'repaint window (bar)
end if
case PGB_SETVALUE
pgb.pStep = min(pgb.pMax, wParam)
if lParam then SendMessage hWnd, PGB_REFRESH, 0, 0 'refresh if lParam says so
case PGB_BUILDBARS
CreateGradientBars(hWnd) 'build the scrollbars
if lParam then SendMessage hWnd, PGB_REFRESH, 0, 0 'refresh if lParam says so
case PGB_REFRESH 'redraw control
InvalidateRect hWnd, null, 0 : UpdateWindow hWnd
'BAR SETTINGS
case PGB_SETMAX
pgb.pMax = wParam 'set max number of steps
case PGB_GETMAX
return pgb.pMax 'Get max number of steps
case PGB_GETVALUE
return pgb.pStep 'return current step value
case PGB_SETCOLBKG
pgb.bkgColor = wParam 'Set background color via wParam
if pgb.hbBack then DeleteObject pgb.hbBack 'delete old brush, if any
pgb.hbBack = CreateSolidBrush(pgb.bkgColor) 'create background color brush
if lParam then SendMessage hWnd, PGB_BUILDBARS, 1, 0 'refresh if lParam says so
case PGB_SETBARCOL
pgb.barCol = wParam * 24 + 1 'Set bar color
if lParam then SendMessage hWnd, PGB_BUILDBARS, 0, 1 'rebuild and refresh if lParam says so
case PGB_GETBARCOL
return pgb.barCol / 24 'return bar color scheme
case PGB_SETBARDIR
pgb.direction = wParam 'left to right = 0, default
if lParam then SendMessage hWnd, PGB_BUILDBARS, 0, 1 'rebuild and refresh if lParam says so
case PGB_GETBARDIR
return pgb.direction 'return bar direction
case PGB_SETGRADIENTDIR
pgb.gradientDir = wParam 'horizontal = 0, default
if lParam then SendMessage hWnd, PGB_BUILDBARS, 0, 1 'rebuild and refresh if lParam says so
case PGB_GETGRADIENTDIR
return pgb.gradientDir 'return gradient direction
'TEXT MESSAGES
case PGB_SETTXTON
pgb.txtOnOff = lParam 'set text on/off
case PGB_GETTXTON
return pgb.txtOnOff 'return txtOnOff setting
case PGB_SETTXTPOS
pgb.txtPos = wParam 'set text position in control
case PGB_GETTXTPOS
return pgb.txtPos 'return txtPos setting
case PGB_GETTXTCOLBAR
return pgb.txtColBar 'return bar text color
case PGB_GETTXTCOLBKG
return pgb.txtColBkg 'return background text color
case PGB_GETCOLBKG
return pgb.bkgColor 'return background color
case PGB_SETTXTBAR
tp = wParam
pgb.txtBar = tp
if lParam then SendMessage hWnd, PGB_REFRESH, 0, 0 'refresh if lParam says so
case PGB_SETTXTBKG
tp = wParam
pgb.txtBkg = tp
if lParam then SendMessage hWnd, PGB_REFRESH, 0, 0 'refresh if lParam says so
case PGB_SETTXTCOLBAR
pgb.txtColBar = wParam 'set bar's text color
case PGB_SETTXTCOLBKG
pgb.txtColBkg = wParam 'set background's text color
case PGB_SETTXTANGLE
LOGFONT logF
dword tFont
pgb.txtAngle = wParam
tFont = SendMessage(hWnd, WM_GETFONT, 0, 0)
if tFont = null then tFont = GetStockObject(ANSI_VAR_FONT) 'null if system font..
GetObject(tFont, sizeof(logF), &logF)
logF.lfEscapement = wParam * 10 'angle is given in tenths of degrees
logF.lforientation = wParam * 10 'both should be same
logF.lfWeight = FW_BOLD 'whatever, this one looks something like system font..
logF.lfFaceName = "Arial" 'must be True Type font for rotation purposes
pgb.hRotateFont = CreateFontIndirect(&logF) 'create the font and store its handle
if lParam then SendMessage hWnd, PGB_BUILDBARS, 0, 1 'rebuild and refresh if lParam says so
case PGB_GETTXTANGLE
return pgb.txtAngle 'return eventual text angle
'STANDARD CONTROL MESSAGES
case WM_ERASEBKGND: return 1 'we handle background redraw ourselves
case WM_PAINT 'time to paint bar
GetClientRect hWnd, &rc 'get size of control
FillRect pgb.memDC, &rc, pgb.hbBack 'clear background
xPos = pgb.pStep * rc.right / pgb.pMax 'pre-calculate, since often used
yPos = pgb.pStep * rc.bottom / pgb.pMax 'pre-calculate, since often used
if pgb.txtOnOff then 'WITH TEXT
if pgb.txtOnOff = 1 then
pgb.txtBar = str(pgb.pStep) + "" 'auto text to paint on bar
pgb.txtBkg = pgb.txtBar 'auto text to paint on background
end if
rcTxt.left=rc.left 'copy rect for drawtext - the easy way
rcTxt.top=rc.top
rcTxt.right=rc.right
rcTxt.bottom=rc.bottom
if pgb.hRotateFont then
hFontOld = SelectObject(pgb.memDC, pgb.hRotateFont) 'store original font for later use
hFontOld = SelectObject(pgb.barDC2, pgb.hRotateFont) 'is same in both DC's
if pgb.direction = 1 then 'upside down
pgb.txtPos = DT_SINGLELINE OR DT_CENTER OR DT_VCENTER OR DT_NOCLIP OR DT_NOPREFIX
GetTextExtentPoint32(pgb.memDC, pgb.txtBar, len(pgb.txtBar), &lpSize)
rcTxt.bottom = rcTxt.bottom + lpSize.cy * 2
rcTxt.right = rcTxt.right + lpSize.cx * 2
elseif pgb.direction = 2 then 'bottom to top
pgb.txtPos = DT_SINGLELINE OR DT_LEFT OR DT_VCENTER OR DT_NOCLIP OR DT_NOPREFIX
GetTextExtentPoint32(pgb.memDC, pgb.txtBar, len(pgb.txtBar), &lpSize)
rcTxt.left = (rcTxt.right - lpSize.cy) / 2
rcTxt.bottom = rcTxt.bottom + lpSize.cx * 1.25
elseif pgb.direction = 3 then 'top to bottom
pgb.txtPos = DT_SINGLELINE OR DT_LEFT OR DT_VCENTER OR DT_NOCLIP OR DT_NOPREFIX
GetTextExtentPoint32(pgb.memDC, pgb.txtBar, len(pgb.txtBar), &lpSize)
rcTxt.left = (rcTxt.right + lpSize.cy) / 2
rcTxt.top = rcTxt.top - lpSize.cx / 1.35
end if
end if
BitBlt pgb.barDC2, 0, 0, rc.right, rc.bottom,
pgb.barDC, 0, 0, SRCCOPY 'paint original bar to buffer
SetTextColor pgb.barDC2, pgb.txtColBar 'set color on bar
DrawText pgb.barDC2, pgb.txtBar, -1, rcTxt, pgb.txtPos 'draw text on bar
SetTextColor pgb.memDC, pgb.txtColBkg 'set color on background
DrawText pgb.memDC, pgb.txtBkg, -1, rcTxt, pgb.txtPos 'draw text on background
if pgb.direction = 0 then 'LEFT to RIGHT - WITH TEXT
BitBlt pgb.memDC, 0, 0, xPos, rc.bottom,
pgb.barDC2, 0, 0, SRCCOPY 'paint proper part of gradiant bar
elseif pgb.direction = 1 then 'RIGHT to LEFT - WITH TEXT
BitBlt pgb.memDC, rc.right - xPos, 0, xPos, rc.bottom,
pgb.barDC2, rc.right - xPos, 0, SRCCOPY
elseif pgb.direction = 2 then 'BOTTOM to TOP - WITH TEXT
BitBlt pgb.memDC, 0, rc.bottom - yPos, rc.right, rc.bottom,
pgb.barDC2, 0, rc.bottom - yPos, SRCCOPY
elseif pgb.direction = 3 then 'TOP to BOTTOM - WITH TEXT
BitBlt pgb.memDC, 0, 0, rc.right, yPos,
pgb.barDC2, 0, 0, SRCCOPY
end if
else 'WITHOUT TEXT
if pgb.direction = 0 then 'LEFT to RIGHT - NO TEXT
BitBlt pgb.memDC, 0, 0, xPos, rc.bottom,
pgb.barDC, 0, 0, SRCCOPY 'paint proper part of gradiant bar
elseif pgb.direction = 1 then 'RIGHT to LEFT - NO TEXT
BitBlt pgb.memDC, rc.right - xPos, 0, xPos, rc.bottom,
pgb.barDC, rc.right - xPos, 0, SRCCOPY
elseif pgb.direction = 2 then 'BOTTOM to TOP - NO TEXT
BitBlt pgb.memDC, 0, rc.bottom - yPos, rc.right, rc.bottom,
pgb.barDC, 0, rc.bottom - yPos, SRCCOPY
elseif pgb.direction = 3 then 'TOP to BOTTOM - NO TEXT
BitBlt pgb.memDC, 0, 0, rc.right, yPos,
pgb.barDC, 0, 0, SRCCOPY
end if
end if
BeginPaint hWnd, &ps 'begin screen painting
if pgb.PalClr(0) then 'if we have palette (256 color mode)
SelectPalette ps.hDC, pgb.PalClr(0), 0 'then use it in DC..
RealizePalette ps.hDC
end if
BitBlt ps.hDC, 0, 0, rc.right, rc.bottom,
pgb.memDC, 0, 0, SRCCOPY 'paint it all to screen
if hFontOld then
SelectObject(pgb.memDC, hFontOld) 'select the original font back
SelectObject(pgb.barDC2, hFontOld) 'was the same in both DC's
end if
EndPaint hWnd, &ps 'finish up
return 0
case WM_DESTROY : 'clean up, to avoid nasty memory leaks
if pgb.hRotateFont then DeleteObject pgb.hRotateFont 'may be a stockobject, but doesn't matter
if pgb.hbBack then DeleteObject pgb.hbBack 'delete brush
if pgb.hbit then DeleteObject SelectObject(pgb.memDC, pgb.hbit)
if pgb.memDC then DeleteDC pgb.memDC 'and memory DC's + bitmaps
if pgb.barBit then DeleteObject SelectObject(pgb.barDC, pgb.barBit)
if pgb.barDC then DeleteDC pgb.barDC
if pgb.barBit2 then DeleteObject SelectObject(pgb.barDC2, pgb.barBit2)
if pgb.barDC2 then DeleteDC pgb.barDC2
if pgb.PalClr(0) then DeleteObject pgb.PalClr(0)
freememory &pgb
return 0
end select
return DefWindowProc(hWnd, wMsg, wParam, lParam)
end function
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' Create actual ProgressBar, based on previously made settings
' Note: one could also load a couple of bitmaps here instead,
' for some terrific effects.. :-)
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
function CreateGradientBars( sys hWnd) as sys
sys hDC, hPen
int ic, jj
float kk, L
RECT rc
PGB3DDATA *pgb
&pgb = GetWindowLongPtr(hWnd, 0) 'Get control specific data
if pgb.hbit then DeleteObject SelectObject(pgb.memDC, pgb.hbit)
if pgb.memDC then DeleteDC pgb.memDC 'delete old memDC's and bitmaps, if any
if pgb.barBit then DeleteObject SelectObject(pgb.barDC, pgb.barBit)
if pgb.barDC then DeleteDC pgb.barDC
if pgb.barBit2 then DeleteObject SelectObject(pgb.barDC2, pgb.barBit2)
if pgb.barDC2 then DeleteDC pgb.barDC2
GetClientRect hWnd, rc 'get control height and width
hDC = GetDc(hWnd)
if hDC then 'create 3 compatible memory DC's based on
pgb.memDC = CreateCompatibleDC(hDC) 'control's DC, for faster action in WM_PAINT
pgb.hbit = CreateCompatibleBitmap(hDC, rc.right, rc.bottom)
pgb.hbit = SelectObject(pgb.memDC, pgb.hbit)
pgb.barDC = CreateCompatibleDC(hDC)
pgb.barBit = CreateCompatibleBitmap(hDC, rc.right, rc.bottom)
pgb.barBit = SelectObject(pgb.barDC, pgb.barBit)
pgb.barDC2 = CreateCompatibleDC(hDC)
pgb.barBit2 = CreateCompatibleBitmap(hDC, rc.right, rc.bottom)
pgb.barBit2 = SelectObject(pgb.barDC2, pgb.barBit2)
SetBkMode pgb.memDC, TRANSPARENT 'set text background modes
SetBkMode pgb.barDC2, TRANSPARENT
'------------------------------------------------------------------------------
' 'need own palette if in 256 color mode
'------------------------------------------------------------------------------
jj = 1
for ic = 117 to 255 STEP 6 '0, gray table 1-24
pgb.PalClr(jj) = RGB(ic, ic, ic) : jj+=1
next
for ic = 117 to 255 STEP 6 '1, red table 25-48
pgb.PalClr(jj) = RGB(ic, ic - 117, ic - 117) : jj+=1
next
for ic = 117 to 255 STEP 6 '2, green table 49-72
pgb.PalClr(jj) = RGB(ic - 117, ic, ic - 117) : jj+=1
next
for ic = 117 to 255 STEP 6 '3, blue table 73-96
pgb.PalClr(jj) = RGB(ic - 117, ic - 117, ic) : jj+=1
next
for ic = 117 to 255 STEP 6 '4, blue-green table 97-120
pgb.PalClr(jj) = RGB(ic - 117, ic, ic) : jj+=1
next
for ic = 117 to 255 STEP 6 '5, violet table 121-144
pgb.PalClr(jj) = RGB(ic, ic - 117, ic) : jj+=1
next
for ic = 117 to 255 STEP 6 '6, gold table 145-168
pgb.PalClr(jj) = RGB(min(ic + 64, 255), ic, ic - 117) : jj+=1
next
for ic = 117 to 255 STEP 6 '7, brown table 169-192
pgb.PalClr(jj) = RGB(min(ic + 16, 255), ic - 48, ic - 117) : jj+=1
next
jj-=1
if GetDeviceCaps(hDC, NUMCOLORS) > -1 and 'if needed, create own palette
(GetDeviceCaps(hDC, RASTERCAPS) and RC_PALETTE) = RC_PALETTE then
if pgb.PalClr(0) then DeleteObject pgb.PalClr(0)
pgb.PalClr(0) = MakeLong(&H0300, jj)
pgb.PalClr(0) = CreatePalette pgb.PalClr(0)
for ic = 1 to jj
pgb.PalClr(ic) = pgb.PalClr(ic) + &H02000000
next
end if
ReleaseDc hWnd, hDC 'release the temporary DC
if pgb.PalClr(0) then 'if we have palette (256 color mode), then use it in memDCs..
SelectPalette pgb.barDC, pgb.PalClr(0), 0
RealizePalette pgb.barDC
SelectPalette pgb.barDC2, pgb.PalClr(0), 0
RealizePalette pgb.barDC2
end if
'------------------------------------------------------------------------------
if pgb.gradientDir = 0 then 'HORIZONTAL BAR
jj = rc.bottom - 1
else 'VERTICAL BAR
jj = rc.right - 1
end if
kk = pgb.barCol
L = 1 / ((jj / 2) / 24) 'calculate steps for color
for ic = 0 to jj 'draw the whole gradient bar
hPen = CreatePen(PS_SOLID, 1, pgb.PalClr(kk)) 'create pen
hPen = SelectObject(pgb.barDC, hPen) 'select pen into DC, store original pen
if pgb.gradientDir = 0 then 'HORIZONTAL BAR
MoveToEx pgb.barDC, 0, ic, null 'move into position
LineTo pgb.barDC, rc.right, ic 'and draw a line from left to right
else 'VERTICAL BAR
MoveToEx pgb.barDC, ic, 0, null 'move into position
LineTo pgb.barDC, ic, rc.bottom 'and draw a line from top to bottom
end if
DeleteObject SelectObject(pgb.barDC, hPen) 'delete pen to avoid memory leaks
if ic < jj / 2 -1 then
kk = MIN(pgb.barCol + 23, int(kk + L))
else
kk = MAX(pgb.barCol, int(kk - L))
end if
next
return true 'return true on success
end if
end function
But I do not understand why you insist to use version A43
TYPE PGB3DDATA 'for storing control specific data in memory block
pStep AS LONG 'for tracking what step we are on
pMax AS LONG 'for storing max number of steps, usually 100 (%)
hbBack AS DWORD 'handle for background brush
barDC AS DWORD 'memCD for Progressbar
barBit AS DWORD 'handle to Progressbar bitmap
barDC2 AS DWORD 'memCD for Progressbar buffer
barBit2 AS DWORD 'handle to Progressbar buffer bitmap
memDc AS DWORD 'memCD for main buffer
hBit AS DWORD 'handle to main buffer bitmap
hRotateFont AS DWORD 'handle to rotated font style
hImageBar AS DWORD 'bar image handle
hImageBkg AS DWORD 'background image handle
direction AS LONG 'bar direction - left to right, or right to left?
gradientDir AS LONG 'gradient direction - left to right, or right to left?
txtAngle AS LONG 'store given text angle
bkgColor AS LONG 'background color
barCol AS LONG 'bar color scheme
txtColBar AS LONG 'custom text color in bar
txtColBkg AS LONG 'custom text color on background
txtOnOff AS LONG '0 = no text, 1 = auto text (%), 2 = custom text
txtPos AS LONG 'text position in control, see DrawText API..
' txtBkg AS ASCIIZ * 255 'text to be painted on background, increase/decrease size to suit your needs
' txtBar AS ASCIIZ * 255 'text to be painted on bar, increase/decrease size to suit your needs
txtBkg[255] AS ASCIIZ 'text to be painted on background, increase/decrease size to suit your needs
txtBar[255] AS ASCIIZ 'text to be painted on bar, increase/decrease size to suit your needs
PalClr(192) AS LONG 'array for color sceme used by the control
end TYPE