I posted this this morning on a newsgroup, but no one
is answering questions there, I guess the newsgroup is
dead.
<my post>
I'm a newbie to the Window's platform and I need some
help. I have a program I'm working on that draws and
animates a piano keyboard based on notes received from
the mic on the sound card. The program works fine for
a few minutes BUT after a while the black brush color
(the fill color for rectangles, circles, ...) does not
work anymore so when the keyboard is re-painted, the
black notes of the piano end up white with a black
outline. Also the Windows borders get screwed up
(buttons and menus etc).Now when I draw the keyboard, I always set the brush
color first, so theoretically what is happening is
impossible.If I change the brush color, do I need to restore it
before I return from processing a message?This is how I do things:
Note: I do not use BeginPaint() as I am not in a
WM_PAINT message handler. I am processing a data
message comming from the sound card.
<SNIPPED>
hdc = GetDC(pparams2->hwnd);
// NOTE: I save and restore the DC but this did not
help at all
state= SaveDC(hdc);
// Brush color change and draw whatever...
WhiteOutlineWhiteFill(hdc);
or
BlackOutlineBlackFill(hdc);
RestoreDC(hdc, state);
ReleaseDC (pparams2->hwnd, hdc) ;
<SNIPPED>
void WhiteOutlineWhiteFill(HDC hdc)
{
HBRUSH NewBrush;
HPEN hPen;
// Set pen and brush to white
hPen = CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
SelectObject(hdc, hPen);
NewBrush = CreateSolidBrush(RGB(255, 255, 255));
SelectObject(hdc, NewBrush);
}
void BlackOutlineBlackFill(HDC hdc)
{
HBRUSH NewBrush;
HPEN hPen;
// Set pen and brush to black
hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
SelectObject(hdc, hPen);
NewBrush = CreateSolidBrush(RGB(0, 0, 0));
SelectObject(hdc, NewBrush);
}
I have and XP system (SP2) and use DevStudio 6.0. I have latest updates.
Thanks for any help.
PeterPurple.