A Switcher Control (like the Windows Task Bar)

Environment: VC6 SP2, WinNT 4.0 SP3, Win98 GOLD

Ever since Windows 95 first came out, I have noticed that just about every developer was scambling to get all the new common controls and UI features into their applications... but it seems like nobody has yet to make a taskbar-like control. So I set out to make one.

After looking at how Microsoft made their task switcher control (they use a modified Tab Control), I decided to just use MFC and subclass a CWnd to make mine.

It was actually pretty simple to make. I simply subclassed a CWnd for the button - CSwitcherButton - and subclassed a window to manage the buttons - CSwitcherWnd.

To use, download the source or demo below and add CSwitcherButton.cpp, CSwitcherButton.h, CSwitcherWnd.cpp, and CSwitcherWnd.h to your project. Then, include CSwitcherWnd.h and CSwitcherButton.h in your window or dialog (or whatever file you want to use it in; it *must* be derived from CWnd, tho). An easy way to include these files globally is to include them in stdafx.h or YourApp.h.

To implement, simply create a CSwitcherWnd object, and call DoCreate.

Example:

(m_wndSwitcher created in the .h file)


m_wndSwitcher.DoCreate(this, 0, 200);

Which will create a switcher at the top of the window with width 200.

That about covers it. Enjoy.

Updates MON MAR 15 1999 - JIMMY BRUSH:

  • Fixed RemoveButton to correctly decrement selected button
  • Added CMemDC by Keith Rule
  • Fixed up Animation a bit

Download demo project - 32 KB

Download source - 8 KB



Comments

  • bugs in it.

    Posted by Legacy on 11/18/2000 12:00am

    Originally posted by: Johnthan

    sometime when u click the button "setsel", u can get it appeared.

    Reply
  • Request: modify so also works for CWnd subclassing

    Posted by Legacy on 12/17/1999 12:00am

    Originally posted by: Rick Shide

    It would be nice if you could modify CSwitcherButton so that it could be subclassed and used as a nice stand-alone button on a CDialog or CFormView.  Youl'd just need to init the m_wndParent == NULL in the constructor, and override PreSubclassWindow to set some specific stuff for normal subclassing:
    
    void CSwitcherButton::PreSubclassWindow()
    {
    if (!m_wndParent) { // normal subclassing
    m_wndParent = GetParent();
    }
    CWnd::PreSubclassWindow();
    }

    also need to figure out how to set the window text

    Reply
  • tab control

    Posted by Legacy on 03/25/1999 12:00am

    Originally posted by: James Kilts

    Yeah, windows does use the tab control with the "button look" style applied, but I like this one better.

    Reply
  • Docking/autohide

    Posted by Legacy on 03/24/1999 12:00am

    Originally posted by: Maxim A. Sidorov

    How do you feel about implementing smart docking/autohiding
    
    feature for control alike office bar and windows taskbar itself.
    Should be great!

    Reply
  • Switcher Control

    Posted by Legacy on 03/23/1999 12:00am

    Originally posted by: Rama Krishna

    Why not just use the tab control with button look style applied. That's what is task bar when looked under Spy++.

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

Top White Papers and Webcasts

  • Live Event Date: November 6, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds