Thread: Draw rect by clicking button

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    4

    Draw rect by clicking button

    I have problum in drawing rect in MFC.(dialoge based) Actually i want 2 draw rect by clicking a button. bt it go ON_Paint function b4 going to button. n display rect n after clicking button it display another rect. i have aply flags on it bt it didnt work. now what to do???

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Quote Originally Posted by fanta View Post
    I have problum in drawing rect in MFC.(dialoge based) Actually i want 2 draw rect by clicking a button. bt it go ON_Paint function b4 going to button. n display rect n after clicking button it display another rect. i have aply flags on it bt it didnt work. now what to do???
    I apologize if English is not your first language.


    If English is your first language, please try to construct a comprehensible sentence to describe each issue, what you have done to correct each issue and what error occurs.

    I normally ignore any post that considers itself so important/urgent that bold had to be used, but the OP is too lazy to actually type ‘before’.

    I also suggest posting in the Windows board for questions on MFC in future. Please include the version of MSVC you are using.



    Now, the answer….You did not post any requirements apart from draw a rectangle when a button is pressed.

    Here is a way to draw an outline of a rectangle without any flags;

    Create a var to hold the rectangle size and location.
    Add a member variable or CRect to you dialog class header (in this example m_rtDraw).
    In the constructor initialize the rect to zero (ie m_rtDraw.SetRectEmpty())

    Create an OnClick() handler for your button.
    In this handler set the rect to the area you want to draw the rectangle (ie m_rtDraw.SetRect(10,10,20,20); ).
    Call for a paint (InvalidateRect(NULL, false);
    Send directly to dlg, bypassing OS queue (UpdateWindow() )

    In the OnPaint()
    If the rect is not empty (m_rtDraw,IsRectEmpty())
    Draw the rect ( dc.Rectangle(m_rtDraw)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. Creating Buttons By Clicking a Button
    By Revengeog in forum C++ Programming
    Replies: 0
    Last Post: 09-04-2009, 12:17 AM
  3. My BS_OWNERDRAW button draw as white when clicked...
    By Jonathan Beaubi in forum Windows Programming
    Replies: 1
    Last Post: 08-16-2007, 10:41 AM
  4. Help clicking a command button
    By anarchytech in forum C++ Programming
    Replies: 7
    Last Post: 07-10-2005, 01:21 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM