📄 ooextoolbar.cpp
字号:
/********************************************************************
filename: d:\spatools\ooextoolbar.cpp
Copyright (c) 2003 Chao Zuo. All rights reserved.
Email: suncho@vip.sina.com
Notice: If this code works, it was written by Chao Zuo.
Else, I don't know who wrote it.
I Wrote this code for all software developers in civil engineering,
and hope it help you.
Have any question, please email me.
*********************************************************************/
#include "StdAfx.h"
// Base class definition.
#include "OOExToolBar.hpp"
// Math include file.
#include "math.h"
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Macro and other definition.
// ------------------------------------------------------------------------
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNAMIC( COOExToolBar, CToolBar )
BEGIN_MESSAGE_MAP( COOExToolBar, CToolBar )
//{{AFX_MSG_MAP( COOExToolBar )
ON_WM_NCCALCSIZE()
ON_WM_CREATE()
ON_WM_NCPAINT()
ON_WM_SYSCOLORCHANGE()
ON_WM_WINDOWPOSCHANGING()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Initialization and destruction method.
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (IMPLEMENTATION)
// <c COOExToolBar>
// This is the main constructor.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
COOExToolBar::COOExToolBar( void )
{
// Set the default flag.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
m_nShowIconMode = 0; // small icon.
m_bShowIconText = TRUE; // Text.
m_SmallIconSize = CSize( 16, 16 );
m_LargeIconSize = CSize( 32, 32 );
m_bOldFloating=false;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (IMPLEMENTATION)
// <c COOExToolBar>
// This is the main destructor.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
COOExToolBar::~COOExToolBar( void )
{
// Free the image list associated memory.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
for ( int i=0; i<NB_POSSIBLE_MODE; i++ )
{
if ( m_ImageList[ i ].GetSafeHandle() )
m_ImageList[ i ].DeleteImageList();
}
}
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Mode related method.
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// To view large or small icon.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void COOExToolBar::SetIconMode(
UINT _nShowIconMode ) // @Parm 0 Small Icon, 1 Large Icon, 2 Extra Large Icon.
{
// Store the new value.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
m_nShowIconMode = _nShowIconMode;
// Load the image list.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
AssignImageList();
// Resize the toolbar.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
ResizeToolBar();
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// To get the large or small icon mode.
// @RDesc 0 Small Icon, 1 Large Icon, 2 Extra Large Icon.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
UINT COOExToolBar::GetIconMode( void ) const
{
return m_nShowIconMode;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// To set the text on or off.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void COOExToolBar::SetTextMode(
bool _bShowIconText ) // @Parm True to view the text, false to hide it.
{
// Store the new value.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
m_bShowIconText = _bShowIconText;
// Resize the toolbar.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
ResizeToolBar();
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// To get the text on or off.
// @RDesc True if the text is on, False otherwise.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
bool COOExToolBar::GetTextMode( void ) const
{
return m_bShowIconText;
}
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Loading information.
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// To load the toolbar information.
// @RDesc True if the tool bar is loaded.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
BOOL COOExToolBar::LoadToolBar(
UINT _ResourceId ) // @Parm The toolbar resource id.
{
// Convert the resource id into a resource name and load the toolbar
// using the base class method.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CString lpszResourceName;
lpszResourceName.Format( "#%d", _ResourceId );
BOOL bReturn = CToolBar::LoadToolBar( lpszResourceName );
// Check if we loaded the toolbar.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
if ( bReturn == FALSE )
{
return bReturn;
}
// Retrieve the height of the toolbar before putting text.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CToolBarCtrl& bar = GetToolBarCtrl();
int nIndex = 0;
CRect NoTextRc( 0, 0, 0, 0 );
bar.GetItemRect( 0, NoTextRc );
// Set the text for each button.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
TBBUTTON tb;
for ( nIndex = bar.GetButtonCount(); nIndex >= 0; nIndex-- )
{
ZeroMemory(&tb, sizeof(TBBUTTON));
bar.GetButton(nIndex, &tb);
// Do we have a separator?
if ( ( tb.fsStyle & TBSTYLE_SEP ) == TBSTYLE_SEP ) {
continue;
}
// Have we got a valid command id?
if ( tb.idCommand == 0 ) {
continue;
}
// Get the resource string if there is one.
CString strText((LPCSTR)tb.idCommand);
LPCTSTR lpszButtonText = NULL;
CString strButtonText(_T(&""));
_TCHAR seps[] = _T(&"\n");
if ( !strText.IsEmpty() ) {
lpszButtonText = _tcstok( ( LPTSTR ) ( LPCTSTR ) strText, seps );
while( lpszButtonText )
{
strButtonText = lpszButtonText;
lpszButtonText = _tcstok( NULL, seps );
}
}
if ( !strButtonText.IsEmpty() ) {
SetButtonText( nIndex, strButtonText );
}
}
// Calculate the effect of the text on the toolbar.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CRect rc( 0, 0, 0, 0 );
CSize sizeMax( 0, 0 );
for ( nIndex = bar.GetButtonCount(); nIndex >= 0; nIndex-- )
{
bar.GetItemRect( nIndex, rc );
rc.NormalizeRect();
sizeMax.cx = __max( rc.Size().cx, sizeMax.cx );
sizeMax.cy = __max( rc.Size().cy, sizeMax.cy );
}
// Resize the toolbar.
// The text width is the maximum width of the bitmap. All toolbar size
// must at least be this width.
// The text height is the height added to the button. Even in large mode
// we must add this text height.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
m_nTextWidth = sizeMax.cx;
m_nTextHeight = sizeMax.cy - ( NoTextRc.Size().cy );
ResizeToolBar();
// Create the needed image list.
// Build the image list.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CClientDC dc( this );
int nNbBits = dc.GetDeviceCaps( BITSPIXEL );
for ( int i=0; i<NB_POSSIBLE_MODE; i++ )
{
UINT nColorMode = ILC_COLOR;
if ( nNbBits > 8 )
{
nColorMode = ILC_COLORDDB;
}
CSize Size = m_LargeIconSize;
if ( i < 3 )
{
Size = m_SmallIconSize;
}
m_ImageList[ i ].Create( Size.cx, Size.cy, nColorMode | ILC_MASK, bar.GetButtonCount(), 10 );
}
return bReturn;
}
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Image list initialization method.
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// To set the image list.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void COOExToolBar::SetImageList(
ImageMode_ _Mode, // @Parm The image mode.
CImageList& _rList ) // @Parm The hoover image list.
{
// Store the list handle for future use.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
m_ImageList[ _Mode ].Attach( _rList.Detach() );
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// To set the current mode appropriate image list.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void COOExToolBar::AssignImageList( void )
{
// Prepare the list associated with the current mode.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CImageList* pTempHotList;
CImageList* pTempNormalList;
CImageList* pTempDisableList;
if ( m_nShowIconMode == 0 )
{
pTempHotList = &m_ImageList[ SmallHot ];
pTempNormalList = &m_ImageList[ SmallStandard ];
pTempDisableList = &m_ImageList[ SmallDisable ];
}
if ( m_nShowIconMode == 1 )
{
pTempHotList = &m_ImageList[ LargeHot ];
pTempNormalList = &m_ImageList[ LargeStandard ];
pTempDisableList = &m_ImageList[ LargeDisable ];
}
// Set the list in the control.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
SetHotImageList( pTempHotList );
SetStandardImageList( pTempNormalList );
SetDisableImageList( pTempDisableList );
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// To set the image list in the control.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void COOExToolBar::InitImageList( void )
{
// Set the image list according to the current mode.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
AssignImageList();
}
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Private Image list method.
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// Method to calculate the current size of the button.
// @rdesc The button size.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
CSize COOExToolBar::CalcButtonSize( void )
{
// Calcul the width of the drop button.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
CSize theButtonSize;
if ( m_nShowIconMode == 0 )
{
theButtonSize = CSize( m_SmallIconSize.cx + 8, m_SmallIconSize.cy + 7 );
}
else if ( m_nShowIconMode == 1 )
{
theButtonSize = CSize( m_LargeIconSize.cx + 8, m_LargeIconSize.cy + 7 );
}
// Check the text mode and set or hide the text.
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
if ( m_bShowIconText )
{
// The text width is the maximum width of the bitmap. All toolbar size
// must at least be this width.
if ( theButtonSize.cx < m_nTextWidth )
{
theButtonSize.cx = m_nTextWidth;
}
// The text height is the height added to the button. Even in large mode
// we must add this text height.
theButtonSize.cy += m_nTextHeight;
}
return theButtonSize;
}
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Image list information method.
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc: (FUNCTIONAL)
// <c COOExToolBar>
// To set the hoover image list.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -