redraw after minimize or change window size

This is a discussion on redraw after minimize or change window size within the Windows Programming forums, part of the Platform Specific Boards category; Hi guys I have next problems I have base class "Shape", it cointains virtual function draw(HWND), I have child class ...

  1. #1
    Registered User
    Join Date
    Jun 2014
    Posts
    1

    redraw after minimize or change window size

    Hi guys

    I have next problems

    I have base class "Shape", it cointains virtual function draw(HWND), I have child class "Line" which contains same function draw(hwnd).
    When I draw line in WM_MOUSEMOVE, it is all ok, but when I minimize or change window size, my line disappear
    I have vector with pointer to base class

    Code:
    vector<Shape*>ff;
    Shape *f;
    
     case WM_LBUTTONDOWN:
        {
    
            IsDrawing = TRUE;
    
            StartX = LOWORD(lParam);
            StartY = HIWORD(lParam);
            EndX = LOWORD(lParam);
            EndY = HIWORD(lParam);
    
            switch(iShape)
            {
            case LINE:
                    f=new Line();
                break;
            case  RECTANGLE:
                f=new MyRectangle();
                break;
            }
    
            f->SetBrushWidth(5);
            f->SetColor(RGB(255,0,0));
            f->SetStartCoord(StartX,StartY);
            f->SetEndCoord(EndX,EndY);
            f->SetMode(1);
            f->draw(hWnd);
            break;
        }
    
      case WM_MOUSEMOVE:
        if( IsDrawing == TRUE )
        {
            f->SetEndCoord(EndX,EndY);
            f->SetMode(2);
            f->draw(hWnd);
            EndX = LOWORD(lParam);
            EndY = HIWORD(lParam);
            f->SetEndCoord(EndX,EndY);
            f->SetMode(2);
            f->draw(hWnd);
        }
    
        break;
    
    case WM_LBUTTONUP:
    
    
        EndX = LOWORD(lParam);
        EndY = HIWORD(lParam);
    
        f->SetEndCoord(EndX,EndY);
        f->SetMode(3);
        f->draw(hWnd);
        ff.push_back(f);
    
        IsDrawing = FALSE;
     break;
    It is drawing ok, but when change windows size
    What I do wrong?

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    You need to do your drawing in the WM_PAINT message handler.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    458
    The OS (Windows) does not store your window client area contents. You have to redraw as required.

    If that is a drawing or paint type program, then you will have to store the information for what is being drawn.
    The initial drawing can be done outside of the WM_PAINT handler, but would have to be redrawn in response
    to the WM_PAINT message, hence the need to store everything.

    For a CAD type drawing program, the attributes for the graphics elements themselves would be stored. That
    would also allow for editing them.

    For something simpler, like Windows Paint, the client area (or drawing) could be copied into a bitmap stored
    in memory device context. Then whenever the window client need to be redrawn, it would be a simple call
    to a bit block transfer function BitBlt().

    Or you could draw on the window DC for the purposes of following the mouse input, and then do all
    the actual drawing on the bitmap. Then BitBlt the bitmap to update the client area.
    This is better, I believe.

    -
    Last edited by megafiddle; 06-27-2014 at 10:41 PM.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    458
    Quote Originally Posted by DaveH View Post
    You need to do your drawing in the WM_PAINT message handler.
    This works well when there is no interactive user drawing or interactive text output. Reading in some data and then
    drawing a graph is a good example. All drawing is done in the WM_PAINT message handler. The program does the
    initial drawing by calling InvalidateRect() for the client area to be drawn. A call to UpdateWindow() might also be needed
    if the WM_PAINT message, will will be subsequently sent, needs to have more priority.

    Nothing else needs to be done to maintain the drawing in the window in this case. The OS will send WM_PAINT messages
    as necessary, and the WM_PAINT message handler will redraw the window. Obviously, the entire drawing procedure needs
    to be within the WM_PAINT message handler.

    So this would not work well with an interactive drawing program.

    -

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 11-02-2011, 09:03 AM
  2. Redraw contents after minimize
    By nutzu2010 in forum Windows Programming
    Replies: 11
    Last Post: 07-15-2011, 04:25 AM
  3. redraw after minimize
    By Prads in forum Windows Programming
    Replies: 6
    Last Post: 03-21-2010, 11:16 AM
  4. minimize executable size
    By heisel in forum C Programming
    Replies: 10
    Last Post: 09-10-2009, 09:00 AM
  5. How to force window redraw when moving... ?
    By jekko in forum Windows Programming
    Replies: 2
    Last Post: 02-28-2004, 01:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21