November 12th, 2013, 06:31 AM
About CreateFont function ..
Hi All ,
I needed to change Default Text attributes (font and color) . So I wrote following code , UnicodeTextOut function. I called this function once in each 55ms to update the display screen. but I observed that my Screen used to become grey
like a crash after sometime . If I use Minimize an Maximize window , the screen was restoring back for some time.
When I thought over the code , I got my mistake that CreateFont initialization should be done once in the program and probably outside the function.
void UnicodeTextOut(int x, int y, CString s, UINT justify,int GreyScaleFlag)
HFONT hfOld ;
hFontUnicode = CreateFont(16, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, _T("Aerial"));
hfOld = (HFONT) SelectObject(hdc, hFontUnicode);
TextOut(hdc, x, y, s, s.GetLength());
Then I shifted the line hFontUnicode = CreateFont(16, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, _T("Aerial")); in my screen class constructor and made hFontUnicode global .
This solved my problem as expected.
PL explain me why a system crash after certain no of CreateFont calls ? I am curious to know.
pl pl ..
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!