Cwindow release candidate 4.
I have adapted Börje's old PGBAR3D control using a class and make it DPI and unicode aware.
You can set the options using SendMessageW, the class methods or a mix of the two.
Example using SendMessage:
' ########################################################################################
' Microsoft Windows
' File: CW_PG3D.fbtpl
' Contents: CWindow with a PGBAR3D control
' Compiler: FreeBasic 32 & 64 bit
' Copyright (c) 2016 Jose Roca. Freeware. Use at your own risk.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#define unicode
#INCLUDE ONCE "windows.bi"
#INCLUDE ONCE "Afx/CWindow.inc"
#INCLUDE ONCE "Afx/CPgBar3D.inc"
USING Afx.CWindowClass
USING Afx.CPgBar3DClass
enum
IDC_START = 1001
IDC_REVERSE
IDC_OPTFAST
IDC_OPTSLOW
IDC_PGBAR1
IDC_PGBAR2
IDC_PGBAR3
end enum
DECLARE FUNCTION WinMain (BYVAL hInstance AS HINSTANCE, _
BYVAL hPrevInstance AS HINSTANCE, _
BYVAL szCmdLine AS ZSTRING PTR, _
BYVAL nCmdShow AS LONG) AS LONG
END WinMain(GetModuleHandleW(""), NULL, COMMAND(), SW_NORMAL)
' ========================================================================================
' Window procedure
' ========================================================================================
FUNCTION WndProc (BYVAL hWnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT
STATIC slow AS LONG, allSteps AS LONG
SELECT CASE uMsg
CASE WM_CREATE
EXIT FUNCTION
' CASE WM_SYSCOMMAND
' ' // Ignore the red X (close) button
' IF (wParam AND &HFFF0) = SC_CLOSE THEN EXIT FUNCTION
CASE WM_COMMAND
SELECT CASE LOWORD(wParam)
CASE IDCANCEL
' // If ESC key pressed, close the application sending an WM_CLOSE message
IF HIWORD(wParam) = BN_CLICKED THEN
SendMessageW hwnd, WM_CLOSE, 0, 0
EXIT FUNCTION
END IF
CASE IDC_OPTFAST
IF HIWORD(wParam) = BN_CLICKED THEN
slow = FALSE
END IF
CASE IDC_OPTSLOW
IF HIWORD(wParam) = BN_CLICKED THEN
slow = CTRUE
END IF
CASE IDC_START
EnableWindow(GetDlgItem(hwnd, IDC_START), FALSE) ' // Disable the start button
SCOPE
DIM i AS LONG, hCtl AS HWND, wszText AS WSTRING * 260
FOR i = 1 TO 100
IF i < 34 THEN
hCtl = GetDlgItem(hwnd, IDC_PGBAR1)
ELSEIF i < 67 THEN
hCtl = GetDlgItem(hwnd, IDC_PGBAR2)
ELSE
hCtl = GetDlgItem(hwnd, IDC_PGBAR3)
END IF
SendMessageW hCtl, PGB_STEPUP, 0, 0
wszText = WSTR(i) & "%"
SendMessageW GetDlgItem(hwnd, IDC_PGBAR2), PGB_SETTXTBKG, CAST(WPARAM, @wszText), CTRUE
SendMessageW GetDlgItem(hwnd, IDC_PGBAR2), PGB_SETTXTBAR, CAST(WPARAM, @wszText), CTRUE
IF i MOD 2 = 0 THEN AfxDoEvents(hwnd)
IF slow THEN SLEEP 40
NEXT
END SCOPE
EnableWindow(GetDlgItem(hwnd, IDC_REVERSE), CTRUE) ' // Enable the reverse button
EXIT FUNCTION
CASE IDC_REVERSE
EnableWindow(GetDlgItem(hwnd, IDC_REVERSE), FALSE) ' // Disable the reverse button
SCOPE
DIM i AS LONG, hCtl AS HWND, wszText AS WSTRING * 260
FOR i = 99 TO 0 STEP -1
IF i > 66 THEN
hCtl = GetDlgItem(hwnd, IDC_PGBAR3)
ELSEIF i > 33 THEN
hCtl = GetDlgItem(hwnd, IDC_PGBAR2)
ELSE
hCtl = GetDlgItem(hwnd, IDC_PGBAR1)
END IF
SendMessageW hCtl, PGB_STEPDN, 0, 0
wszText = WSTR(i) & "%"
SendMessageW GetDlgItem(hwnd, IDC_PGBAR2), PGB_SETTXTBKG, CAST(WPARAM, @wszText), CTRUE
SendMessageW GetDlgItem(hwnd, IDC_PGBAR2), PGB_SETTXTBAR, CAST(WPARAM, @wszText), CTRUE
IF i MOD 2 = 0 THEN AfxDoEvents(hwnd)
IF slow THEN SLEEP 40
NEXT
END SCOPE
EnableWindow(GetDlgItem(hwnd, IDC_START), CTRUE) ' // Enable the start button
EXIT FUNCTION
END SELECT
CASE WM_DESTROY
PostQuitMessage(0)
EXIT FUNCTION
END SELECT
FUNCTION = DefWindowProcW(hWnd, uMsg, wParam, lParam)
END FUNCTION
' ========================================================================================
' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS HINSTANCE, _
BYVAL hPrevInstance AS HINSTANCE, _
BYVAL szCmdLine AS ZSTRING PTR, _
BYVAL nCmdShow AS LONG) AS LONG
' // Set process DPI aware
AfxSetProcessDPIAware
DIM pWindow AS CWindow
pWindow.Create(NULL, "CWindow with PGBAR3D control", @WndProc)
pWindow.SetClientSize(300, 155)
pWindow.Center
' // Add the buttons
DIM hbtReverse AS HWND = pWindow.AddControl("Button", pWindow.hWindow, IDC_REVERSE, "&Reverse", 30, 115, 100, 23)
DIM hbtStart AS HWND = pWindow.AddControl("Button", pWindow.hWindow, IDC_START, "&Start", 168, 115, 100, 23)
EnableWindow(hbtReverse, FALSE) ' // Disable the reverse button
' // Add the check boxes
pWindow.AddControl("Option", pWindow.hWindow, IDC_OPTFAST, "Fast", 30, 60, 75, 23)
pWindow.AddControl("Option", pWindow.hWindow, IDC_OPTSLOW, "Slow", 30, 80, 75, 23)
' // Add a label
DIM hLabel AS HWND = pWindow.AddControl("Label", pWindow.hWindow, -1, "", 29, 14, 242, 25, , WS_EX_CLIENTEDGE)
' // Add the first progress bar
DIM pPgBar1 AS CPgBar3D = CPgBar3D(@pWindow, IDC_PGBAR1, "", 30, 15, 80, 23)
SendMessageW pPgBar1.hWindow, PGB_SETMAX, 33, 0 ' Max number of teps
SendMessageW pPgBar1.hWindow, PGB_SETBARCOL, PGB_RED, 0 ' Bar color scheme
' // Add the second progress bar
DIM pPgBar2 AS CPgBar3D = CPgBar3D(@pWindow, IDC_PGBAR2, "", 110, 15, 80, 23)
SendMessageW pPgBar2.hWindow, PGB_SETMAX, 33, 0 ' Max number of teps
SendMessageW pPgBar2.hWindow, PGB_SETBARCOL, PGB_GOLD, 0 ' Bar color scheme
SendMessageW pPgBar2.hWindow, PGB_SETTXTON, 0, PGB_TEXTCUSTOM ' Show own text
SendMessageW pPgBar2.hWindow, PGB_SETTXTCOLBKG, BGR(255, 255, 0), 0 ' Backgound text color yellow
SendMessageW pPgBar2.hWindow, PGB_SETTXTCOLBAR, BGR(0, 0, 0), 0 ' Bar text color black
' // Add the third progress bar
DIM pPgBar3 AS CPgBar3D = CPgBar3D(@pWindow, IDC_PGBAR3, "", 190, 15, 80, 23)
SendMessageW pPgBar3.hWindow, PGB_SETMAX, 33, 0 ' Max number of teps
SendMessageW pPgBar3.hWindow, PGB_SETBARCOL, PGB_GREEN, 0 ' Bar color scheme
' // Requires: Build the bars
SendMessageW pPgBar1.hWindow, PGB_BUILDBARS, 0, 0
SendMessageW pPgBar2.hWindow, PGB_BUILDBARS, 0, 0
SendMessageW pPgBar3.hWindow, PGB_BUILDBARS, 0, 0
FUNCTION = pWindow.DoEvents(nCmdShow)
END FUNCTION
' ========================================================================================
Example using the class methods:
' ########################################################################################
' Microsoft Windows
' File: CW_PG3D.fbtpl
' Contents: CWindow with a PGBAR3D control
' Compiler: FreeBasic 32 & 64 bit
' Copyright (c) 2016 Jose Roca. Freeware. Use at your own risk.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#define unicode
#INCLUDE ONCE "windows.bi"
#INCLUDE ONCE "Afx/CWindow.inc"
#INCLUDE ONCE "Afx/CPgBar3D.inc"
USING Afx.CWindowClass
USING Afx.CPgBar3DClass
enum
IDC_START = 1001
IDC_REVERSE
IDC_OPTFAST
IDC_OPTSLOW
IDC_PGBAR1
IDC_PGBAR2
IDC_PGBAR3
end enum
DECLARE FUNCTION WinMain (BYVAL hInstance AS HINSTANCE, _
BYVAL hPrevInstance AS HINSTANCE, _
BYVAL szCmdLine AS ZSTRING PTR, _
BYVAL nCmdShow AS LONG) AS LONG
END WinMain(GetModuleHandleW(""), NULL, COMMAND(), SW_NORMAL)
' ========================================================================================
' Window procedure
' ========================================================================================
FUNCTION WndProc (BYVAL hWnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT
STATIC slow AS LONG, allSteps AS LONG
SELECT CASE uMsg
CASE WM_CREATE
EXIT FUNCTION
' CASE WM_SYSCOMMAND
' ' // Ignore the red X (close) button
' IF (wParam AND &HFFF0) = SC_CLOSE THEN EXIT FUNCTION
CASE WM_COMMAND
SELECT CASE LOWORD(wParam)
CASE IDCANCEL
' // If ESC key pressed, close the application sending an WM_CLOSE message
IF HIWORD(wParam) = BN_CLICKED THEN
SendMessageW hwnd, WM_CLOSE, 0, 0
EXIT FUNCTION
END IF
CASE IDC_OPTFAST
IF HIWORD(wParam) = BN_CLICKED THEN
slow = FALSE
END IF
CASE IDC_OPTSLOW
IF HIWORD(wParam) = BN_CLICKED THEN
slow = CTRUE
END IF
CASE IDC_START
EnableWindow(GetDlgItem(hwnd, IDC_START), FALSE) ' // Disable the start button
SCOPE
DIM i AS LONG, hCtl AS HWND, wszText AS WSTRING * 260
DIM pPgBar1 AS CPgBar3D PTR = CAST(CPgBar3D PTR, GetPropW(GetDlgItem(hwnd, IDC_PGBAR1), "CPGBAR3DPTR"))
DIM pPgBar2 AS CPgBar3D PTR = CAST(CPgBar3D PTR, GetPropW(GetDlgItem(hwnd, IDC_PGBAR2), "CPGBAR3DPTR"))
DIM pPgBar3 AS CPgBar3D PTR = CAST(CPgBar3D PTR, GetPropW(GetDlgItem(hwnd, IDC_PGBAR3), "CPGBAR3DPTR"))
FOR i = 1 TO 100
IF i < 34 THEN
pPgBar1->StepUp
ELSEIF i < 67 THEN
pPgBar2->StepUp
ELSE
pPgBar3->StepUp
END IF
wszText = WSTR(i) & "%"
pPgBar2->SetBackText wszText, CTRUE
pPgBar2->SetBarText wszText, CTRUE
IF i MOD 2 = 0 THEN AfxDoEvents(hwnd)
IF slow THEN SLEEP 40
NEXT
END SCOPE
EnableWindow(GetDlgItem(hwnd, IDC_REVERSE), CTRUE) ' // Enable the reverse button
EXIT FUNCTION
CASE IDC_REVERSE
EnableWindow(GetDlgItem(hwnd, IDC_REVERSE), FALSE) ' // Disable the reverse button
DIM pPgBar1 AS CPgBar3D PTR = CAST(CPgBar3D PTR, GetPropW(GetDlgItem(hwnd, IDC_PGBAR1), "CPGBAR3DPTR"))
DIM pPgBar2 AS CPgBar3D PTR = CAST(CPgBar3D PTR, GetPropW(GetDlgItem(hwnd, IDC_PGBAR2), "CPGBAR3DPTR"))
DIM pPgBar3 AS CPgBar3D PTR = CAST(CPgBar3D PTR, GetPropW(GetDlgItem(hwnd, IDC_PGBAR3), "CPGBAR3DPTR"))
SCOPE
DIM i AS LONG, hCtl AS HWND, wszText AS WSTRING * 260
FOR i = 99 TO 0 STEP -1
IF i > 66 THEN
pPgBar3->StepDown
ELSEIF i > 33 THEN
pPgBar2->StepDown
ELSE
pPgBar1->StepDown
END IF
wszText = WSTR(i) & "%"
pPgBar2->SetBackText wszText, CTRUE
pPgBar2->SetBarText wszText, CTRUE
IF i MOD 2 = 0 THEN AfxDoEvents(hwnd)
IF slow THEN SLEEP 40
NEXT
END SCOPE
EnableWindow(GetDlgItem(hwnd, IDC_START), CTRUE) ' // Enable the start button
EXIT FUNCTION
END SELECT
CASE WM_DESTROY
PostQuitMessage(0)
EXIT FUNCTION
END SELECT
FUNCTION = DefWindowProcW(hWnd, uMsg, wParam, lParam)
END FUNCTION
' ========================================================================================
' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS HINSTANCE, _
BYVAL hPrevInstance AS HINSTANCE, _
BYVAL szCmdLine AS ZSTRING PTR, _
BYVAL nCmdShow AS LONG) AS LONG
' // Set process DPI aware
AfxSetProcessDPIAware
DIM pWindow AS CWindow
pWindow.Create(NULL, "CWindow with PGBAR3D control", @WndProc)
pWindow.SetClientSize(300, 155)
pWindow.Center
' // Add the buttons
DIM hbtReverse AS HWND = pWindow.AddControl("Button", pWindow.hWindow, IDC_REVERSE, "&Reverse", 30, 115, 100, 23)
DIM hbtStart AS HWND = pWindow.AddControl("Button", pWindow.hWindow, IDC_START, "&Start", 168, 115, 100, 23)
EnableWindow(hbtReverse, FALSE) ' // Disable the reverse button
' // Add the check boxes
pWindow.AddControl("Option", pWindow.hWindow, IDC_OPTFAST, "Fast", 30, 60, 75, 23)
pWindow.AddControl("Option", pWindow.hWindow, IDC_OPTSLOW, "Slow", 30, 80, 75, 23)
' // Add a label
DIM hLabel AS HWND = pWindow.AddControl("Label", pWindow.hWindow, -1, "", 29, 14, 242, 25, , WS_EX_CLIENTEDGE)
' // Add the first progress bar
DIM pPgBar1 AS CPgBar3D = CPgBar3D(@pWindow, IDC_PGBAR1, "", 30, 15, 80, 23)
pPgBar1.SetMaxSteps 33 ' Max number of teps
pPgBar1.SetBarColor PGB_RED ' Bar color scheme
' // Add the second progress bar
DIM pPgBar2 AS CPgBar3D = CPgBar3D(@pWindow, IDC_PGBAR2, "", 110, 15, 80, 23)
pPgBar2.SetMaxSteps 33 ' Max number of teps
pPgBar2.SetBarColor PGB_GOLD ' Bar color scheme
pPgBar2.SetTextOn PGB_TEXTCUSTOM ' Show own text
pPgBar2.SetBarTextColor BGR(255, 255, 0) ' Backgound text color yellow
pPgBar2.SetBarTextColor BGR(0, 0, 0) ' Bar text color black
' // Add the third progress bar
DIM pPgBar3 AS CPgBar3D = CPgBar3D(@pWindow, IDC_PGBAR3, "", 190, 15, 80, 23)
pPgBar3.SetMaxSteps 33 ' Max number of teps
pPgBar3.SetBarColor PGB_GREEN ' Bar color scheme
' // Requires: Build the bars
pPgBar1.BuildBar
pPgBar2.BuildBar
pPgBar3.BuildBar
FUNCTION = pWindow.DoEvents(nCmdShow)
END FUNCTION
' ========================================================================================
Jose,
I noticed in your FBWThemes_HDPI_W7.xml no listing in the <!-- Compatibility section --> for Win 10.
Not needed?
James
Quote from: James Fuller on May 02, 2016, 05:08:55 PM
Jose,
I noticed in your FBWThemes_HDPI_W7.xml no listing in the <!-- Compatibility section --> for Win 10.
Not needed?
James
Guess that it is needed, but I don't have Windows 10 to test.
I have modified the Progress Bar slightly.
New code included in the attachment.
New examples also in the attachment.
This control from Börje is a very nice replacement to the Windows progress bar control, that I found very ugly.
I think that I'm going to store the pointer to the class in extra bytes of the window class instead of as a property.