Click here to Skip to main content
Click here to Skip to main content

A cool bitmap slider like Media Player's...

, 23 Jul 2004
Rate this:
Please Sign up or sign in to vote.
A cool bitmap slider like Windows Media Player's.

Sample Image - CoolSlider.gif


Do you like the cool slider in Windows Media Player 9.0? Yes!!

Let's build it, following this article.

Used custom classes

  • CBitItem

    Inherits none. Manages bitmap resources, one or more bitmaps.

  • CBitWnd

    Inherits CWnd. Manages owner draw bitmap window.

  • CBitSlider

    Inherits CSliderCtrl. Manages owner draw bitmap slider.

By the way:

CBitItem and CBitWnd are common tool classes for any place where you want to make bitmap owner draw window...

Sample demo code

Step 1: Get the hand cursor from OS
HCURSOR    CCoolSliderDlg::GetSysHandCursor()
    TCHAR        strWinDir[MAX_PATH] = {0};
    HCURSOR        hHandCursor    = NULL;
    hHandCursor = ::LoadCursor(NULL, MAKEINTRESOURCE(32649));
    // Still no cursor handle - load the WinHelp hand cursor
    if( hHandCursor == NULL )
        GetWindowsDirectory(strWinDir, MAX_PATH);
        strcat(strWinDir, _T("\\winhlp32.exe"));
        // This retrieves cursor #106 from winhlp32.exe,
        // which is a hand pointer
        HMODULE hModule = ::LoadLibrary(strWinDir);
        DWORD    dwErr = GetLastError();
        if( hModule != NULL )
            HCURSOR     hTempCur = ::LoadCursor(hModule, MAKEINTRESOURCE(106));
            hHandCursor = (hTempCur != NULL) ? CopyCursor(hTempCur) : NULL;
    return hHandCursor;
Step 2: Build a cool-slider using exclusive bitmap resource
void CCoolSliderDlg::BuildCoolSlider()
    m_hHandCur = this->GetSysHandCursor();
    ASSERT( m_hHandCur != NULL );
    m_ctlSlider.BuildThumbItem(IDB_BITMAP_THUMB, 6, 12);
    m_ctlSlider.BuildBackItem(IDB_BITMAP_NORMAL, IDB_BITMAP_ACTIVE);
    m_ctlSlider.SetRange(0, 100);
Step 3: Build some cool-sliders using shared bitmap resource (3 sliders use the same bitmap resource)
void CCoolSliderDlg::BuildShareSlider()
    ASSERT( m_hHandCur != NULL );

    ASSERT( m_lpActive == NULL );
    ASSERT( m_lpNormal == NULL );
    ASSERT( m_lpThumb == NULL );

    m_lpActive = new CBitItem(IDB_BITMAP_ACTIVE, 0, 0);
    m_lpNormal = new CBitItem(IDB_BITMAP_NORMAL, 0, 0);
    m_lpThumb  = new CBitItem(IDB_BITMAP_THUMB, 6, 12);

    m_ctlShare1.BuildBackItem(m_lpNormal, m_lpActive);
    m_ctlShare1.SetRange(0, 100);

    m_ctlShare2.BuildBackItem(m_lpNormal, m_lpActive);
    m_ctlShare2.SetRange(0, 100);

    m_ctlShare3.BuildBackItem(m_lpNormal, m_lpActive);
    m_ctlShare3.SetRange(0, 100);
Step 4: Erase the dialog background using slider bitmap's back-color
BOOL CCoolSliderDlg::OnEraseBkgnd(CDC* pDC) 
    CRect    rcRect;
    pDC->FillSolidRect(rcRect, RGB(96, 123, 189));

    return TRUE;
Step 5: Release all the allocated resources when program exits
    if( m_lpNormal != NULL )
        delete m_lpNormal;
        m_lpNormal = NULL;
    if( m_lpActive != NULL )
        delete m_lpActive;
        m_lpActive = NULL;
    if( m_lpThumb != NULL )
        delete m_lpThumb;
        m_lpThumb = NULL;

Want to know more detail? Please see the demo project!!

Bug report or comments, please contact me: Jackey.

Enjoy it!!


  • 07/24/2004

    First version... (Only supports horizontal sliderSmile | :) )

  • 07/25/2004

    Added vertical slider support, thanks for PJ Arends.

  • To be continued...


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Web Developer
China China
Hello everybody!!

Comments and Discussions

GeneralMy vote of 4 Pinmemberlanyuliuyun19-Aug-10 18:57 
Generalwonderful! Pinmemberhuangzongwu21-Oct-09 21:06 
General.Net dll [modified] Pinmemberjen0s7-Sep-07 5:37 
GeneralCrash moving the slider PinmemberSbarBaz30-May-06 4:03 
QuestionLoading Bitmaps from Outside PinmemberManni Singh19-Apr-06 19:05 
GeneralThank you for your article PinmemberEinst29-Jan-06 11:50 
GeneralSlider dimensions Pinmembercamillo2-Sep-04 22:53 
GeneralNice Start PinmemberPJ Arends24-Jul-04 13:23 
GeneralRe: Nice Start Pinmemberjackey_xp24-Jul-04 18:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 24 Jul 2004
Article Copyright 2004 by jackey_xp
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid