How to refresh/redraw the screen (not the program window)

Posted by mohrphium on Stack Overflow See other posts from Stack Overflow or by mohrphium
Published on 2012-05-30T19:59:39Z Indexed on 2012/05/30 22:40 UTC
Read the original article Hit count: 234

Filed under:
|
|
|

I'm having a bit of a hard time figuring out, how to remove a drawn ellipse after it has been drawn somewhere else. I need a circle to follow my mouse all the time and this is all the program should do. I get the mousepositions and draw my circle but how can I remove the last one?

#include <Windows.h>
#include <iostream>

void drawRect(int a1, int a2){
HDC screenDC = ::GetDC(0);
//Draw circle at mouse position
::Ellipse(screenDC, a1, a2+5, a1+9, a2+14);
::ReleaseDC(0, screenDC);
//::InvalidateRect(0, NULL, TRUE); //<- I tried that but then everything flickers
//Also, the refresh rate is not fast enough... still some circles left
}

int main(void)
{

int a1;
int a2;
bool exit=false;
while (exit!=true)
    {
    POINT cursorPos;
    GetCursorPos(&cursorPos);
    float x = 0;
    x = cursorPos.x; 
    float y = 0;
    y = cursorPos.y;

    a1=(int)cursorPos.x;
    a2=(int)cursorPos.y; 
    drawRect(a1, a2);

    }
}

I am working with graphics and all that stuff for the first time. Im kinda stuck here... once again.

Thanks.

© Stack Overflow or respective owner

Related posts about c++

Related posts about draw