Flat Scroll Bar Common Control

.

  Download Source Code and Example

Environment: VC++ 5.0 SP3, commctrl.dll 4.71 or above.
Up to date commctrl.h/comctl32.lib (From Latest Platform SDK)

Microsoft. Internet Explorer Version 4.0 introduces a new visual technology called flat scroll bars. Functionally, flat scroll bars behave just like normal scroll bars. The only difference is they are not displayed three-dimensionally. Flat scroll bar APIs are implemented in version 4.71 and later of Comctl32.dll.

Here's a Thin Wrapper around the Flat ScrollBar API.


Header File


class CFlatScrollBar 
{
// Construction
public:
	CFlatScrollBar();

// Attributes
public:
	CWnd *m_pWnd;

// Operations
public:
	BOOL EnableScrollBar(int, UINT);
	BOOL ShowScrollBar(int code, BOOL);

	BOOL GetScrollRange(int code, LPINT, LPINT);
	BOOL GetScrollInfo(int code, LPSCROLLINFO);
	int  GetScrollPos(int code);
	BOOL GetScrollProp(int propIndex, LPINT);

	int  SetScrollPos(int code, int pos, BOOL fRedraw);
	int  SetScrollInfo(int code, LPSCROLLINFO, BOOL fRedraw);
	int  SetScrollRange(int code, int min, int max, BOOL fRedraw);
	BOOL SetScrollProp(UINT index, int newValue, BOOL);

	BOOL InitializeFlatSB(CWnd *);
	HRESULT UninitializeFlatSB();

// Implementation
public:
	virtual ~CFlatScrollBar();

protected:
};

Implementation File


CFlatScrollBar::CFlatScrollBar()
{
	m_pWnd = NULL;
}

CFlatScrollBar::~CFlatScrollBar()
{
	m_pWnd = NULL;
}

/////////////////////////////////////////////////////////////////////////////
// CFlatScrollBar message handlers

BOOL CFlatScrollBar::EnableScrollBar(int wSBflags,UINT wArrows)
{
	return ::FlatSB_EnableScrollBar(m_pWnd->GetSafeHwnd(),wSBflags,wArrows);
}

BOOL CFlatScrollBar::ShowScrollBar(int code, BOOL bShow)
{
	return ::FlatSB_ShowScrollBar(m_pWnd->GetSafeHwnd(),code, bShow);
}

BOOL CFlatScrollBar::GetScrollRange(int code, LPINT lpMinPos, LPINT lpMaxPos)
{
	return ::FlatSB_GetScrollRange(m_pWnd->GetSafeHwnd(),code,lpMinPos,lpMaxPos);
}

BOOL CFlatScrollBar::GetScrollInfo(int code, LPSCROLLINFO lpsi)
{
	return ::FlatSB_GetScrollInfo(m_pWnd->GetSafeHwnd(),code,lpsi);
}

int  CFlatScrollBar::GetScrollPos(int code)
{
	return ::FlatSB_GetScrollPos(m_pWnd->GetSafeHwnd(),code);
}

BOOL CFlatScrollBar::GetScrollProp(int propIndex, LPINT pValue)
{
	return ::FlatSB_GetScrollProp(m_pWnd->GetSafeHwnd(),propIndex, pValue);
}

int  CFlatScrollBar::SetScrollPos(int code, int pos, BOOL fRedraw)
{
	return ::FlatSB_SetScrollPos(m_pWnd->GetSafeHwnd(),code,pos,fRedraw);
}

int  CFlatScrollBar::SetScrollInfo(int code, LPSCROLLINFO lpsi, BOOL fRedraw)
{
	return ::FlatSB_SetScrollInfo(m_pWnd->GetSafeHwnd(),code,lpsi,fRedraw);
}

int  CFlatScrollBar::SetScrollRange(int code, int min, int max, BOOL fRedraw)
{
	return ::FlatSB_SetScrollRange(m_pWnd->GetSafeHwnd(),code,min,max,fRedraw);
}

BOOL CFlatScrollBar::SetScrollProp(UINT index, int newValue, BOOL fRedraw)
{
	return ::FlatSB_SetScrollProp(m_pWnd->GetSafeHwnd(),index,newValue,fRedraw);
}

BOOL CFlatScrollBar::InitializeFlatSB(CWnd *pWnd)
{
	m_pWnd = pWnd;
	return ::InitializeFlatSB(pWnd->GetSafeHwnd());
}

HRESULT CFlatScrollBar::UninitializeFlatSB()
{
	return ::UninitializeFlatSB(m_pWnd->GetSafeHwnd());
}

To use CFlatScrollBar on a CEdit Control inside a CDialog:

BOOL CFlatScrollDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	...
	scrollbar.InitializeFlatSB(&m_edit);
	scrollbar.EnableScrollBar(SB_BOTH,ESB_ENABLE_BOTH);
	...
}

Last updated: 16 June 1998



Comments

  • bug

    Posted by jundax on 07/08/2005 06:26am

    Platform: VC .NET | Windows XP BUG: when typing Flat style becomes normal. :(

    Reply
  • What about scrollbar controls inserted into a dialog box !

    Posted by Legacy on 11/27/2002 12:00am

    Originally posted by: Mike Marquet

    I have inserted an horizontal scrollbar into your test application and tried to make same flat.

    Doesn't works.

    I have make it so :

    horz.InitializeFlatSB( GetDlgItem(IDSB_HORZ) );
    horz.EnableScrollBar(SB_BOTH,ESB_ENABLE_BOTH);

    Reply
  • Help me change pallete

    Posted by Legacy on 08/30/2002 12:00am

    Originally posted by: Yoo

    I want to color of scrollbar.
    How can I change color of scrollbar.
    In msdn,
    BOOL FlatSB_SetScrollProp(
    HWND hwnd,
    UINT index,
    INT_PTR newValue,
    BOOL fRedraw
    );
    I find WSB_PROP_PALETTE for index.
    It seems to change color of scrollbar.
    Who don't know the solution of this?

    Reply
  • Anyone try to change the pallette?

    Posted by Legacy on 06/10/2002 12:00am

    Originally posted by: John

    I added the following:
    
    

    CPalette pal;

    LPLOGPALETTE lpLogPal = (LPLOGPALETTE)new
    BYTE[sizeof(LOGPALETTE) + 20 * sizeof(PALETTEENTRY)];
    lpLogPal->palNumEntries = 20;
    lpLogPal->palVersion = 0x300;
    for (int i = 0; i < 20; i++)
    {
    lpLogPal->palPalEntry[i].peRed = i * 10;
    lpLogPal->palPalEntry[i].peBlue = 0;
    lpLogPal->palPalEntry[i].peGreen = 0;
    lpLogPal->palPalEntry[i].peFlags = 0;
    }

    pal.CreatePalette(lpLogPal);

    CFlatScrollBar::SetScrollProp(WSB_PROP_PALETTE,
    (int)(HPALETTE)pal.Detach());


    But the colors don't change. I can use WSB_PROP_VBKGDCOLOR just fine.

    Suggestions?

    Reply
  • Does not work with List Box

    Posted by Legacy on 05/31/2002 12:00am

    Originally posted by: Pauli

    It does not work with List Box.

    Reply
  • Can't move scrollbar in CListCtrl :(

    Posted by Legacy on 02/05/2002 12:00am

    Originally posted by: 111222

    like title:(

    Reply
  • Can Flat Scrollbar be used with Windows Common Controls

    Posted by Legacy on 01/08/2002 12:00am

    Originally posted by: Ravi

    Can this FlatSb be used with other Common Controls like TreeView, ListView etc ?
    Can we subclass these controls and use custom Scrollbars with them ?

    Ravi

    Reply
  • A job well done!!!!!

    Posted by Legacy on 10/15/2001 12:00am

    Originally posted by: Prashanth Kamath

    this was a ver neatly done job. thanks a lot

    Reply
  • greate job!! (clear work..)

    Posted by Legacy on 06/06/2001 12:00am

    Originally posted by: Kwon Jinho

    Window 2000, VC6.0, SP5.0 (not import SDK )

    Thanks your wapper class..
    That's clear work..

    => if source doesn't work..
    => then, not modify WM_VSCROLL & WM_HSCROLL event handler..
    => override OnVScroll and OnHScroll

    Thanks..

    Reply
  • It Works!!!! Checked with NT4.0/SP4/VC++5.0/Platform SDK (Jan98)

    Posted by Legacy on 12/29/1998 12:00am

    Originally posted by: Davanum Srinivas

    Hi,

    Can you please explain what you meant by

    "missing of the core d=code fonctions"

    I just checked the sample code which can be downloaded on the platform mentioned above. Please be specific in your comments so that others can understand as to whether there was problem compiling or running the program.

    -- dims

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds