Click to See Complete Forum and Search --> : textout in second thread


lopez86100
September 14th, 2007, 07:55 PM
When I run textout in function lunched with CreateThread() (the same effect with _beginthread) text doesn't appear on window. But when I run this function normally , it sends text to the window. Here is the function





DWORD WINAPI SetScreenText(void * data){

InvalidateRect(hwnda, NULL, TRUE);
RedrawWindow(hwnda, NULL, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_ERASENOW | RDW_UPDATENOW | RDW_INTERNALPAINT);
HDC df;
UpdateWindow(hwnda);
SetBkMode((df=GetDC(hwnda)), TRANSPARENT);
/*

SetTextColor(
df, // handle to DC
0xFF << 0 // text color
);

*/
ExtTextOut(
df, // handle to DC
10, // x-coordinate of starting position
10, // y-coordinate of reference point
ETO_CLIPPED, // text-output options
NULL, // optional dimensions
text, // character string
size , // number of characters in string
NULL // array of spacing values
);


}

//some of variables are global

ahoodin
September 17th, 2007, 09:32 AM
Well can you put the data in a variable during your thread, and flag a Window Update? Then just set the text in the window with WM_PAINT. A problem may occur when the dialog closes but the new thread is still trying to update it.

HTH,

Boris K K
September 17th, 2007, 10:50 AM
Do you really need all these InvalidateRect/RedrawWindow/UpdateWindow?

GetDC(HWND) is different from BeginPaint(HWND,...) in that there are no protected regions which do not need painting in the returned DC.

lopez86100
September 29th, 2007, 04:24 PM
I don't know why it didn't work, but when I put text in a global variable the problem appear to be resolved. Thanks for help