Hi -
I'm working on a program that's going to always be on top. Originally I was going use a topmost window with regions to make an oddly shaped window, but I thought it might be easier just to grab the Desktop DC via GetDC(NULL), but then I ran into a problem.
Because I'm drawing on portions of the DC for the whole screen, I have two possible outcomes:
1 - I just run my drawing code, something akin to the following, called several times each second:
HDC hdc;
HBRUSH hBrush;
hdc = GetDC(NULL);
hBrush = (HBRUSH)SelectObject(hdc, GetStockObject(BLACK_BRUSH));
Rectangle(hdc, m_X, m_Y, m_X + 10, m_Y + 10);
DeleteObject(SelectObject(hdc, hBrush));
ReleaseDC(NULL, hdc);
In this case, the little black squares from previous drawings are not deleted... meaning that if I have m_X and m_Y changing linearly (ie, m_X++, m_Y++ each time through), I end up having a line drawn on the screen until I force the windows beneath it (ie, anything on screen) to redraw.
2 - Taking the above code, and placing this before the GetDC(NULL):
static RECT rc;
rc.top = m_Y - 10;
rc.left = m_X - 10;
rc.bottom = m_Y + 10;
rc.right = m_X + 10;
InvalidateRect(NULL, &rc, TRUE);
This results in the same problem in some windows, and in other windows the entire window being forced to redraw, resulting in a flashing window as the redraws happen too fast to be handled between redraws on the screen.
Can anyone come up with anyway around this, so that I don't have the entire background to redraw each time? Or should I just bite the bullet and deal with Window regions?
Thanks!
Andrew
I'm working on a program that's going to always be on top. Originally I was going use a topmost window with regions to make an oddly shaped window, but I thought it might be easier just to grab the Desktop DC via GetDC(NULL), but then I ran into a problem.
Because I'm drawing on portions of the DC for the whole screen, I have two possible outcomes:
1 - I just run my drawing code, something akin to the following, called several times each second:
HDC hdc;
HBRUSH hBrush;
hdc = GetDC(NULL);
hBrush = (HBRUSH)SelectObject(hdc, GetStockObject(BLACK_BRUSH));
Rectangle(hdc, m_X, m_Y, m_X + 10, m_Y + 10);
DeleteObject(SelectObject(hdc, hBrush));
ReleaseDC(NULL, hdc);
In this case, the little black squares from previous drawings are not deleted... meaning that if I have m_X and m_Y changing linearly (ie, m_X++, m_Y++ each time through), I end up having a line drawn on the screen until I force the windows beneath it (ie, anything on screen) to redraw.
2 - Taking the above code, and placing this before the GetDC(NULL):
static RECT rc;
rc.top = m_Y - 10;
rc.left = m_X - 10;
rc.bottom = m_Y + 10;
rc.right = m_X + 10;
InvalidateRect(NULL, &rc, TRUE);
This results in the same problem in some windows, and in other windows the entire window being forced to redraw, resulting in a flashing window as the redraws happen too fast to be handled between redraws on the screen.
Can anyone come up with anyway around this, so that I don't have the entire background to redraw each time? Or should I just bite the bullet and deal with Window regions?
Thanks!
Andrew