|
Using this code replace CXPToolbar with CToolbarXP is better
This is code of CToolbarXP.cpp and replace XPToolbar.h with ToolbarXP.h
///////////////////////////////////////////////////////////////////////////////
//
// ToolBarXP.cpp: implementation of the CToolBarXP class.
//
///////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ToolBarXP.h"
#include "Draw.h"
#pragma warning(disable : 4244)
#pragma message("You are using CToolBarXP")
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
///////////////////////////////////////////////////////////////////////////////
CToolBarXP::CToolBarXP () : m_bCheckVisibility (false)
{
}
///////////////////////////////////////////////////////////////////////////////
BOOL CToolBarXP::LoadToolBar (UINT nIDResource)
{
if ( !CToolBar::LoadToolBar (nIDResource) )
{
return false;
}
SetBorders (CRect(2,2,3,2));
SendMessage (TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_DRAWDDARROWS);
return true;
}
///////////////////////////////////////////////////////////////////////////////
bool CToolBarXP::InsertControl (int nIndex, CWnd& Ctrl)
{
TBBUTTON tbbutton;
int nCount = DefWindowProc (TB_BUTTONCOUNT, 0, 0);
CWindowRect rcCtrl (Ctrl);
tbbutton.iBitmap = rcCtrl.Width();
tbbutton.idCommand = Ctrl.GetDlgCtrlID();
tbbutton.fsState = 0;
tbbutton.fsStyle = TBSTYLE_SEP;
tbbutton.bReserved[0] = 0;
tbbutton.bReserved[1] = 0;
tbbutton.iString = -1;
tbbutton.dwData = NULL;
if ( nIndex < 0 || nIndex > nCount )
{
nIndex = nCount;
}
if ( GetToolBarCtrl().InsertButton (nIndex, &tbbutton) )
{
m_bDelayedButtonLayout = true;
return true;
}
return false;
}
///////////////////////////////////////////////////////////////////////////////
LRESULT CToolBarXP::DefWindowProc (UINT nMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT lRes = CToolBar::DefWindowProc (nMsg, wParam, lParam);
if ( m_bCheckVisibility && nMsg == TB_GETBUTTON )
{
TBBUTTON* pButton = (TBBUTTON*)lParam;
if ( IS_CONTROL(*pButton) )
{
if ( m_bCheckVisibility == 1 ) pButton->fsState |= TBSTATE_HIDDEN;
else pButton->fsState &= ~TBSTATE_HIDDEN;
}
}
return lRes;
}
///////////////////////////////////////////////////////////////////////////////
CSize CToolBarXP::CalcDynamicLayout (int nLength, DWORD dwMode)
{
bool bHideControls = (dwMode & LM_VERTDOCK) == LM_VERTDOCK;
m_bCheckVisibility = (BYTE)(bHideControls ? 1 : 2);
CSize size = CToolBar::CalcDynamicLayout (nLength, dwMode);
m_bCheckVisibility = false;
if ( dwMode & LM_COMMIT )
{
TBBUTTON tbbutton;
int nCount = DefWindowProc (TB_BUTTONCOUNT, 0, 0);
for ( int i = 0; i < nCount; i++ )
{
VERIFY(DefWindowProc (TB_GETBUTTON, i, (LPARAM)&tbbutton));
if ( !IS_CONTROL(tbbutton) )
{
continue;
}
CWnd* pWnd = GetDlgItem (tbbutton.idCommand);
if ( pWnd == NULL )
{
continue;
}
if ( bHideControls )
{
GetToolBarCtrl().HideButton (tbbutton.idCommand, true);
pWnd->ShowWindow (SW_HIDE);
}
else
{
GetToolBarCtrl().HideButton (tbbutton.idCommand, false);
// Update control position
CRect rcControl;
VERIFY (DefWindowProc (TB_GETITEMRECT, i, (LPARAM)&rcControl));
rcControl.DeflateRect (1, 1);
CWindowRect rcCtrl (pWnd);
int nNoSize = 0;
if ( rcControl.Width() == rcCtrl.Width() )
{
nNoSize = SWP_NOSIZE;
}
pWnd->SetWindowPos (NULL, rcControl.left, rcControl.top, rcControl.Width(), rcControl.Height(),
nNoSize|SWP_NOACTIVATE|SWP_NOZORDER|SWP_SHOWWINDOW);
}
}
}
return size;
}
///////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CToolBarXP, CToolBar)
ON_WM_NCPAINT()
ON_WM_NCCALCSIZE()
ON_WM_PAINT()
ON_NOTIFY_REFLECT(TBN_DROPDOWN, OnButtonDropDown)
END_MESSAGE_MAP()
IMPLEMENT_DYNAMIC(CToolBarXP, CToolBar)
///////////////////////////////////////////////////////////////////////////////
// Paint the toolbar
void CToolBarXP::OnPaint ()
{
if ( m_bDelayedButtonLayout )
{
Layout();
}
CPaintDC cDC (this);
CRect rcClip;
cDC.GetClipBox (rcClip);
cDC.SetBkMode (TRANSPARENT);
cDC.SelectObject (CFont::FromHandle ((HFONT)GetStockObject (DEFAULT_GUI_FONT)));
cDC.FillSolidRect (rcClip, HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), 20, 0));
CPoint ptCursor;
::GetCursorPos (&ptCursor);
ScreenToClient (&ptCursor);
CClientRect rcClient (this);
HIMAGELIST m_hImageList = (HIMAGELIST)DefWindowProc (TB_GETIMAGELIST, 0, 0);
TBBUTTON tbbutton;
int nCount = DefWindowProc (TB_BUTTONCOUNT, 0, 0);
int nHotItem = GetToolBarCtrl().GetHotItem();
for ( int i = 0; i < nCount; i++ )
{
VERIFY(DefWindowProc (TB_GETBUTTON, i, (LPARAM)&tbbutton));
if ( !IS_VISIBLE(tbbutton) )
{
continue;
}
CRect rcButton;
VERIFY(DefWindowProc (TB_GETITEMRECT, i, (LPARAM)&rcButton));
if ( !CRect().IntersectRect (rcClip, rcButton) )
{
continue;
}
bool bOver = nHotItem == i && IS_ENABLED(tbbutton);
bool bPressed = false;
if ( IS_INDETERMINATE(tbbutton) )
{
CPenDC pen (cDC, ::GetSysColor (COLOR_3DSHADOW));
cDC.MoveTo (rcButton.left, rcButton.bottom);
cDC.LineTo (rcButton.left, rcButton.top);
cDC.LineTo (rcButton.right-1, rcButton.top);
cDC.LineTo (rcButton.right-1, rcButton.bottom-1);
cDC.LineTo (rcButton.left, rcButton.bottom-1);
bOver = true;
}
else if ( bOver || IS_CHECKED(tbbutton) )
{
bPressed = KEYDOWN(VK_LBUTTON) && rcButton.PtInRect (ptCursor);
if ( IS_DROPDOWN(tbbutton) && bPressed )
{
bPressed = ptCursor.x < rcButton.right-13;
if ( bPressed )
{
rcButton.right -= 13;
}
}
COLORREF crHighLight = ::GetSysColor (COLOR_HIGHLIGHT);
CPenDC pen (cDC, crHighLight);
CBrushDC brush (cDC, bPressed||(bOver&&IS_CHECKED(tbbutton)) ? HLS_TRANSFORM (crHighLight, +50, -50) : (bOver ? HLS_TRANSFORM (crHighLight, +70, -57) : HLS_TRANSFORM (crHighLight, +80, -66)));
cDC.Rectangle (&rcButton);
if ( IS_DROPDOWN(tbbutton) )
{
if ( bPressed )
{
int nLeft = rcButton.left;
rcButton.left = rcButton.right-1;
rcButton.right += 13;
brush.Color (HLS_TRANSFORM (crHighLight, +70, -66));
cDC.Rectangle (&rcButton);
rcButton.left = nLeft;
}
else
{
cDC.MoveTo (rcButton.right-14, rcButton.top);
cDC.LineTo (rcButton.right-14, rcButton.bottom);
}
}
}
if ( IS_SEPARATOR(tbbutton) )
{
CPenDC pen (cDC, HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), -15, 0));
if ( IS_WRAP(tbbutton) )
{
cDC.MoveTo (rcClient.left+2, rcButton.bottom-4);
cDC.LineTo (rcClient.right-2, rcButton.bottom-4);
}
else
{
cDC.MoveTo ((rcButton.right+rcButton.left)/2-1, rcButton.top+2);
cDC.LineTo ((rcButton.right+rcButton.left)/2-1, rcButton.bottom-2);
}
}
else if ( !IS_CONTROL(tbbutton) )
{
if ( IS_DROPDOWN(tbbutton) )
{
CPenDC pen (cDC, ( bOver && !IS_INDETERMINATE(tbbutton) ) ? RGB(0,0,0) : ::GetSysColor (IS_ENABLED(tbbutton) ? COLOR_BTNTEXT : COLOR_GRAYTEXT));
cDC.MoveTo (rcButton.right-9, (rcButton.top+rcButton.bottom)/2-1);
cDC.LineTo (rcButton.right-4, (rcButton.top+rcButton.bottom)/2-1);
cDC.MoveTo (rcButton.right-8, (rcButton.top+rcButton.bottom)/2);
cDC.LineTo (rcButton.right-5, (rcButton.top+rcButton.bottom)/2);
cDC.SetPixel (rcButton.right-7, (rcButton.top+rcButton.bottom)/2+1, pen.Color());
rcButton.right -= 14;
}
if ( tbbutton.iBitmap >= 0 )
{
if ( !IS_ENABLED(tbbutton) || (bOver && !bPressed) )
{
HICON hIcon = ImageList_ExtractIcon (NULL, m_hImageList, tbbutton.iBitmap);
cDC.DrawState (CPoint (rcButton.left + ( bOver ? 4 : 3 ), rcButton.top + ( bOver ? 4 : 3 )), m_sizeImage, hIcon, DSS_MONO, CBrush (bOver ? (IS_INDETERMINATE(tbbutton) ? HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), -20, 0) : HLS_TRANSFORM (::GetSysColor (COLOR_HIGHLIGHT), +50, -66)) : HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), -27, 0)));
DestroyIcon (hIcon);
}
if ( IS_ENABLED(tbbutton) )
{
::ImageList_Draw (m_hImageList, tbbutton.iBitmap, cDC.m_hDC,
rcButton.left + ( (bOver && !bPressed) ? 2 : 3 ), rcButton.top + ( (bOver && !bPressed) ? 2 : 3 ), ILD_TRANSPARENT);
}
}
}
}
}
///////////////////////////////////////////////////////////////////////////////
void CToolBarXP::OnButtonDropDown (NMHDR* lpnmhdr, LRESULT* plResult)
{
LPNMTOOLBAR lpnmtb = (LPNMTOOLBAR)lpnmhdr;
*plResult = TBDDRET_DEFAULT;
if ( !m_pDockSite->SendMessage (WM_COMMAND, DROPDOWN(lpnmtb->iItem)) )
{
*plResult = TBDDRET_TREATPRESSED;
}
}
void CToolBarXP::OnNcPaint()
{
EraseNonClient(); //don't do it here
}
void CToolBarXP::DrawGripper(CWindowDC *pDC, CRect& rectWindow)
{
// get the gripper rect (1 pixel smaller than toolbar)
CRect gripper = rectWindow;
//Disable these line to disable the XP Gripper
if (m_brGripperHorz.GetSafeHandle () == NULL)
{
CreateGripperBrush ();
}
pDC->FillSolidRect(gripper, HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), 20, 0));
//pDC->FillSolidRect(gripper, ::GetSysColor (COLOR_BTNFACE));//Enable this to get the classic color
if (m_dwStyle & CBRS_FLOATING)
{ // no grippers
}
else if (m_dwStyle & CBRS_ORIENT_HORZ)
{ // gripper at left
gripper.right = gripper.left+3;
//pDC->Draw3dRect(gripper,::GetSysColor(COLOR_3DHIGHLIGHT),::GetSysColor(COLOR_3DSHADOW));//Enable this to get the classic gripper
gripper.OffsetRect(+4,0);
gripper.DeflateRect(0,6);
pDC->FillRect (gripper,&m_brGripperHorz);//Disable This to disable the XP Gripper
rectWindow.left += 8;
} else
{ // gripper at top
gripper.bottom = gripper.top+3;
//pDC->Draw3dRect(gripper,::GetSysColor(COLOR_3DHIGHLIGHT),::GetSysColor(COLOR_3DSHADOW));//Enable this to get the classic look
gripper.OffsetRect(0,+4);
gripper.DeflateRect(6,0);
pDC->FillRect (gripper,&m_brGripperVert);//Disable this to disable the XP Gripper
rectWindow.top += 8;
}
}
void CToolBarXP::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
{
CToolBar::OnNcCalcSize(bCalcValidRects,lpncsp);
// adjust non-client area for gripper at left or top
if (m_dwStyle & CBRS_FLOATING)
{ // no grippers
}
else if (m_dwStyle & CBRS_ORIENT_HORZ)
{
// let's move a little to make some space
lpncsp->rgrc[0].left += 0;
lpncsp->rgrc[0].right += 3;
lpncsp->rgrc[0].top += -1;
lpncsp->rgrc[0].bottom += 2;
}
else
{ // now moving down
lpncsp->rgrc[0].top += 4;
lpncsp->rgrc[0].bottom += 5;
}
}
void CToolBarXP::EraseNonClient(/*BOOL bRaised*/)
{
// get window DC that is clipped to the non-client area
CWindowDC dc(this);
CRect rectClient;
GetClientRect(rectClient);
CRect rectWindow;
GetWindowRect(rectWindow);
ScreenToClient(rectWindow);
rectClient.OffsetRect(-rectWindow.left, -rectWindow.top);
dc.ExcludeClipRect(rectClient); // draw borders in non-client area
rectWindow.OffsetRect(-rectWindow.left, -rectWindow.top);
DrawBorders(&dc, rectWindow); // erase parts not drawn
dc.IntersectClipRect(rectWindow);
SendMessage(WM_ERASEBKGND, (WPARAM)dc.m_hDC);
dc.SetBkColor(::GetSysColor(COLOR_3DFACE));
DrawGripper(&dc, rectWindow); // lets draw some grippers
}
void CToolBarXP::DrawBorders(CDC* pDC, CRect& rect)
{
ASSERT_VALID(this);
ASSERT_VALID(pDC);
DWORD dwStyle = m_dwStyle;
if (!(dwStyle & CBRS_BORDER_ANY))
return;
// prepare for dark lines
ASSERT(rect.top == 0 && rect.left == 0);
COLORREF clr = ::GetSysColor(COLOR_BTNFACE);
if(dwStyle&CBRS_BORDER_RIGHT)
pDC->FillSolidRect(rect.right,0,-1,rect.Height(),clr); //right
if(dwStyle&CBRS_BORDER_BOTTOM)
pDC->FillSolidRect(0,rect.Width()-1, -1,rect.bottom,clr); //bottom
if(dwStyle&CBRS_BORDER_TOP)
pDC->FillSolidRect(0,0,rect.Width()-1 ,1,clr); //top
if(dwStyle&CBRS_BORDER_LEFT)
pDC->FillSolidRect(0,0,1,rect.Height() - 1,clr); //left
if(dwStyle&CBRS_BORDER_TOP)
++rect.top;
if(dwStyle&CBRS_BORDER_RIGHT)
--rect.right;
if(dwStyle&CBRS_BORDER_BOTTOM)
--rect.bottom;
if(dwStyle&CBRS_BORDER_LEFT)
++rect.left;
}
// This will make the XP style grippers, COOOL
void CToolBarXP::CreateGripperBrush ()
{
ASSERT (m_brGripperHorz.GetSafeHandle () == NULL);
ASSERT (m_brGripperVert.GetSafeHandle () == NULL);
WORD horzHatchBits [8] = { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00 };
CBitmap bmpGripperHorz;
bmpGripperHorz.CreateBitmap (8, 8, 1, 1, horzHatchBits);
m_brGripperHorz.CreatePatternBrush (&bmpGripperHorz);
WORD vertHatchBits[8] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
CBitmap bmpGripperVert;
bmpGripperVert.CreateBitmap (8, 8, 1, 1, vertHatchBits);
m_brGripperVert.CreatePatternBrush (&bmpGripperVert);
}
Now the Toolbar is ok
|
|
|
|