⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ooextoolbar.cpp

📁 采用Vc++开发
💻 CPP
📖 第 1 页 / 共 4 页
字号:
					SetButton(i, &pData[i]); // **PD** renamed from _SetButton
				
				if (nControlCount > 0)
				{
					for (int i = 0; i < nControlCount; i++)
					{
						CWnd* pWnd = GetDlgItem(pControl[i].nID);
						if (pWnd != NULL)
						{
							CRect rect;
							pWnd->GetWindowRect(&rect);
							CPoint pt = rect.TopLeft() - pControl[i].rectOldPos.TopLeft();
							GetItemRect(pControl[i].nIndex, &rect);
							pt = rect.TopLeft() + pt;
							pWnd->SetWindowPos(NULL, pt.x, pt.y, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER);
						}
					}
					delete[] pControl;
				}
				m_bDelayedButtonLayout = bIsDelayed;
		}
		delete[] pData;
	}
	
	//BLOCK: Adjust Margins
	{
		CRect rect; rect.SetRectEmpty();
		CalcInsideRect(rect, (dwMode & LM_HORZ));
		sizeResult.cy -= rect.Height();
		sizeResult.cx -= rect.Width();
		
		CSize size = CControlBar::CalcFixedLayout((dwMode & LM_STRETCH), (dwMode & LM_HORZ));
		sizeResult.cx = max(sizeResult.cx, size.cx);
		sizeResult.cy = max(sizeResult.cy, size.cy);
	}
	return sizeResult;
}

CSize COOExToolBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
{
	DWORD dwMode = bStretch ? LM_STRETCH : 0;
	dwMode |= bHorz ? LM_HORZ : 0;
	
	return CalcLayout(dwMode);
}

// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Macro and other definition.
// ------------------------------------------------------------------------
IMPLEMENT_DYNAMIC( COOBmpToolBar, COOExToolBar )
BEGIN_MESSAGE_MAP( COOBmpToolBar, COOExToolBar )
	//{{AFX_MSG_MAP( COOBmpToolBar )
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Initialization and destruction method.
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc:    (IMPLEMENTATION)
//            <c COOBmpToolBar> 
//            This is the main constructor.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
COOBmpToolBar::COOBmpToolBar( void )
{
}

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc:    (IMPLEMENTATION)
//            <c COOBmpToolBar> 
//            This is the main destructor.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
COOBmpToolBar::~COOBmpToolBar( void )
{
}
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Image list initialization method.
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc:    (FUNCTIONAL)
//            <c COOBmpToolBar> 
//            To set the image list in the control.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void COOBmpToolBar::InitImageList( void )
{
    // Build the image list.
    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    for ( int i=0; i<NB_POSSIBLE_MODE; i++ )
    {
        BuildImageList( m_ImageList[ i ], m_256Image[ i ] );
    }

    // Set the image list according to the current mode.
    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    AssignImageList();
}
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Private Image list method.
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc:    (FUNCTIONAL)
//            <c COOBmpToolBar> 
//            To build an image list based on the given bitmap and size.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void COOBmpToolBar::BuildImageList( 
     CImageList& _rImageList,       // @Parm The image list to build.
     const CExBitmap& _rBitmap )    // @Parm The bitmap to put in the image list.
{
    CBitmap bmpImage;
    bmpImage.LoadBitmap( _rBitmap.m_nResourceId );
    _rImageList.Add( &bmpImage, _rBitmap.m_clrTransparent );
}
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Image list information method.
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc:    (FUNCTIONAL)
//            <c COOBmpToolBar> 
//            To set the small hoover bitmap.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void COOBmpToolBar::SetBitmap( 
     UINT _nBitmap,         // @Parm The bitmap id.
     ImageMode_ _Mode,      // @Parm The image mode.
     COLORREF _clrBk,       // @Parm The background color.
     bool _b256 )           // @Parm The nb of color.
{
    // Initialise the bitmap info.
    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    if ( _b256 )
    {
        m_256Image[ _Mode ].m_nResourceId = _nBitmap;
        m_256Image[ _Mode ].m_clrTransparent = _clrBk;
    }
    else
    {
        m_16Image[ _Mode ].m_nResourceId = _nBitmap;
        m_16Image[ _Mode ].m_clrTransparent = _clrBk;
    }
}
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usefull protected method.
// ------------------------------------------------------------------------
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// MFC Overloaded method.
// ------------------------------------------------------------------------
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// MFC Message method.
// ------------------------------------------------------------------------
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Macro and other definition.
// ------------------------------------------------------------------------
IMPLEMENT_DYNAMIC( COOIconToolBar, COOExToolBar )
BEGIN_MESSAGE_MAP( COOIconToolBar, COOExToolBar )
	//{{AFX_MSG_MAP( COOIconToolBar )
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Initialization and destruction method.
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc:    (IMPLEMENTATION)
//            <c COOIconToolBar> 
//            This is the main constructor.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
COOIconToolBar::COOIconToolBar( void )
{
}

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc:    (IMPLEMENTATION)
//            <c COOIconToolBar> 
//            This is the main destructor.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
COOIconToolBar::~COOIconToolBar( 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 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Private usefull method.
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc:    (IMPLEMENTATION)
//            <c COOIconToolBar> 
//            To convert the given icon into grayscale.
// @rdesc     The gray scale icon.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
HICON COOIconToolBar::ConvertIconToGrayScale( 
        HICON _hIcon,           // @Parm The icon to convert.
        CSize _sizeImage )      // @Parm The icon size.
{
    // Validate the given icon.
    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    if ( _hIcon == 0 )
    {
        return NULL;
    }

    // Create a device context and initialise it.
    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    CDC dcMem;
    dcMem.CreateCompatibleDC( NULL );
    dcMem.SetBkMode( TRANSPARENT );

    // We need to load the icon into the context to initialise as a full color
    // context.
    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    ICONINFO IconInformation;
    GetIconInfo( _hIcon, &IconInformation );
    
    // Create the bitmap to store the gray image.
    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    CBitmap bmpMem;
    bmpMem.CreateBitmap( _sizeImage.cx, _sizeImage.cx, 1, 16, NULL );
    CBitmap* pOldBmp = ( CBitmap* ) dcMem.SelectObject( &bmpMem );

    // Draw the icon in the context.
    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    dcMem.DrawState( CPoint( 0, 0 ), _sizeImage, ( HICON ) _hIcon, DST_ICON | DSS_NORMAL, ( CBrush* ) NULL );

    // Retrieve each pixels and set them in gray scale.
    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    for ( int nRow = 0; nRow < _sizeImage.cy; nRow++ )
    {
        for ( int nColumn = 0; nColumn < _sizeImage.cx; nColumn++ )
        {
            COLORREF clrPixels = dcMem.GetPixel( nColumn, nRow );
            long lSquareSum = GetRValue( clrPixels ) * GetRValue( clrPixels ) +
                              GetBValue( clrPixels ) * GetBValue( clrPixels ) +
                              GetGValue( clrPixels ) * GetGValue( clrPixels );

            int nGray = ( int ) sqrt( ( ( double ) lSquareSum ) / 3 );
            dcMem.SetPixel( nColumn, nRow, RGB( nGray, nGray, nGray ) );
        }
    }
    dcMem.SelectObject( pOldBmp );

    // Set the grayscale bitmap in the icon.
    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    IconInformation.hbmColor = ( HBITMAP ) bmpMem.Detach();

    // Create it and return.
    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    return CreateIconIndirect( &IconInformation );
}
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Image list information method.
// ------------------------------------------------------------------------
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// @mfunc:    (FUNCTIONAL)
//            <c COOIconToolBar> 
//            To set the button icon.
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
void COOIconToolBar::SetIcon( 
        UINT _nStandardIcon,        // @Parm The button standard icon.
        UINT _nDisableIcon,         // @Parm The button disable icon.
        UINT _nHotIcon )            // @Parm The button icon when the mouse is over.
{
    // If the hot icon is 0, use the standard icon.
    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    if ( _nHotIcon == 0 )
    {
        _nHotIcon = _nStandardIcon;
    }
    
    // Retrieve the small icon from the resource and add them in the image
    // list.
    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    {
        CSize Size = m_SmallIconSize;

        HICON hStandardIcon = 
            ( HICON ) ::LoadImage( AfxGetApp()->m_hInstance, 
                                   MAKEINTRESOURCE( _nStandardIcon ), 
                                   IMAGE_ICON, Size.cx, Size.cy, 0 );
        HICON hHotIcon = 
            ( HICON ) ::LoadImage( AfxGetApp()->m_hInstance, 
                                   MAKEINTRESOURCE( _nHotIcon ), 
                                   IMAGE_ICON, Size.cx, Size.cy, 0 );

        HICON hDisableIcon;
        if ( _nDisableIcon == 0 )
        {
            hDisableIcon = ConvertIconToGrayScale( hStandardIcon, Size );
        }
        else
        {
            hDisableIcon = 
            ( HICON ) ::LoadImage( AfxGetApp()->m_hInstance, 
                                   MAKEINTRESOURCE( _nDisableIcon ), 
                                   IMAGE_ICON, Size.cx, Size.cy, 0 );
        }

        // Add them in the image list.
        m_ImageList[ SmallHot ].Add( hHotIcon );
        m_ImageList[ SmallStandard ].Add( hStandardIcon );
        m_ImageList[ SmallDisable ].Add( hDisableIcon );
    }

    // Retrieve the large icon from the resource and add them in the image
    // list.
    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    {
        CSize Size = m_LargeIconSize;

        HICON hStandardIcon = 
            ( HICON ) ::LoadImage( AfxGetApp()->m_hInstance, 
                                   MAKEINTRESOURCE( _nStandardIcon ), 
                                   IMAGE_ICON, Size.cx, Size.cy, 0 );
        HICON hHotIcon = 
            ( HICON ) ::LoadImage( AfxGetApp()->m_hInstance, 
                                   MAKEINTRESOURCE( _nHotIcon ), 
                                   IMAGE_ICON, Size.cx, Size.cy, 0 );

        HICON hDisableIcon;
        if ( _nDisableIcon == 0 )
        {
            hDisableIcon = ConvertIconToGrayScale( hStandardIcon, Size );
        }
        else
        {
            hDisableIcon = 
            ( HICON ) ::LoadImage( AfxGetApp()->m_hInstance, 
                                   MAKEINTRESOURCE( _nDisableIcon ), 
                                   IMAGE_ICON, Size.cx, Size.cy, 0 );
        }

        // Add them in the image list.
        m_ImageList[ LargeHot ].Add( hHotIcon );
        m_ImageList[ LargeStandard ].Add( hStandardIcon );
        m_ImageList[ LargeDisable ].Add( hDisableIcon );
    }
}
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Usefull protected method.
// ------------------------------------------------------------------------
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// MFC Overloaded method.
// ------------------------------------------------------------------------
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

// Start =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// MFC Message method.
// ------------------------------------------------------------------------
// @end =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -