New to Windows & C++ - InvalidateRect Problem

This is a discussion on New to Windows & C++ - InvalidateRect Problem within the Windows Programming forums, part of the Platform Specific Boards category; OK, I'm making little excersizes for myself just to explore programming C++ in windows. I made a little app to ...

  1. #1
    Assembler + Basic from 79
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    22

    New to Windows & C++ - InvalidateRect Problem

    OK,
    I'm making little excersizes for myself just to explore programming C++ in windows. I made a little app to show the mouse coordinates next to the cursor as I moved it but didn't like the way it made the entire screen flicker. So I decided to try giving InvalidateRect an hRgn. (type RECT)

    The code below has been adjusted for testing. A rectangle appears at the mouse pointer. BUT it only seems to appear when the x and y coordinates are close to the same. So you get unearased fragments of the box from 0,0 and continuing 0+1, 0+1... etc in a diaginal line down the window?!?!

    I read the technote on normalization of RECT and tried that with no positive results. Can anyone tell me what I'm missing?


    Code:
    	case WM_PAINT:
    		hdc = BeginPaint(hWnd, &ps);
    
    		MoveToEx(hdc,0,0,NULL);
    		LineTo(hdc,639,429);
    		MoveToEx(hdc,300,0,NULL);
    
    		LineTo(hdc,50,300);
    		TextOut(hdc,120,30,"<- a few lines ->",17);
    
    		Ellipse(hdc,250,250,450,450);
    		TextOut(hdc,345,330,"Ellipse",7);
    
    		Chord(hdc,550,20,630,80,555,25,625,70);
    		TextOut(hdc,470,30," A Chord ->",11);
    
    		Pie(hdc,300,50,400,150,300,50,300,100);
    		TextOut(hdc,350,80,"<- A Pie Wedge", 14);
    
    		Rectangle(hdc,550,300,700,400);
    		TextOut(hdc,710,350,"<- A Rectangle",14);
    
    		Rectangle(hdc,x,y,x+50,y+50);
    //		TextOut(hdc,x+20,y,"X-",2);
    //		TextOut(hdc,x+35,y,convertedX,(int)strlen(convertedX));
    //		TextOut(hdc,x+20,y+20,"Y-",2);
    //		TextOut(hdc,x+35,y+20,convertedY,(int)strlen(convertedY));
    
    		ValidateRect(hWnd,NULL);
    		EndPaint(hWnd,&ps);
    		break;
    	case WM_MOUSEMOVE:
    		x=LOWORD(lParam);
    		y=HIWORD(lParam);
    		itoa(x,convertedX,10);
    		itoa(y,convertedY,10);
    
    // coords is of type RECT
    		coords.left = y;
    		coords.top = x;
    		coords.bottom = x+40;
    		coords.right = y+40;
    
    		InvalidateRect(hWnd,&coords,TRUE);
    		UpdateWindow(hWnd);
    		break;
    Twin engine aircraft are way better. If one engine quits the other takes you to the scene of the crash.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,854
    Is the RECT a static? (or it will have lost its value before the paint)

    Don't need the ValidateRect(), BiginPaint() does that by default. Could use GetUpdateRect() before the BeginPaint().

    Try setting the flag to FALSE in InvalidateRect() and not calling for a paint again straight after wards.

    Or returning true to WM_ERASEBKGRD msg's.
    "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. IPv6 ping in windows...problem..lots of ode:(
    By Neill KElly in forum C Programming
    Replies: 3
    Last Post: 04-27-2009, 11:50 PM
  2. Exit Windows problem
    By cfrost in forum Windows Programming
    Replies: 7
    Last Post: 08-18-2004, 05:21 PM
  3. FlashWindowEx not declared?
    By Aidman in forum Windows Programming
    Replies: 3
    Last Post: 05-17-2003, 02:58 AM
  4. Application Termination Problem in Windows XP
    By wasabee in forum Windows Programming
    Replies: 2
    Last Post: 04-11-2003, 12:53 PM
  5. C++ Gurus, UNIX vs. Windows ascii problem perhaps?
    By puck in forum C++ Programming
    Replies: 6
    Last Post: 03-28-2003, 09:33 PM

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