Jump to content
Tuts 4 You

VLC like seek bar


LulzCoder

Recommended Posts

LulzCoder
Posted (edited)

Anyone know how to make a VLC like seek bar in plain Win32 C without using QT or MFC?

Or skinning a slider control to like it.

Edited by LulzCoder
Posted

What's wrong with the slider control?

Greetings

Posted

Without QT or MFC? That questions is pretty strange. Why wouldn't you use MFC as all normal people?! Try other window UI frameworks. There are planty of them for C.


Posted

Why wouldn't you use MFC as all normal people?!

Damn, I thought I was normal...

  • Like 2
Posted

@dn5: I guess he is not using MFC because it's classes are pretty ugly to use[infact for me], needs more dependency.

@exodia: Using slider control as a seek bar is not a good idea, because slider control is not precise with clicks. As in a normal seek bar if we click then bar[thumb] directly jumps there, but in a standard slider control when we click the thumb goes only to the next tick.

Posted

I just played with a dialog app/ The dialog only contains a slider control, named IDC_SLIDER1.


 


The client are of the slider is 20 pixels wider than the horizontal track draw in it. As a consequence, the range of motion is the width of the slider - 20 pixels.


This also means that the smallest value of the slider will occur when the 10 pixels to the right of the control's left edge. That's why the hard-coded values of 10 and 20 have been chosen. Obviously, they shouldn't be hard-coded..


 


 




#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include "resource.h"
HINSTANCE hInst;
int sliderWidth;
long oldProc;
LRESULT CALLBACK sliderWindowProc(HWND hwndSlider, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
        case WM_LBUTTONDOWN:
            PostMessage(hwndSlider, TBM_SETPOS, true, LOWORD(lParam-10));
            return 0;
        case WM_MOUSEMOVE:
                if (wParam & MK_LBUTTON)
                {
                    PostMessage(hwndSlider, TBM_SETPOS, true, LOWORD(lParam-10));
                    return 0;
                }
    }
    return CallWindowProc( (WNDPROC)oldProc, hwndSlider, uMsg, wParam, lParam);
}
BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    RECT mRect;
    HWND slider;
    switch(uMsg)
    {
    case WM_INITDIALOG:
    {
            slider = GetDlgItem(hwndDlg, IDC_SLIDER1);
            oldProc = GetWindowLong(slider, GWL_WNDPROC);
            SetWindowLong(slider, GWL_WNDPROC, (long)sliderWindowProc);
            GetClientRect( GetDlgItem(hwndDlg, IDC_SLIDER1), &mRect);
            sliderWidth = (mRect.right - mRect.left) - 20;
            printf("Slider Width (pixels): %d\n", sliderWidth);
            SendDlgItemMessage(hwndDlg, IDC_SLIDER1, TBM_SETRANGE, true, MAKELONG(0,sliderWidth));
  //          SendDlgItemMessage(hwndDlg, IDC_SLIDER1, TBM_SETPAGESIZE, 0, 1);
            SendDlgItemMessage(hwndDlg, IDC_SLIDER1, TBM_SETTICFREQ, 1, 0);
    }
    return TRUE;
    case WM_CLOSE:
    {
        EndDialog(hwndDlg, 0);
    }
    return TRUE;
    case WM_COMMAND:
    {
        switch(LOWORD(wParam))
        {
        }
    }
    return TRUE;
    }
    return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    hInst=hInstance;
    InitCommonControls();
    return DialogBox(hInst, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain);
}


 


  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...