Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

WhiteRaptor

GDI Font problem

This topic is 6063 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m having a problem with changing Fonts with a simple GDI TextOut method. The font will display in the intended size/style that I called for with the CreateFont for a brief period. Then, after maybe a minute or so, it reverts to a different (default?) font/size. I''ve tried creating the Font inside and out of the function (code is below), but nothing''s changed. Has anyone else encountered this? ////////////////////////////////////////////////////////////// int Draw_FText_GDI(char * text, int x,int y, COLORREF color, LPDIRECTDRAWSURFACE4 lpdds, HFONT fnt) { HDC xdc; // the working dc if (FAILED(lpdds->GetDC(&xdc))) return(0); SetTextColor(xdc,color); SetBkMode(xdc, TRANSPARENT); SelectObject (xdc, fnt); TextOut(xdc,x,y,text,strlen(text)); lpdds->ReleaseDC(xdc); return(1); }

Share this post


Link to post
Share on other sites
Advertisement
I''m pretty sure what''s happening is that it''s leaking resources until it can no longer select the font into the DC. Try this:

//////////////////////////////////////////////////////////////
int Draw_FText_GDI(char * text, int x,int y,
COLORREF color, LPDIRECTDRAWSURFACE4 lpdds, HFONT fnt)
{
HDC xdc; // the working dc

if (FAILED(lpdds->GetDC(&xdc)))
return(0);

SetTextColor(xdc,color);

SetBkMode(xdc, TRANSPARENT);

// Record the old font.
HFONT oldfnt = SelectObject (xdc, fnt);

TextOut(xdc,x,y,text,strlen(text));

// Restore the old font.
SelectObject(xdc, oldfnt);

lpdds->ReleaseDC(xdc);

return(1);
}

Share this post


Link to post
Share on other sites
Thanks for pointing me in the right direction. The code below is what I got to work for me. My problem of the font changing on it''s own has vanished. Thanks again.

//////////////////////////////////////////////////////////
int Draw_FontText_GDI(char * text, int x,int y,
COLORREF color, LPDIRECTDRAWSURFACE4 lpdds, HFONT fnt)
{
HDC xdc; // the working dc

if (FAILED(lpdds->GetDC(&xdc)))
return(0);

SetTextColor(xdc,color);

SetBkMode(xdc, TRANSPARENT);

HFONT oldfnt = (HFONT)SelectObject(xdc, fnt);

SelectObject(xdc,fnt);

TextOut(xdc,x,y,text,strlen(text));

SelectObject(xdc, oldfnt);

DeleteObject(fnt);
DeleteObject(oldfnt);

lpdds->ReleaseDC(xdc);

return(1);
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!