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
|