Collapsible Panel control

Collapsible Panel control

This article was submitted .

This control acts somewhat like the Windows XP Collapsible Panel: the one in the left side of the Windows Explorer with the links and shortcuts.

The control can contain multiple views, slides up and down when you click on the header bars, and allows you to add title icons and custom expand/collapse buttons. Several style flags can be used to customize how the panels behave and are painted. Specifically you can also enjoy a "flat" look - like the non-themed version of Windows XP.

When you click on a panel, you'll receive a WM_COMMAND notification in the parent window telling you that a panel is being expanded or collapsed. Panels slide up and down using animation, however this feature can be turned off.

The control also supports an ownerdrawn style that allows you to catch WM_DRAWITEM messages to paint your own button graphics.

For performance reasons, the control internally renders and stores the button graphics in a bitmap, so it can be blitted to the screen as quickly as possible. To prevent flicker, a memory DC is used during the paint sequence.

How to use it

The control is designed to be used in a view - and not particular for placement in a dialog. Assuming that the project is built with a splitter style layout, or at least that the control will be placed in a separate view - create a view class looking like this...
#include "CollapsiblePanel.h"

class CMyView : 
   public CCollapsiblePanelImpl<CMyView>
   typedef CCollapsiblePanelImpl<CMyView> parentClass;

   BOOL PreTranslateMessage(MSG* pMsg)
      return FALSE;

      CHAIN_MSG_MAP( parentClass )

   LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& b)
      LRESULT lRes = parentClass::OnCreate(uMsg, wParam, lParam, b);

      InsertItem(m_view1, _T("File and Folder Tasks"));
      InsertItem(m_view2, _T("Details"));
      InsertItem(m_view3, _T("Links"));

      b = TRUE;
      return lRes;

Finally, create the view dialogs. Remove all border styles, captions, and make them CHILD forms. You must also add the "Clip Siblings" style (the WS_CLIPSIBLINGS style flag) because of rendering problems in Windows.

Source Code Dependencies

Microsoft Visual C++ 6.0
Microsoft WTL 7.0 Library

See Also

A nice MS Outlook Bar control

Useful Links

Chris Haarmeijer's extended version

Download Files

DownloadSource Code (38 Kb)

To the top