描述:
现有一CFont类型变量要传递给VSPrinter的SetFont(LPDISPATCH newValue),怎样将该CFont类型变量转换成LPDISPATCH类型的变量
解决方案1:
问题我解决了
CreateOleFont(CFont *pFont)
{
IDispatch* pDispatch = NULL;
USES_CONVERSION;
if (pFont)
{
LOGFONT LogFont;
if (pFont->GetLogFont(&LogFont))
{
LOGFONT* pLogFont = &LogFont;
FONTDESC fd;
fd.cbSizeofstruct = sizeof(FONTDESC);
fd.lpstrName = T2OLE(pLogFont->lfFaceName);
fd.sWeight = (short)pLogFont->lfWeight;
fd.sCharset = pLogFont->lfCharSet;
fd.fItalic = pLogFont->lfItalic;
fd.fUnderline = pLogFont->lfUnderline;
fd.fStrikethrough = pLogFont->lfStrikeOut;
long lfHeight = pLogFont->lfHeight;
if (lfHeight < 0)
lfHeight = -lfHeight;
fd.cySize.Lo = lfHeight * 720000 / 96;
fd.cySize.Hi = 0;
if (FAILED(::OleCreateFontIndirect(&fd, IID_IFontDisp, (void**)&pDispatch)))
pDispatch = NULL;
}
}
return pDispatch;
}