Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Font combobox shows square boxes
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Font combobox shows square boxes

 Post Reply Post Reply
Author
Message
BethZ View Drop Down
Newbie
Newbie


Joined: 25 October 2005
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote BethZ Quote  Post ReplyReply Direct Link To This Post Topic: Font combobox shows square boxes
    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 



Edited by BethZ
Back to Top
Barto View Drop Down
Groupie
Groupie


Joined: 27 February 2005
Location: Germany
Status: Offline
Points: 60
Post Options Post Options   Thanks (0) Thanks(0)   Quote Barto Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
BethZ View Drop Down
Newbie
Newbie


Joined: 25 October 2005
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote BethZ Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.125 seconds.