最好在虚函数PreCreateWindow()中实现

解决方案 »

  1.   

    不能在构造函数和PreCreateWindow()中完成。因为此时窗口还没有形成。
    你可以在OnInitalUpdate()中完成
      

  2.   

    TO: xuyongg(懶漢) 
    我认为可以在构造函数里可以实现,因为我现在的程序就是这样做的,
    当然构造函数里只是初始化操作,具体绘画操作还是在ondraw(我是这样实现的)
    pDC->SelectStockObject(m_nColor);
    pDC->Ellipse(m_rectEllipse);
      

  3.   

    “CTESTView::CTESTView():m_rectEllipse(0,0,200,200)”
    我对这种表示方式不太理解
    在这里
    CTESTView::CTESTView()本身是一个构造函数
    现在变成CTESTView::CTESTView():m_rectEllipse(0,0,200,200)我认为这里是对m_rectEllipse初始化
    我的问题是:
    我要画两个椭圆,那怎么初始化了
      

  4.   

    就是这么简单!CTESTView::CTESTView():m_rectEllipse1(0,0,200,200),m_rectEllipse2(0,0,200,200)
      

  5.   

    TO: hooligan(风) 
    在这里m_rectEllipse1(0,0,200,200)是一个函数,我这样说没错吧
    现在我想在程序的某个地方改变这个椭圆的位置,要可以怎样调用这个函数
      

  6.   

    这里并不是一般的函数调用,实际上是将这几个参数传给了m_rectEllipse1的构造函数。所以你不能直接调用这个函数。这种写法是C++中初始化类的成员对象的一种写法。msdn中是这么说的:Initializing Member Objects
    Classes can contain member objects of class type, but to ensure that initialization requirements for the member objects are met, one of the following conditions must be met: The contained object’s class requires no constructor.
    The contained object’s class has an accessible default constructor.
    The containing class’s constructors all explicitly initialize the contained object. 
    The following example shows how to perform such an initialization:// Declare a class Point.
    class Point
    {
    public:
    Point( int x, int y ) { _x = x; _y = y; }
    private:
    int _x, _y;
    };// Declare a rectangle class that contains objects of type Point.
    class Rect
    {
    public:
    Rect( int x1, int y1, int x2, int y2 );
    private:
    Point _topleft, _bottomright;
    };// Define the constructor for class Rect. This constructor
    // explicitly initializes the objects of type Point.
    Rect::Rect( int x1, int y1, int x2, int y2 ) :
    _topleft( x1, y1 ), _bottomright( x2, y2 )
    {
    }
    The Rect class, shown in the preceding example, contains two member objects of class Point. Its constructor explicitly initializes the objects _topleft and _bottomright. Note that a colon follows the closing parenthesis of the constructor (in the definition). The colon is followed by the member names and arguments with which to initialize the objects of type Point.Warning The order in which the member initializers are specified in the constructor does not affect the order in which the members are constructed; the members are constructed in the order in which they are declared in the class.Reference and const member objects must be initialized using the member initialization syntax shown in Syntax in Initializing Bases and Members. There is no other way to initialize these objects.