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

📄 customizedialog.cpp

📁 The ITU-T(Telecommunication Standardization Sector)is a permanent organ of the International Telecom
💻 CPP
📖 第 1 页 / 共 2 页
字号:
void CCustomizeDialog::OnMeasureItem( int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct )
{
   
#ifdef CUSTOM_DRAW
	if ( lpMeasureItemStruct->CtlType == ODT_LISTBOX )
    {
        if ( ( nIDCtl == IDC_LB_AVAILABLE ) ||
             ( nIDCtl == IDC_LB_CURRENT ) )
        {
            lpMeasureItemStruct->itemHeight = GetButtonSize().cy;
            return;
        }
    }
#endif // CUSTOM_DRAW

    CWnd::OnMeasureItem( nIDCtl, lpMeasureItemStruct );
}

void CCustomizeDialog::OnDrawItem( int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct )
{

#ifdef CUSTOM_DRAW
    if ( lpDrawItemStruct->CtlType == ODT_LISTBOX )
    {
        if ( ( nIDCtl == IDC_LB_AVAILABLE ) || ( nIDCtl == IDC_LB_CURRENT ) )
        {
            CDC* pDC = CDC::FromHandle( lpDrawItemStruct->hDC );
            int nSavedDC = pDC->SaveDC();
            ASSERT( nSavedDC );

			CFont *pToolBarFont= m_pToolBar->GetFont();
			if (pToolBarFont)  pDC->SelectObject(pToolBarFont);
			

            // Get all needed info about the item being drawn
            CRect rcItem( &lpDrawItemStruct->rcItem );

            int nItem  = ( SHORT )HIWORD( lpDrawItemStruct->itemData );
            int nImage = ( SHORT )LOWORD( lpDrawItemStruct->itemData );
            int nIndex = ( int )lpDrawItemStruct->itemID;
            bool bSelected  = ( lpDrawItemStruct->itemState & ODS_SELECTED ) != 0;
            bool bFocused   = ( lpDrawItemStruct->itemState & ODS_FOCUS    ) != 0;
            bool bSeparator = false;
			bool bHidden    = false;


			//I found these magic numbers by trial, they may be wrong
			if ( ( nItem < 0 ) || ( nItem > m_pToolBar->m_ToolBarInfo.GetUpperBound() ) )
			{
				//	actually hidden or last seperator
				 bHidden    = ((nItem & 0x4000)==0x4000) || ((nItem & 0xa000)==0xa000); //magic  number
				 bSeparator =(nItem &0x2000)==0x2000;		  //magic  number
				 nItem  &=0xFF;								 //magic  number
			}



            // Calculate rectangles for image, text and focus frame
            CSize szButton = GetButtonSize();
            CRect rcImage( rcItem );
            rcImage.right = rcImage.left + szButton.cx;
            CRect rcText( rcItem );
            rcText.left  += szButton.cx + 5;
            rcText.right -= 2;
            CRect rcLabel( rcItem );
            rcLabel.left += szButton.cx + 1;

            // Cache system colors
            COLORREF clrText     =  bSelected ? m_clrHighLightText : m_clrBtnText ;
            COLORREF clrBack     =  bSelected ? m_clrHighLight : m_clrBtnFace ;

            pDC->FillSolidRect( rcImage, m_clrBtnFace );
            pDC->FillSolidRect( rcLabel, clrBack );

            // Draw focus rect, if needed
            if ( bFocused )
            {
                CBrush brush( RGB(
                    255 - GetRValue( clrBack ),
                    255 - GetGValue( clrBack ),
                    255 - GetBValue( clrBack ) ) );
                rcLabel.DeflateRect( 2, 2 );
                pDC->FrameRect( rcLabel, &brush );
                VERIFY( brush.DeleteObject() );
            }

            // Get item text to be drawn
            CString strText;
            if ( !bSeparator )
                strText= m_pToolBar->m_ToolBarInfo[ nItem ].btnText;
            else
				strText=STR_SEPARATOR;

            // Prepare to draw item text
            int nFormat = DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_END_ELLIPSIS;
            pDC->SetBkMode( TRANSPARENT );
            pDC->SetTextColor( clrText );

            if ( !bSeparator )
            {
                // Draw item image, if any
                if ( nImage >= 0 )
                {
                    if ( bSelected )
                    {
                        pDC->Draw3dRect( rcImage, m_clr3dHilite, m_clr3dShadow );
                    }


                    CToolBarCtrl& tbCtrl = m_pToolBar->GetToolBarCtrl();
					ASSERT(m_pToolBar->m_hbmImageWell);

					CSize szImage = ( m_pToolBar->GetIconOptions() == ioSmallIcons ) ?
							CToolBarEx::m_szImageSmall : CToolBarEx::m_szImageLarge;


                    CDC dc;
                    VERIFY( dc.CreateCompatibleDC( pDC ) );
                    CBitmap  * pbmpImage =CBitmap::FromHandle(m_pToolBar->m_hbmImageWell);
                    CBitmap* pOldBitmap = dc.SelectObject( pbmpImage );
					ASSERT(rcImage.Width()>=szImage.cx);
					ASSERT(rcImage.Height()>=szImage.cy);

                    VERIFY( pDC->BitBlt((rcImage.Width()-szImage.cx)/2+ rcImage.left,(rcImage.Height()-szImage.cy)/2+rcImage.top , szImage.cx, szImage.cy,&dc, nImage*szImage.cx, 0, SRCCOPY ) );
                    dc.SelectObject( pOldBitmap );
                    VERIFY( pbmpImage->Detach() );
                }
							   
                if ( m_pToolBar->m_ToolBarInfo[ nItem ].tbButton.fsStyle & TBSTYLE_DROPDOWN )
                {
                    // This button is drop-down button.  To indicate this simple fact
                    // we draw an arrow on right like one that submenu items have.

                    CRect rcArrow( rcText );
                    rcArrow.left = rcArrow.right - ::GetSystemMetrics( SM_CXMENUCHECK );
                    rcText.right -= rcArrow.Width();

                    CBrush brush( clrText );
                    CBrush* pOldBrush = pDC->SelectObject( &brush );

                    CDC dc;
                    VERIFY( dc.CreateCompatibleDC( pDC ) );

                    CBitmap bmpArrow;
                    VERIFY( bmpArrow.CreateCompatibleBitmap( pDC, rcArrow.Width(), rcArrow.Height() ) );

                    CBitmap* pOldBitmap = dc.SelectObject( &bmpArrow );
                    CRect rc( 0, 0, rcArrow.Width(), rcArrow.Height() );
                    VERIFY( dc.DrawFrameControl( rc, DFC_MENU, DFCS_MENUARROW ) );
                    VERIFY( pDC->BitBlt( rcArrow.left, rcArrow.top, rcArrow.Width(), rcArrow.Height(),
                        &dc, 0, 0, 0x00B8074A /*=PSDPxax*/ ) );

                    dc.SelectObject( pOldBitmap );
                    VERIFY( bmpArrow.DeleteObject() );

                    pDC->SelectObject( pOldBrush );
                    VERIFY( brush.DeleteObject() );
                }

				if (bHidden)
                {
                    if ( bSelected )
                    {
                        pDC->SetTextColor( m_clrBtnFace );
                        pDC->DrawText( strText, rcText, nFormat );
                    }
                    else
                    {
                        CRect rcTemp( rcText );
                        rcTemp.OffsetRect( 1, 1 );
                        pDC->SetTextColor( m_clr3dHilite );
                        pDC->DrawText( strText, -1, rcTemp, nFormat );
                        pDC->SetTextColor( m_clrGrayText );
                        pDC->DrawText( strText, rcText, nFormat );
                    }
				}
				else
				{
					pDC->DrawText( strText, rcText, nFormat );
				}
            }
			else
			{
			 if (bHidden)
                {
                    if ( bSelected )
                    {
                        pDC->SetTextColor( m_clrBtnFace );
                        pDC->DrawText( strText, rcText, nFormat );
                    }
                    else
                    {
                        CRect rcTemp( rcText );
                        rcTemp.OffsetRect( 1, 1 );
                        pDC->SetTextColor( m_clr3dHilite );
                        pDC->DrawText( strText, -1, rcTemp, nFormat );
                        pDC->SetTextColor( m_clrGrayText );
                        pDC->DrawText( strText, rcText, nFormat );
                    }
                }
                else				   
                {
                    // Draw the separator bar in the middle
                    rcImage.DeflateRect( cxPadding, cyPadding );
                    int y = ( rcImage.top + rcImage.bottom ) / 2;
                    rcImage.top    = y - 1;
                    rcImage.bottom = y + 1;

                    pDC->Draw3dRect( rcImage, m_clr3dShadow, m_clr3dHilite );
                    pDC->DrawText( strText, rcText, nFormat );
                }
			}

            VERIFY( pDC->RestoreDC( nSavedDC ) );
            return;
        }
    }
#endif //CUSTOM_DRAW

    CWnd::OnDrawItem( nIDCtl, lpDrawItemStruct );
}

#ifdef CUSTOM_DRAW
CSize CCustomizeDialog::GetButtonSize() const
{
    CSize szImage = ( m_pToolBar->GetIconOptions() == ioSmallIcons ) ?
		CToolBarEx::m_szImageSmall : CToolBarEx::m_szImageLarge;
    return szImage + CSize( cxPadding * 2, cyPadding * 2 );
}
#endif //CUSTOM_DRAW

LRESULT CCustomizeDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	if (message==WM_HELP)
	{
	  LPHELPINFO lphi = (LPHELPINFO) lParam; 
	  if ( (lphi->iCtrlId != IDC_CB_TEXTOPTIONS) && (lphi->iCtrlId != IDC_CB_ICONOPTIONS) )
		return DefWindowProc(message,wParam,lParam);
	}
	return CWnd::WindowProc(message, wParam, lParam);
}

void CCustomizeDialog::OnSysColorChange() 
{
#ifdef CUSTOM_DRAW
	//get the color again
	GetColors();
#endif // CUSTOM_DRAW

	CWnd::OnSysColorChange();
}

#ifdef CUSTOM_DRAW
void CCustomizeDialog::GetColors()
{
	m_clrHighLightText=::GetSysColor( COLOR_HIGHLIGHTTEXT);
	m_clrBtnText=::GetSysColor( COLOR_BTNTEXT );
    m_clrHighLight=	::GetSysColor(COLOR_HIGHLIGHT );
    m_clrGrayText = ::GetSysColor( COLOR_GRAYTEXT );
    m_clrBtnFace  = ::GetSysColor( COLOR_BTNFACE );
    m_clr3dShadow = ::GetSysColor( COLOR_3DSHADOW );
    m_clr3dHilite = ::GetSysColor( COLOR_3DHILIGHT );
}
#endif // CUSTOM_DRAW

⌨️ 快捷键说明

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