Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » How to change text color of Shortcut list item? Collapse All
Subject Author Date
Virendra Mishra May 12, 2005 - 3:23 AM

Hi dear,


I ahve a requirement to change text colour of shortcut list item as in Office 2000 theme text colour is white which is not visible when shortcut list’s background is set to RGB(205,205,239).


Thanks in advance.


Virendra

Technical Support May 12, 2005 - 8:35 AM

Any custom look of items in the shortcut list control can be implemented only by overriding the CExtShortcutListWnd::OnShortcutListDrawItem() virtual method. Here is the source code for painting the standard shortcut list item in which you can modify whatever you need:

if( rcBoundsAll.IsRectEmpty()
  || ( ! dc.RectVisible( &rcBoundsAll ) )
  )
  return;

 if( (! rcBoundsIcon.IsRectEmpty() )
  && dc.RectVisible( &rcBoundsIcon )
  )
 {
  CExtCmdIcon & _icon =
   IsBigIconView() ? _sii.m_iconBig : _sii.m_iconSmall;
  HICON hIcon = _icon.GetIcon();
  if( hIcon == NULL )
  {
   hIcon = _sii.m_iconBig.GetIcon();
   if( hIcon == NULL )
    hIcon = _sii.m_iconSmall.GetIcon();
  }
  CRect rcUnderIcon( rcBoundsIcon );
  rcUnderIcon.InflateRect(
   __EXT_SHORTCUTLISTWND_ICON_BORDER_GAP_X,
   __EXT_SHORTCUTLISTWND_ICON_BORDER_GAP_Y
   );
  dc.FillSolidRect(
   &rcUnderIcon,
   g_PaintManager->GetColor( COLOR_3DSHADOW, this )
   );
  if( hIcon != NULL )
  {
   ::DrawIconEx(
    dc.GetSafeHdc(),
    rcBoundsIcon.left,
    rcBoundsIcon.top,
    hIcon,
    rcBoundsIcon.Width(),
    rcBoundsIcon.Height(),
    0,
    (HBRUSH)NULL,
    DI_NORMAL
    );
  }
  if( _sii.m_bPressed || _sii.m_bHover )
  {
   COLORREF clrLT =
    g_PaintManager->GetColor(
     _sii.m_bPressed ? COLOR_3DDKSHADOW : COLOR_3DFACE, this
     );
   COLORREF clrRB =
    g_PaintManager->GetColor(
     _sii.m_bPressed ? COLOR_3DFACE : COLOR_3DDKSHADOW, this
     );
   dc.Draw3dRect(
    &rcUnderIcon,
    clrLT,
    clrRB
    );
  }
 }

CExtSafeString sItemText = _sii.m_sText;
 if( (! rcBoundsText.IsRectEmpty() )
  && dc.RectVisible( &rcBoundsText )
  && ( ! sItemText.IsEmpty() )
  )
 {
  LONG nItemTextLen = sItemText.GetLength();
  CRect rcCaption( rcBoundsText );
bool bHorzLayout = IsHorizontalLayout();
  CFont * pItemFont = 
OnShortcutListItemGetFont( bHorzLayout, _sii );
  ASSERT( pItemFont != NULL );
  ASSERT( pItemFont->GetSafeHandle() != NULL );
  CFont * pOldFont = dc.SelectObject( pItemFont );
  COLORREF clrTextOld =
   dc.SetTextColor(
    g_PaintManager->GetColor(
     bExpandMode ? COLOR_INFOTEXT : COLOR_3DHILIGHT, this
     )
    );
  int nOldBkMode = dc.SetBkMode( TRANSPARENT );
  if( bHorzLayout )
  {
   rcCaption.InflateRect( 3, 0 );
   CSize sizeTextMeasured = rcBoundsText.Size();
   UINT nOldTA = dc.SetTextAlign(
    TA_TOP | TA_BASELINE
    );
   rcCaption.OffsetRect(
    ( (m_dwShortcutListStyle & __ESLW_INV_VFONT) == 0 )
     ?   sizeTextMeasured.cx/2
     : - sizeTextMeasured.cx/2 + 2
     ,
    0
    );
   CPoint ptCenter = rcCaption.CenterPoint();
   if( (m_dwShortcutListStyle & __ESLW_INV_VFONT) == 0 )
    ptCenter.y =
     rcCaption.bottom - 4
     - (rcCaption.Height() - sizeTextMeasured.cy)
     ;
   else
    ptCenter.y =
     rcCaption.top + 4
     ;
   dc.ExtTextOut(
    ptCenter.x,
    ptCenter.y,
    ETO_CLIPPED,
    &rcCaption,
    sItemText,
    NULL
    );
   dc.SetTextAlign( nOldTA );
  } // if( bHorzLayout )
  else
  {
   rcClient.DeflateRect( 1, 0 );
   CRect rcText(
    max(rcCaption.left, rcClient.left),
    rcCaption.top,
    min(rcCaption.right, rcClient.right),
    rcCaption.bottom
    );
   if( rcText.left < rcText.right )
   {
    UINT nFormat =
     DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
    dc.DrawText(
     sItemText,
     nItemTextLen,
     &rcText,
     nFormat
     );
   } // if( rcText.left < rcText.right )
  } // else from if( bHorzLayout )
  dc.SetBkMode( nOldBkMode );
  dc.SetTextColor( clrTextOld );
  dc.SelectObject( pOldFont );
 }