(newbie) needs help for subclassing CStatic - Programmer

This is a discussion on (newbie) needs help for subclassing CStatic - Programmer ; I've been trying to draw an openGL scene inside a popped up dialog without success (no scene shows at all). The GL scene is supposed to appear inside a picture frame which is of class CStatic. After a lot of ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: (newbie) needs help for subclassing CStatic

  1. (newbie) needs help for subclassing CStatic

    I've been trying to draw an openGL scene inside a popped up dialog
    without success (no scene shows at all). The GL scene is supposed to
    appear inside a picture frame which is of class CStatic. After a lot
    of googling, it seems this is the source of the problem. The OnPaint()
    handler is never called in CStatic, thus nothing is shown. So I need,
    so the suggestion says, to subclass the control. The problem is I
    don't have much idea how to do this and would appreciate any help.

    Using class wizard, I have created a class CStaticGl based on CStatic.
    Now:

    1. What do I do with this new class so that its OnPaint is callable?
    2. How do I assign this new class to the picture frame item of my
    dialog? I put this frame in the dialog using the Controls toolbox. How
    do you put item in the dialog manually if that item is not part of the
    Controls toolbox?

    Much thanks for any help,

    David

  2. Re: (newbie) needs help for subclassing CStatic

    I can't really tell where you are getting confused. So here is the entire
    process.

    First derive a class from CStatic and take over the WM_PAINT message
    You can do this using the Class Wizard.
    And it should give you something like this

    class CMyStatic : public CStatic
    {
    public:
    constructor/destructor
    protected:
    afx_msg void OnPaint();
    };

    void CMyStatic::OnPaint()
    {
    //do your drawing here.
    }

    Next using the dialog editor put a static or picture control on your dialog
    box, and give it a distinct ID (IDC_MYSTATIC). Then depending on the
    version you have assign a variable name to that control.
    Version 6.0 - use class wizard - under the second tab, select the control ID
    and click the add button. Give it a name and make sure that control is
    selected, and your CMyStatic should be available as a control type. If not
    then simpley use CStatic and manually change the type to CMyStatic in your
    dialog's .h file.
    ..Net - while in the dialog editor right click on the control and select add
    variable, and the rest should be pretty much the same as 6.0

    Ali R.


    "David Ananas" wrote in message
    news:1f57124c.0311191007.24e7dd32@posting.google.c om...
    > I've been trying to draw an openGL scene inside a popped up dialog
    > without success (no scene shows at all). The GL scene is supposed to
    > appear inside a picture frame which is of class CStatic. After a lot
    > of googling, it seems this is the source of the problem. The OnPaint()
    > handler is never called in CStatic, thus nothing is shown. So I need,
    > so the suggestion says, to subclass the control. The problem is I
    > don't have much idea how to do this and would appreciate any help.
    >
    > Using class wizard, I have created a class CStaticGl based on CStatic.
    > Now:
    >
    > 1. What do I do with this new class so that its OnPaint is callable?
    > 2. How do I assign this new class to the picture frame item of my
    > dialog? I put this frame in the dialog using the Controls toolbox. How
    > do you put item in the dialog manually if that item is not part of the
    > Controls toolbox?
    >
    > Much thanks for any help,
    >
    > David




  3. Re: (newbie) needs help for subclassing CStatic

    David Ananas wrote:
    > I've been trying to draw an openGL scene inside a popped up dialog
    > without success (no scene shows at all). The GL scene is supposed to
    > appear inside a picture frame which is of class CStatic. After a lot
    > of googling, it seems this is the source of the problem. The OnPaint()
    > handler is never called in CStatic, thus nothing is shown. So I need,
    > so the suggestion says, to subclass the control. The problem is I
    > don't have much idea how to do this and would appreciate any help.
    >
    > Using class wizard, I have created a class CStaticGl based on CStatic.
    > Now:
    >
    > 1. What do I do with this new class so that its OnPaint is callable?
    > 2. How do I assign this new class to the picture frame item of my
    > dialog? I put this frame in the dialog using the Controls toolbox. How
    > do you put item in the dialog manually if that item is not part of the
    > Controls toolbox?
    >
    > Much thanks for any help,
    >
    > David


    Use class wizard to add a control member variable (of your derived
    class) to the parent dialog.

    Class Wizard adds a DDX_Control() call to the dialog, and it is this
    call that does the subclassing (so your class will get messages like
    WM_PAINT) and also associates your member variable with the derived
    control object (so you can call functions in your class from the dialog).

    --
    Scott McPhillips [VC++ MVP]


  4. Re: (newbie) needs help for subclassing CStatic

    Add SS_OWNERDRAW to the style of the control, then override the
    DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) member function. Look at
    CStatic:rawItem in the MFC Library Reference.

    Francis

    "David Ananas" a écrit dans le message de news:
    1f57124c.0311191007.24e7dd32@posting.google.com...
    > I've been trying to draw an openGL scene inside a popped up dialog
    > without success (no scene shows at all). The GL scene is supposed to
    > appear inside a picture frame which is of class CStatic. After a lot
    > of googling, it seems this is the source of the problem. The OnPaint()
    > handler is never called in CStatic, thus nothing is shown. So I need,
    > so the suggestion says, to subclass the control. The problem is I
    > don't have much idea how to do this and would appreciate any help.
    >
    > Using class wizard, I have created a class CStaticGl based on CStatic.
    > Now:
    >
    > 1. What do I do with this new class so that its OnPaint is callable?
    > 2. How do I assign this new class to the picture frame item of my
    > dialog? I put this frame in the dialog using the Controls toolbox. How
    > do you put item in the dialog manually if that item is not part of the
    > Controls toolbox?
    >
    > Much thanks for any help,
    >
    > David




+ Reply to Thread