//----------------------------------------------------------------------------------------------------------------- //WTLExplorer : WTLized version of the explorer sample from MSDN. // Use this code at your own risk. We wrote it just for fun :-) // Tested *only* on Win2k. Requires Platform SDK headers. // // //----------------------------------------------------------------------------------------------------------------- #pragma once #ifndef _EXPLORER_LEFTPANE_H_ #define _EXPLORER_LEFTPANE_H_ template < typename TContainedWindow = CTreeViewCtrlEx, typename ChainClass > class CFolderBarWindow: public CWindowImpl { public: CFolderBarWindow(ChainClass *pChainClass):m_pChainClass(pChainClass),m_hFont(0),m_hBrush(0),m_hPen(0) { m_hBrush = ::CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); m_hPen = ::CreatePen(PS_SOLID,1,GetSysColor(COLOR_3DSHADOW)); m_hFont = ::CreateFont( 3, 0, 0, 0, FW_NORMAL, FALSE,FALSE,FALSE,ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,DEFAULT_PITCH, _T("Ms Sans Serif") ); } ~CFolderBarWindow() { if(m_hFont) { ::DeleteObject(m_hFont); m_hFont = NULL; } if(m_hBrush) { DeleteObject(m_hBrush);m_hBrush = 0; } if(m_hPen) { DeleteObject(m_hPen);m_hPen = 0; } } BEGIN_MSG_MAP(CFolderBarWindow) MESSAGE_HANDLER(WM_CREATE, OnCreate) MESSAGE_HANDLER(WM_PAINT, OnPaint) MESSAGE_HANDLER(WM_SIZE, OnSize) if(uMsg == WM_NOTIFY && m_pChainClass && m_pChainClass->IsWindow()) CHAIN_MSG_MAP_MEMBER((*m_pChainClass)) END_MSG_MAP() LRESULT OnPaint(UINT , WPARAM , LPARAM , BOOL& bHandled) { PAINTSTRUCT ps; HDC hDC = BeginPaint(&ps); DrawCaption(hDC); EndPaint(&ps); bHandled = FALSE; return 0L; } LRESULT OnCreate(UINT , WPARAM , LPARAM , BOOL& bHandled) { m_wndContained.Create(m_hWnd,CWindow::rcDefault,NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | TVS_SHOWSELALWAYS, WS_EX_CLIENTEDGE); return 0L; } LRESULT OnSize(UINT , WPARAM wParam, LPARAM , BOOL& bHandled) { if(wParam != SIZE_MINIMIZED) { RECT rc;GetClientRect(&rc); rc.top = rc.top + GetSystemMetrics(SM_CYCAPTION) + 4; m_wndContained.SetWindowPos(HWND_TOP,&rc,SWP_NOZORDER); } bHandled = FALSE; return 1; } void DrawCaption(const HDC& hDC) { const c_maxlen = 256; RECT rc1,rc2; GetWindowRect((LPRECT)&rc2 ); rc1.left = 2; rc1.top = 1; rc1.right = rc2.right - rc2.left - 1; rc1.bottom = GetSystemMetrics(SM_CYCAPTION) + 4; SetBkMode(hDC,TRANSPARENT); SetBkColor( hDC, GetSysColor(COLOR_BTNFACE)); SetTextColor(hDC,GetSysColor(COLOR_BTNTEXT)); CComBSTR strTemp; GetWindowText(&strTemp); CComBSTR strTitle = _T("Folders"); strTitle += strTemp; HBRUSH hOldBr = (HBRUSH)::SelectObject(hDC,m_hBrush); HFONT hFontOld = (HFONT)::SelectObject(hDC,m_hFont); HPEN hOldPen = (HPEN)::SelectObject(hDC,m_hPen); //Draw the rect with DKGray pen and brush ::Rectangle(hDC,2,2,rc1.right,rc1.bottom); ::DrawEdge(hDC,&rc1,EDGE_ETCHED,BF_RECT); USES_CONVERSION; ::TextOut(hDC,5,5,OLE2T(strTitle),strTitle.Length()); ::SelectObject(hDC,hOldBr); ::SelectObject(hDC,hOldPen); ::SelectObject(hDC,hFontOld); } public: TContainedWindow m_wndContained; ChainClass *m_pChainClass; private: HPEN m_hPen; HBRUSH m_hBrush; HFONT m_hFont; }; #endif