• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Windows Developers, please help with GDI question

Nevyn522

Senior member
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
 
Back
Top