Reputation: 1015
i've hit another wall in my printText function and have been searching for a while now for a solution with no luck.
Basically, the printText function is called within the WM_PAINT message to paint text to a win32 window. It works fine but only for one call. If i try to call the function for a second time with different parameters nothing appears to happen.
Im sure i am just completely overlooking something again but I can't see what it could possibly be.
the function is as follows:
void controls::printText(unsigned char R, unsigned char G, unsigned char B, int x, int y, LPCSTR text, HWND parent, PAINTSTRUCT pss, HDC hdc)
{
hdc = BeginPaint(parent, &pss);
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(R,G,B));
TextOut(hdc, x, y, text, strlen(text));
EndPaint(parent, &pss);
}
It is inside a 'controls' class and the calls are as follows:
HDC hdc, hdc2;
PAINTSTRUCT ps, ps2;
ctrls->printText(255,0,0,30,50,"Test text",hWnd,ps,hdc);
ctrls->printText(255,0,0,30,80,"test text 2",hWnd,ps2,hdc2);
There are two(2) HDC and PAINTSTRUCT declarations as I've been playing with the code trying to find a solution; I tried removing the paintstruct and hdc arguments from the function and having them declared inside the function as locals (which doesn't make a great deal of sense to me) with no success.
Basically, the first line,
ctrls->printText(255,0,0,30,50,"Test text",hWnd,ps,hdc);
Will do as it should and print "test text", in red, starting at (30,50) but the second line does not print anything. If i remove the first line, however, the second line works fine also.
please note: i may have used paint and print synonymously here whilst describing.
I think i've included everything relevant here but if any other code is needed just let me know and i'll post it as soon as i see the message :)
Thanks in advance again guys, your time and answers are much appreciated.
Upvotes: 1
Views: 1335
Reputation: 147018
The documentation quite clearly states
An application should not call BeginPaint except in response to a WM_PAINT message.
So you should call it once per WM_PAINT
and no more.
Upvotes: 4