Thread: Clearing the client area

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    202

    Clearing the client area

    No, this is not "How do I clear the screen?" question. See my problem is I want a "new" option in my menu, which I have. The code of it just invalidates the client area and that works fine but it repaints the entir window(in the client area) including the menus and title bar. I used to accomplish the effect of clearing the screen with SendMessage and sending WM_PAINT but I recently switched to using a FrameBuffer so that option wont work anymore. Any suggestions?

    Isometric

    PS..The code for my Invalidation is:
    InvalidateRect (hwnd, &rectClient, TRUE) ;
    and rectClient is already set to be the size fof the client area

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    flush?

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    What do you mean Flush?

  4. #4
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    So is it like a picture drawing thing?

    Maybe you should send a message making every pixel white.

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    acturally its a geometric graphing program (I solidify both my geometry and my coding :-) so I cant make every pixel white or it will take out my graph which it is spose to keep and just get rid of any drawings that were done.

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    It may be in your WM_PAINT handler.

    If your not using the PAINTSTRUCT (filled with the BeginPaint() call) in your cooresponding BitBlt() call, then I'd say that's the problem.

    Or are you already doing that? That's all I can think.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  7. #7
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    The BitBlt works fine its just the client area is redrawn using the wrong parts of the screen.

  8. #8
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    What is the RECT* param that you are setting with InvalidateRect? You could try just invalidating the area without the menu and what do you don't want repainted.

    [EDIT] Actually, you musn't be invalidating the menu because it is "doubling" it. What does your WM_PAINT handling look like? Post the code. You might be repainting the toolbar and menu there. That's all I can think of.[/EDIT]
    1978 Silver Anniversary Corvette

  9. #9
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    &rectClient is already initilized to only hold the client area no menus or titlebars. And its only redrawing that section but with the wrong section of screen in it.

  10. #10
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Post your handling of WM_PAINT. There is no other explanation than you are either repainting the menu and toolbar.

    My $0.02

    Garfield
    1978 Silver Anniversary Corvette

  11. #11
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    Code:
    hdc = BeginPaint (hwnd, &ps) ;
    		marks = CreatePen (PS_INSIDEFRAME, 1, 0) ; // create pen for drawing the marks
    		axis = CreatePen (PS_SOLID, 4, 0) ; // create pen for drawing axis
    		SelectObject (hdc, marks) ;
    		xspace = cxClient/20 ;//to find spacing on x axis
    		yspace = cyClient/20 ;//to find spacing on the X axis
    		n = 1 ;
    		while(n<20){
    			xmarks = xspace * n ;         //calculate the position of x marks
    			ymarks = yspace * n ;   // calculate the position of y marks
    			MoveToEx(hdc, xmarks, 0, NULL) ;//move to starting point of x marks
    			LineTo(hdc, xmarks, cyClient) ;//draw x marks
    			MoveToEx(hdc, 0, ymarks, NULL) ;//move to starting point of y marks
    			LineTo(hdc, cxClient, ymarks) ;//draw y marks
    		  n++ ;
    		}
    		SelectObject (hdc, axis) ;
    		yaxis = cyClient/2 ; //to find half the hieght
    		xaxis = cxClient/2 ; //to find half the width
    		MoveToEx(hdc, xaxis, 0, NULL) ; //to move to top of Y axis
    		LineTo(hdc, xaxis, cyClient) ; //to draw y axis
    		MoveToEx(hdc, 0, yaxis, NULL) ; //to move to left of X axis
    		LineTo(hdc, cxClient, yaxis) ; //to draw X axis
    		SelectObject (hdc, NULL) ;
    		DeleteObject(axis) ;
    		DeleteObject(marks) ;
    		BitBlt(hdc, 0, 0, clientWidth, clientHeight, memhdc, 0, 0, SRCCOPY) ;
    
    		EndPaint (hwnd, &ps) ;
    		break ;
    is that what you wanted?
    Last edited by Isometric; 01-28-2002 at 02:22 PM.

  12. #12
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    First, watch the SelectObject() as you may be loosing a brush / pen per paint.
    Second try to get all the drawing functions out of the paint, much quicker and easier to debug.
    Third you set up a HDC, returned from paint (hdc), and then BitBlt() memhdc over the top, wiping hdc out.

    This could be the problem, how did you create memdc?

    Is it the Window rect or Client rect?
    Last edited by novacain; 01-28-2002 at 10:53 PM.
    "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

  13. #13
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    On style not functionality,

    I would create a function that only drew the axis given a HDC and RECT.
    Also function that clears the HDC given a HDC and RECT, use BitBlt() and WHITENESS as the type of drawing (last param).
    A function that graphs the data given a HDC, RECT and a pointer to the data.
    If the user calls for a clear call the functions to do the drawing.

    OR

    This is where having multiple HDC is a help, once you get used to them.
    Create a DC for the axis, one for the actual graph and another for, if I understand correctly the user's drawings all exactly the same (an array).
    The idea is that you redraw the entire graph, calc the axis ect. Then BitBlt() all the components (line, axis ect) to one HDC, the FrameBuffer.
    Then call a paint with InvalidateRect().

    In paint the FrameBuffer is only BitBlt()ed to the HDC returned from BeginPaint(), NOTHING more. If Windows calls for a paint only the FrameBuffer will be redrawn.

    In other words try to have all the drawing finished BEFORE calling paint.
    "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

  14. #14
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    Your saying that I should do the drawing before WM_PAINT but eh only message that would accomedate that would be WM_CREATE. I tried moving the recently functionized(is that a word??) axis and marks drawing into WM_CREATE but I came out with a blank screen. Any suggestions?

    BTW... if the functions are called from WM_PAINT they work fine. Am I mistaken about the order of messages but that wouldn't make sense, right?
    Last edited by Isometric; 01-29-2002 at 02:33 PM.

  15. #15
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Hard to describe as I do not know what / how your app works. Will tell you how mine does.

    In WM_CREATE I have a StartUp function that does all the Start up things.
    This includes creating two HDC's, with BMP's, compatible with the screen and the same size as the client area. These are the MAIN and FRAMEBUFFER. A small function BitBlt's them white (this will be used to clear the HDC's again later) .

    These are released / deleted in my WM_CLOSE handling function.

    When the user calls data (clicks a ctrl) from the server and asks for a graph I draw to one HDC (MAIN).
    Small functions to do one of the following are called;
    Clear HDC (as at start
    Draw axis
    Assemble data (convert to axis scales, POINT array)
    graph data

    Now I have the graph drawn, I BitBlt MAIN to the unused HDC (framebuffer) and call a paint (InvalidateRect ect). The framebuffer is used to BitBlt to the BeginPaint() hdc. The main never gets drawn to the screen (or goes near the paint function).

    Now if Windows calls a paint the framebuffer is drawn, it contains the last graph (until the new graph is finished).

    This gives good control over the drawing and is easier to debug (you can't put a break point in the paint as it generates a paint call itself).

    How do you know to draw a new graph?
    "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. Nonclient & client area transparency
    By TheDan in forum Windows Programming
    Replies: 0
    Last Post: 03-27-2007, 02:19 PM
  2. MFC: Clear Client Area
    By mrafcho001 in forum Windows Programming
    Replies: 2
    Last Post: 06-27-2005, 01:35 PM
  3. Displaying more shapes in the same client Area
    By sajeev_js in forum Windows Programming
    Replies: 1
    Last Post: 06-11-2005, 01:52 PM
  4. Help resizing client area
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 07-07-2002, 08:33 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM