BOOL CFontPropPage::SetFontProps(CDataExchange* pDX, FONTOBJECT fobj, LPCTSTR pszPropName) { USES_CONVERSION; BOOL bStatus = FALSE; COleDispatchDriver PropDispDriver; // Set the properties for all the objects ASSERT_KINDOF(COlePropertyPage, pDX->m_pDlgWnd); COlePropertyPage* propDialog = (COlePropertyPage*)(pDX->m_pDlgWnd); ULONG nObjects; LPDISPATCH* ppDisp = GetObjectArray(&nObjects); for (ULONG i = 0; i < nObjects; i++) { DISPID dwDispID; // Get the Dispatch ID for the property and if successful set the value LPCOLESTR lpOleStr = T2COLE(pszPropName); if (SUCCEEDED(ppDisp[i]->GetIDsOfNames(IID_NULL, (LPOLESTR*)&lpOleStr, 1, m_lcid, &dwDispID))) { LPDISPATCH pFontDisp = NULL; // Get property PropDispDriver.AttachDispatch(ppDisp[i], FALSE); TRY PropDispDriver.GetProperty(dwDispID, VT_DISPATCH, &pFontDisp); END_TRY PropDispDriver.DetachDispatch(); if (pFontDisp == NULL) continue; // Get font interface IFont * pFont; HRESULT hresult = pFontDisp->QueryInterface(IID_IFont, (void**)&pFont); if (hresult == S_OK) { // Set font characteristics if (propDialog->GetControlStatus(AFX_IDC_FONTNAMES)) { BSTR bstrName = fobj.strName.AllocSysString(); pFont->put_Name(bstrName); SysFreeString(bstrName); } if (propDialog->GetControlStatus(AFX_IDC_FONTSIZES)) pFont->put_Size(fobj.cySize); if (propDialog->GetControlStatus(AFX_IDC_FONTSTYLES)) { pFont->put_Bold(fobj.bBold); pFont->put_Italic(fobj.bItalic); pFont->put_Weight(fobj.sWeight); } if (propDialog->GetControlStatus(AFX_IDC_UNDERLINE)) pFont->put_Underline(fobj.bUnderline); if (propDialog->GetControlStatus(AFX_IDC_STRIKEOUT)) pFont->put_Strikethrough(fobj.bStrikethrough); // Release the font interface RELEASE(pFont); bStatus = TRUE; } // Release the font dispatch interface RELEASE(pFontDisp); } } return bStatus; }