Question about OnPaint - Programmer

This is a discussion on Question about OnPaint - Programmer ; Hi NG I have a question about how to solve different problems in my program. I have 3 different pictures which I will use as buttons. When I leftclick on picture 1 - box 1 will show underneth the buttons ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Question about OnPaint

  1. Question about OnPaint

    Hi NG

    I have a question about how to solve different problems in my program. I
    have 3 different pictures which I will use as buttons. When I leftclick on
    picture 1 - box 1 will show underneth the buttons and when I leftclick on
    picture 2 - box 2 will show and so on.

    The question is as followed:

    Where shall I place the code for the clicks? Shall i place it in the
    OnLButtonDown function or in OnPaint? As i see it will give me to problems:

    1) If I place it in OnLButtonDown and I leftclick picture 2 - box 2 wille
    show underneth. But if I recise the program window, box 1 will show again
    "big problem".

    2) If I place it in OnPaint, I need to have a variable in OnLButtonDown
    which changes as I click the different pictures. But only when OnPaint is
    called something happening "porblem again".

    Hope you can help me )

    Regards
    AHR



  2. Re: Question about OnPaint

    AHR wrote:
    > Hi NG
    >
    > I have a question about how to solve different problems in my program. I
    > have 3 different pictures which I will use as buttons. When I leftclick on
    > picture 1 - box 1 will show underneth the buttons and when I leftclick on
    > picture 2 - box 2 will show and so on.
    >
    > The question is as followed:
    >
    > Where shall I place the code for the clicks? Shall i place it in the
    > OnLButtonDown function or in OnPaint? As i see it will give me to problems:
    >
    > 1) If I place it in OnLButtonDown and I leftclick picture 2 - box 2 wille
    > show underneth. But if I recise the program window, box 1 will show again
    > "big problem".
    >
    > 2) If I place it in OnPaint, I need to have a variable in OnLButtonDown
    > which changes as I click the different pictures. But only when OnPaint is
    > called something happening "porblem again".
    >
    > Hope you can help me )
    >
    > Regards
    > AHR
    >
    >


    A button click is not the same thing as OnLButtonDown. When a button is
    clicked it sends a BN_CLICKED notification to its parent window. You
    should put code in this click handler.

    The click handler should set a variable to remember which picture to
    draw. Then it should call Invalidate(). Do NOT draw in the click
    handler.

    Invalidate() will cause OnPaint to be called soon. Draw only in the
    OnPaint handler. You have already discovered why: Windows calls it at
    other times, like resizing.

    --
    Scott McPhillips [VC++ MVP]


  3. Re: Question about OnPaint

    > A button click is not the same thing as OnLButtonDown. When a button is
    > clicked it sends a BN_CLICKED notification to its parent window. You
    > should put code in this click handler.


    Can you show an example "just a short one"?

    I am new in MFC and dont know how to continue.

    Regards
    AHR



  4. Re: Question about OnPaint

    AHR wrote:
    >>A button click is not the same thing as OnLButtonDown. When a button is
    >>clicked it sends a BN_CLICKED notification to its parent window. You
    >>should put code in this click handler.

    >
    >
    > Can you show an example "just a short one"?
    >
    > I am new in MFC and dont know how to continue.
    >
    > Regards
    > AHR
    >
    >


    Example code would not help you: Adding a click message handler is done
    with menu commands, not code. Find a tutorial or a book. Most versions
    of VC come with a SCRIBBLE tutorial in the help. Try searching for it.
    If you buy a book, make sure it is about the same VC version that you
    are using, because the menu commands are very different in different
    versions.

    --
    Scott McPhillips [VC++ MVP]


  5. Re: Question about OnPaint

    > Example code would not help you: Adding a click message handler is done
    > with menu commands, not code. Find a tutorial or a book. Most versions
    > of VC come with a SCRIBBLE tutorial in the help. Try searching for it.
    > If you buy a book, make sure it is about the same VC version that you
    > are using, because the menu commands are very different in different
    > versions.
    >
    > --
    > Scott McPhillips [VC++ MVP]


    Solved it with help from your first mail.

    Thanks
    AHR



+ Reply to Thread