Print Page | Close Window

Font combobox shows square boxes

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=3095
Printed Date: 06 October 2024 at 2:35am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Font combobox shows square boxes
Posted By: BethZ
Subject: Font combobox shows square boxes
Date Posted: 25 October 2005 at 4:27pm

I built a font combobox in the toolbar by following the Custom Themes sample and certain fonts cannot be displayed properly and they are shown as square boxes just like those in the sample program. Does anybody know the solution for this ? I am using Xtreme Command Bars Pro v9.70. 

                

Thanks, Beth 




Replies:
Posted By: Barto
Date Posted: 26 October 2005 at 6:50am

that's just the special symbol fonts, that only have symbols, but no letters.

What I have seen in other applications ist that you draw the name of the font in the standard system font and draw a sample of the font right to it... I think there may even be a way to determine if a font is a symbol font or a "real" font



Posted By: BethZ
Date Posted: 26 October 2005 at 11:03am

But not all of them that show square boxes are special symbol fonts, such as "Estrangelo Edessa", "Gautami", "Latha", "Mangal", "MV Boli", "Raavi", "Shruti", and "Tunga", and they are not shown as square boxes in Microsoft Word, but they are shown square boxes in the sample progam "Custom Themes" if you pick any of these fonts using "CustomDraw" toolbar button on the bottom of the window.

Only two classes are needed to implement this font combobox, and they are CControlComboBoxCustomDraw and CControlComboBoxCustomDrawList. The code is as following. Is there anything missing in this code ?

//////////////////////////////////////////////////////////// //////////////
// CControlComboBoxCustomDraw
/*********************************************************** ******/
/* The header file for CControlComboBoxCustomDraw                         */
/*********************************************************** *******/
class CControlComboBoxCustomDraw: public CXTPControlFontComboBox
{
 DECLARE_XTP_CONTROL(CControlComboBoxCustomDraw)
public:

 CControlComboBoxCustomDraw()
 {
  if (m_pCommandBar)
  {
   m_pCommandBar->InternalRelease();
  }

  m_pCommandBar = new CControlComboBoxCustomDrawList();
  ((CControlComboBoxCustomDrawList*)m_pCommandBar) ->CreateListBox();

  ((CControlComboBoxCustomDrawList*)m_pCommandBar) ->EnumFontFamiliesEx(1);

 }
};

/*********************************************************** **********/
/* The .cpp file for CControlComboBoxCustomDraw                         */
/*********************************************************** **********/
IMPLEMENT_XTP_CONTROL(CControlComboBoxCustomDraw, CXTPControlFontComboBox)

 

//////////////////////////////////////////////////////////// //////////////
// CControlComboBoxCustomDrawList
/*********************************************************** **********/
/* The header file for CControlComboBoxCustomDrawList                   */
/*********************************************************** **********/
class CControlComboBoxCustomDrawList : public CXTPControlFontComboBoxList
{
 DECLARE_XTP_COMMANDBAR(CControlComboBoxCustomDrawList) ;
 DECLARE_MESSAGE_MAP()
public:

 void DrawItem ( LPDRAWITEMSTRUCT lpDrawItemStruct );

 virtual void CreateListBox()
 {
  CWnd* pParentWnd = CMainFrame::m_pInstance;

  CreateEx(WS_EX_STATICEDGE|WS_EX_TOOLWINDOW, _T("LISTBOX"), _T(""),
   WS_CHILD|WS_VSCROLL|WS_BORDER|WS_CLIPCHILD REN|LBS_SORT|LBS_OWNERDRAWFIXED|LBS_HASSTRINGS|LBS_NOTIFY,
   CRect(0,0,0,0), pParentWnd,  0);

  SetWindowLong(m_hWnd, GWL_HWNDPARENT, 0 );
  ModifyStyle(WS_CHILD, WS_POPUP);
 #ifdef _WIN64
  SetWindowLongPtr(m_hWnd, GWL_HWNDPARENT, (LONG_PTR)(pParentWnd->m_hWnd));
 #else
  SetWindowLong(m_hWnd, GWL_HWNDPARENT, (LONG)(LONG_PTR)(pParentWnd->m_hWnd));
 #endif
 }

 friend class CControlComboBoxCustomDraw;
};

/*********************************************************** **********/
/* The .cpp file for CControlComboBoxCustomDrawList                   */
/*********************************************************** **********/
IMPLEMENT_XTP_COMMANDBAR(CControlComboBoxCustomDrawList, CXTPControlFontComboBoxList)

BEGIN_MESSAGE_MAP(CControlComboBoxCustomDrawList, CXTPControlFontComboBoxList)
 ON_WM_DRAWITEM_REFLECT()
END_MESSAGE_MAP()


void CControlComboBoxCustomDrawList::DrawItem ( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
 CString strText;
 ((CListBox*)this)->GetText(lpDrawItemStruct->ite mID, strText);

 CRect rc(&lpDrawItemStruct->rcItem);

 ASSERT(lpDrawItemStruct->CtlType == ODT_LISTBOX);
 LPCTSTR lpszText = (LPCTSTR) strText;
 ASSERT(lpszText != NULL);
 CDC dc;

 dc.Attach(lpDrawItemStruct->hDC);

 // Save these value to restore them when done drawing.
 COLORREF crOldTextColor = dc.GetTextColor();
 COLORREF crOldBkColor = dc.GetBkColor();

 COLORREF cltBkColor = crOldBkColor;

 // If this item is selected, set the background color
 // and the text color to appropriate values. Also, erase
 // rect by filling it with the background color.
 if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
  (lpDrawItemStruct->itemState & ODS_SELECTED))
 {
  cltBkColor = XTPPaintManager()->GetXtremeColor(XPCOLOR_HIGHLIGHT);

  dc.SetTextColor(XTPPaintManager()->GetXtremeC olor(XPCOLOR_HIGHLIGHT_TEXT));
  dc.FillSolidRect(rc, cltBkColor);

  dc.Draw3dRect(rc, XTPPaintManager()->GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDE R), XTPPaintManager()->GetXtremeColor(XPCOLOR_HIGHLIGHT_BORDE R));
 }
 else
  dc.FillSolidRect(rc, crOldBkColor);

 CFont fnt;
 fnt.CreatePointFont(100, strText);

 CFont* pOldFont = (CFont*)dc.SelectObject(&fnt);

 dc.SetBkMode(TRANSPARENT);
 rc.left += 3;
 dc.DrawText(strText, rc, DT_SINGLELINE|DT_VCENTER);

 dc.SelectObject(pOldFont);

 // Reset the background color and the text color back to their
 // original values.
 dc.SetTextColor(crOldTextColor);
 dc.SetBkColor(crOldBkColor);

 dc.Detach();
}

 

Thanks, Beth




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net