我现在可以用VC控制PowerPoint的调用、显示、插入文本、分页等功能,而且字体的大小、名称都可以改,但就是无法改变字体颜色(Slide),简略程序如下:在中声明相应的类对象:
_Application app;
Presentations presentations;
_Presentation presentation;
Slides slides;
_Slide slide;
ShapeRange shaperange;
Shapes shapes;
Shape shape;
TextFrame textframe;
TextRange textrange;
Font font;
FillFormat fillformat;
ColorFormat colorformat;
ShadowFormat shadow;
在中创建实例并修改字体的属性:
if(!app.CreateDispatch("Powerpoint.Application", &e)) 
{
CString str;
str.Format("CreateDispatch() failed w/err 0x%08lx", e.m_sc),
AfxMessageBox(str, MB_SETFOREGROUND);
return;
}
app.SetVisible(TRUE); Presentations presSet(app.GetPresentations());
_Presentation pres(presSet.Add(TRUE));Slides slideSet(pres.GetSlides());
_Slide slide1(slideSet.Add(1, 2));// Add text to slide, by navigating the slide as follows:
// slide1.shapes(#).TextFrame.TextRange.Text
{
Shapes shapes(slide1.GetShapes());
Shape shape(shapes.Item(COleVariant((long)1)));
TextFrame textFrame(shape.GetTextFrame());
TextRange textRange(textFrame.GetTextRange());
textRange.SetText("My first slide");
}
{
Shapes shapes(slide1.GetShapes());
Shape shape(shapes.Item(COleVariant((long)2)));
TextFrame textFrame(shape.GetTextFrame());
TextRange textRange(textFrame.GetTextRange());
textRange.SetText("Automating PowerPoint is easy\r\n"
"Using Visual C++ is powerful!");
font = textrange.GetFont();
font.SetName("Comic Sans MS"); //Set the font name.
font.SetSize((float)48);
}
现在字体的大小、名称等属性都可以改,但就是字体的颜色改不了,不知为什么!
可不可以重写这个字体(Font)的类啊,然后加入改变字体颜色的函数?如果可以,该怎么写?
      请大家帮小弟看看,小弟不胜感激!!
             多谢了!!

解决方案 »

  1.   

    需要将Font对象申明为类的成员变量,不能申明为局部变量。
      

  2.   

    TO: happyparrot(快乐鹦鹉)
    Font这个类是我导入进来的,并不是我自己写的。
    与这个有什么关系吗?
    如果有的话,为什么我可以改变字体的大小和名称呢?
    请赐教!!
      

  3.   

    你看这个Font类中提供修改颜色的功能没有,如果没有你需要自己把这个功能添加进去。
      

  4.   

    TO:I_Love_CPP(我爱C++)
    这个Font类中就是没有提供修改颜色的功能,具体怎么来写这个函数呢?
              请赐教!!
      

  5.   

    我在PowerPoint2000下录制了一个改变字体颜色的宏,VBA程序如下:
    Sub second()
    '
    ' 宏由 kyh 记录,日期: 2004-11-22
    '    ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=0).Select
        With ActiveWindow.Selection.TextRange
            .Text = "Hello World!!"
            With .Font
                .NameAscii = "Times New Roman"
                .NameFarEast = "宋体"
                .NameOther = "Times New Roman"
                .Size = 44
                .Bold = msoFalse
                .Italic = msoFalse
                .Underline = msoFalse
                .Shadow = msoFalse
                .Emboss = msoFalse
                .BaselineOffset = 0
                .AutoRotateNumbers = msoTrue
                .Color.SchemeColor = ppTitle
            End With
        End With
        ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=13).Select
        With ActiveWindow.Selection.TextRange.Font
            .NameAscii = "Times New Roman"
            .NameFarEast = "宋体"
            .Size = 44
            .Bold = msoFalse
            .Italic = msoFalse
            .Underline = msoFalse
            .Shadow = msoFalse
            .Emboss = msoFalse
            .BaselineOffset = 0
            .AutoRotateNumbers = msoTrue
            .Color.SchemeColor = ppFill
        End With
    End Sub
         请问我怎样才能将这段程序转换成C++的程序啊?
                         多谢指教!!
                            急:-(
      

  6.   

    struct ColorFont {
    COLORREF color;
    LOGFONT  logfont;
             };
    ColorFont cf = ...;
    CDC memDC = ...;
    ....
    memDC.SetTextColor(cf.color);
      

  7.   

    参考按钮改变文字颜色的方法:
    pDC->SetTextColor(::GetSysColor( COLOR_3DHILIGHT));
    pDC->DrawText( strText, rect+CPoint(1,1) , DT_SINGLELINE | DT_LEFT | DT_VCENTER|DT_CENTER);