Trackbar question & animate window

Started by Frank Bruebach, July 13, 2026, 02:24:00 PM

Previous topic - Next topic

Frank Bruebach


hello. I have tried yesterday just for fun to use the slider (trackbar) control.

I couldn't find Trackbar_SetTicfreq hTrackBar, 10 ', 0 ' function, that doesnt exist in cWindow?
I have built and add in cWindow 'SendMessageW hTrackBar, TBM_SETTICFREQ, 10,0' but this code have no effect in my current example.

how to insert a correct AnimateWindow() effect fade in fade out using the slider control  ?
my code I have built so far..

thanks, frank


' trackbar example
 
#define UNICODE
#INCLUDE ONCE "AfxNova/CWindow.inc"
USING AfxNova

' Constants for animation types
const AW_HOR_POSITIVE = 1
Const AW_HOR_NEGATIVE = 2
Const AW_VER_POSITIVE = 4
Const AW_VER_NEGATIVE = 8
Const AW_CENTER = 16
Const AW_SLIDE = 262144
Const AW_BLEND = 524288

DECLARE FUNCTION wWinMain (BYVAL hInstance AS HINSTANCE, _
                           BYVAL hPrevInstance AS HINSTANCE, _
                           BYVAL pwszCmdLine AS WSTRING PTR, _
                           BYVAL nCmdShow AS LONG) AS LONG
   END wWinMain(GetModuleHandleW(NULL), NULL, wCommand(), SW_NORMAL)

' // Forward declaration
DECLARE FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

CONST IDC_TRACKBAR = 1001

' ========================================================================================
' Main
' ========================================================================================
FUNCTION wWinMain (BYVAL hInstance AS HINSTANCE, _
                   BYVAL hPrevInstance AS HINSTANCE, _
                   BYVAL pwszCmdLine AS WSTRING PTR, _
                   BYVAL nCmdShow AS LONG) AS LONG

   ' // Set process DPI aware
   SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE)
   ' // Enable visual styles without including a manifest file
   AfxEnableVisualStyles

   ' // Creates the main window
   DIM pWindow AS CWindow = "MyClassName"   ' Use the name you wish
   DIM hWin AS HWND = pWindow.Create(NULL, "CWindow - TrackBar", @WndProc)
   ' // Sizes it by setting the wanted width and height of its client area
   pWindow.SetClientSize(400, 220)
   ' // Centers the window
   pWindow.Center

   ' // Adds a Trackbar control
   DIM hTrackBar AS HWND = pWindow.AddControl("Trackbar", hWin, IDC_TRACKBAR, "", 75, 60, 240, 32)
   ' // Set the range values
   Trackbar_SetRangeMin hTrackBar, 0, TRUE
   Trackbar_SetRangeMax hTrackBar, 20, TRUE
   ' new
   Trackbar_SetTicfreq hTrackBar, 10 ', 0 ' doesnt exist ?
 
   ' SendMessageW hTrackBar, TBM_SETTICFREQ, 10,0 ' included in cWindow ?
   
   ' // Set the page size
   Trackbar_SetPageSize hTrackBar, 1
   pWindow.AnchorControl(IDC_TRACKBAR, AFX_ANCHOR_WIDTH)

' Fade the window in over 500 milliseconds
    AnimateWindow(hWin, 500, AW_BLEND Or AW_ACTIVATE)
   
    Sleep 2000 ' Wait for 2 seconds
   
    ' Slide the window out to the right
     AnimateWindow(hWin, 500, AW_SLIDE Or AW_HOR_POSITIVE Or AW_HIDE)

   ' // Adds a button
   pWindow.AddControl("Button", hWin, IDCANCEL, "&Close", 270, 155, 75, 30)
   ' // Anchors the button to the bottom and the right side of the main window
   pWindow.AnchorControl(IDCANCEL, AFX_ANCHOR_BOTTOM_RIGHT)

   ' // Displays the window and dispatches the Windows messages
   FUNCTION = pWindow.DoEvents(nCmdShow)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main window procedure
' ========================================================================================
FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

   SELECT CASE uMsg

      ' // If an application processes this message, it should return zero to continue
      ' // creation of the window. If the application returns –1, the window is destroyed
      ' // and the CreateWindowExW function returns a NULL handle.
      CASE WM_CREATE
         
         RETURN 0
         
      ' // Sent when the user selects a command item from a menu, when a control sends a
      ' // notification message to its parent window, or when an accelerator keystroke is translated.
      CASE WM_COMMAND
         SELECT CASE CBCTL(wParam, lParam)
            CASE IDCANCEL
               ' // If ESC key pressed, close the application by sending an WM_CLOSE message
               IF CBCTLMSG(wParam, lParam) = BN_CLICKED THEN SendMessageW(hwnd, WM_CLOSE, 0, 0)
         END SELECT
         RETURN 0

      CASE WM_HSCROLL
         IF GetWindowID(cast(HWND, lParam)) = IDC_TRACKBAR THEN
            ' Put your code here
            ' The LOWORD of wParam specifies a scroll bar value that indicates the user's scrolling request.
            ' The HIWORD specifies the current position of the scroll box if the LOWORD is SB_THUMBPOSITION
            ' or SB_THUMBTRACK; otherwise, this word is not used.
            'AnimateWindow(hwnd, 500, AW_BLEND Or AW_ACTIVATE)
           
         END IF
         RETURN 0

      CASE WM_DESTROY
         ' // End the application by sending an WM_QUIT message
         PostQuitMessage(0)
         RETURN 0

   END SELECT

   ' // Default processing of Windows messages
   FUNCTION = DefWindowProcW(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================

Frank Bruebach

#1
Update: Slider fade Out at Position 20 works. Only the setticfreq marks are still Missing.. better to say the Tic Marks below or above trackbar control

'
 slider fade out at position 20 go
'
#define UNICODE
#INCLUDE ONCE "AfxNova/CWindow.inc"
USING AfxNova

Const AW_BLEND = 524288
Const AW_HIDE  = 65536
Const AW_ACTIVATE = 131072
Const AW_SLIDE = 262144
Const AW_HOR_POSITIVE = 1

Const IDC_TRACKBAR = 1001

DECLARE FUNCTION wWinMain (BYVAL hInstance AS HINSTANCE, _
                           BYVAL hPrevInstance AS HINSTANCE, _
                           BYVAL pwszCmdLine AS WSTRING PTR, _
                           BYVAL nCmdShow AS LONG) AS LONG
   END wWinMain(GetModuleHandleW(NULL), NULL, wCommand(), SW_NORMAL)

' // Forward declaration
DECLARE FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT


FUNCTION wWinMain(hInstance AS HINSTANCE, hPrevInstance AS HINSTANCE, _
                  pwszCmdLine AS WSTRING PTR, nCmdShow AS LONG) AS LONG

    SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE)
    AfxEnableVisualStyles

    DIM win AS CWindow = "MyClassName"
    DIM hWin AS HWND = win.Create(NULL, "Trackbar + AnimateWindow", @WndProc)
    win.SetClientSize(400, 220)
    win.Center

    ' Trackbar mit Ticks
    DIM hTrack AS HWND = win.AddControl("Trackbar", hWin, IDC_TRACKBAR, "", _
                                        75, 60, 240, 32, _
                                        WS_CHILD OR WS_VISIBLE OR TBS_AUTOTICKS)

    Trackbar_SetRangeMin(hTrack, 0, TRUE)
    Trackbar_SetRangeMax(hTrack, 20, TRUE)
    Trackbar_SetTicfreq hTrack, 10 ' doesnt exist ?
 
    ' Jetzt funktioniert es
    SendMessageW(hTrack, TBM_SETTICFREQ, 5, 0)

    win.AddControl("Button", hWin, IDCANCEL, "&Close", 270, 155, 75, 30)
    win.AnchorControl(IDCANCEL, AFX_ANCHOR_BOTTOM_RIGHT)

    FUNCTION = win.DoEvents(nCmdShow)
END FUNCTION


FUNCTION WndProc(hwnd AS HWND, uMsg AS UINT, wParam AS WPARAM, lParam AS LPARAM) AS LRESULT
    SELECT CASE uMsg

    CASE WM_SHOWWINDOW
       ' IF GetWindowID(cast(HWND, lParam)) = IDC_TRACKBAR THEN
               IF GET_WM_COMMAND_CMD(wParam, lParam) = BN_CLICKED THEN
         
        'IF wParam = TRUE THEN
            ' Fade-In
            AnimateWindow(hwnd, 500, AW_BLEND OR AW_ACTIVATE)
           
        END IF
        RETURN 0

    CASE WM_HSCROLL
        IF GetWindowID(CAST(HWND, lParam)) = IDC_TRACKBAR THEN
            DIM posy AS LONG = Trackbar_GetPos(CAST(HWND, lParam))

            ' Fade-Out abhängig vom Slider
            IF posy = 20 THEN
                AnimateWindow(hwnd, 500, AW_BLEND OR AW_HIDE)
            END IF
        END IF
        RETURN 0

    CASE WM_COMMAND
        IF CBCTL(wParam, lParam) = IDCANCEL THEN
            IF CBCTLMSG(wParam, lParam) = BN_CLICKED THEN
                SendMessageW(hwnd, WM_CLOSE, 0, 0)
            END IF
        END IF
        RETURN 0

    CASE WM_DESTROY
        PostQuitMessage(0)
        RETURN 0
    END SELECT

    RETURN DefWindowProcW(hwnd, uMsg, wParam, lParam)
END FUNCTION


Frank Bruebach

Another example with transparency of Main Window works fine by using trackbar Control


' slider window transparency works :-)
'
#define UNICODE
#INCLUDE ONCE "AfxNova/CWindow.inc"
USING AfxNova

' Constants for animation types
const AW_HOR_POSITIVE = 1
Const AW_HOR_NEGATIVE = 2
Const AW_VER_POSITIVE = 4
Const AW_VER_NEGATIVE = 8
Const AW_CENTER = 16
Const AW_SLIDE = 262144
Const AW_BLEND = 524288

DECLARE FUNCTION wWinMain (BYVAL hInstance AS HINSTANCE, _
                           BYVAL hPrevInstance AS HINSTANCE, _
                           BYVAL pwszCmdLine AS WSTRING PTR, _
                           BYVAL nCmdShow AS LONG) AS LONG
   END wWinMain(GetModuleHandleW(NULL), NULL, wCommand(), SW_NORMAL)

' // Forward declaration
DECLARE FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

CONST IDC_TRACKBAR = 1001

FUNCTION wWinMain(hInstance AS HINSTANCE, hPrevInstance AS HINSTANCE, _
                  pwszCmdLine AS WSTRING PTR, nCmdShow AS LONG) AS LONG

    SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE)
    AfxEnableVisualStyles

    DIM win AS CWindow = "LayeredWindow"
    DIM hWin AS HWND = win.Create(NULL, "Slider Transparency", @WndProc)

    ' Fenstergröße
    win.SetClientSize(400, 220)
    win.Center

    ' Fenster zu einem Layered Window machen
    DIM exStyles AS LONG = GetWindowLongW(hWin, GWL_EXSTYLE)
    SetWindowLongW(hWin, GWL_EXSTYLE, exStyles OR WS_EX_LAYERED)

    ' Anfangstransparenz (255 = voll sichtbar)
    SetLayeredWindowAttributes(hWin, 0, 255, LWA_ALPHA)

    ' Trackbar
    DIM hTrack AS HWND = win.AddControl("Trackbar", hWin, IDC_TRACKBAR, "", _
                                        75, 60, 240, 32, _
                                        WS_CHILD OR WS_VISIBLE OR TBS_AUTOTICKS)

    Trackbar_SetRangeMin(hTrack, 0, TRUE)
    Trackbar_SetRangeMax(hTrack, 255, TRUE)
    SendMessageW(hTrack, TBM_SETTICFREQ, 25, 0)

    ' Close Button
    win.AddControl("Button", hWin, IDCANCEL, "&Close", 270, 155, 75, 30)
    win.AnchorControl(IDCANCEL, AFX_ANCHOR_BOTTOM_RIGHT)

    FUNCTION = win.DoEvents(nCmdShow)
END FUNCTION


FUNCTION WndProc(hwnd AS HWND, uMsg AS UINT, wParam AS WPARAM, lParam AS LPARAM) AS LRESULT
    SELECT CASE uMsg

    CASE WM_HSCROLL
        IF GetWindowID(CAST(HWND, lParam)) = IDC_TRACKBAR THEN
            DIM posy AS LONG = Trackbar_GetPos(CAST(HWND, lParam))

            ' Transparenz setzen
            ' posy = 0   → komplett durchsichtig
            ' posy = 255 → komplett sichtbar
            SetLayeredWindowAttributes(hwnd, 0, posy, LWA_ALPHA)
        END IF
        RETURN 0

    CASE WM_COMMAND
        IF CBCTL(wParam, lParam) = IDCANCEL THEN
            IF CBCTLMSG(wParam, lParam) = BN_CLICKED THEN
                SendMessageW(hwnd, WM_CLOSE, 0, 0)
            END IF
        END IF
        RETURN 0

    CASE WM_DESTROY
        PostQuitMessage(0)
        RETURN 0
    END SELECT

    RETURN DefWindowProcW(hwnd, uMsg, wParam, lParam)
END FUNCTION
'ends

Frank Bruebach

#3
Concerning my First and second example..

hello again.. simple question.. does "Trackbar_SetTicfreq" hTrackBar, 2, 0 exist in cWindow?
TBM_SETTICFREQ ?


' // Adds a Trackbar control
   DIM hTrackBar AS HWND = pWindow.AddControl("Trackbar", hWin, IDC_TRACKBAR, "", 75, 60, 240, 32)
   ' // Set the range values
   Trackbar_SetRangeMin hTrackBar, 0, TRUE
   Trackbar_SetRangeMax hTrackBar, 20, TRUE
   ' new
   ' Trackbar_SetTicfreq hTrackBar, 2, 0 ' doesnt exist in cWindow ?
   ' SendMessageW hTrackBar, TBM_SETTICFREQ, 2,0 ' included in cWindow or commctrl ?

thanks, frank   

José Roca

Yes, it does exist, but it has one parameter, not two. It is in AfxCtl.inc.

' ========================================================================================
' Sets the interval frequency for tick marks in a trackbar.
' ========================================================================================
PRIVATE SUB Trackbar_SetTicFreq (BYVAL hTrackbar AS HWND, BYVAL wFreq AS WORD)
   SendMessageW(hTrackbar, TBM_SETTICFREQ, cast(WPARAM, wFreq), 0)
END SUB
' ========================================================================================