CreateIndirectFont() - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

CreateIndirectFont()


Hi,

I have trouble with CreateIndirectFont(). When I run my program for a while the font size automatically change. Why could this happen?
Here is part of my code.

case WM_PAINT:
...
hDC = BeginPaint ( hWnd, &ps);

lf.lfWeight= FW_NORMAL;
lf.lfCharSet= ANSI_CHARSET;
lf.lfPitchAndFamily=35;
lf.lfHeight= 10;

hNFont=CreateFontIndirect(&lf);
SelectObject(hDC,hNFont);

TextOut(hDC...
DeleteObject(hNFont);
...
....

EndPaint(hWnd,&ps);

break;


Where did I go wrong?

Thanks for your help.
Regards,
Jikko

Comments

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    [b][red]This message was edited by AsmGuru62 at 2005-10-25 4:0:27[/red][/b][hr]
    :
    : Hi,
    :
    : I have trouble with CreateIndirectFont(). When I run my program for a while the font size automatically change. Why could this happen?
    : Here is part of my code.
    : [code]
    : case WM_PAINT:
    : ...
    : hDC = BeginPaint ( hWnd, &ps);
    :
    : lf.lfWeight= FW_NORMAL;
    : lf.lfCharSet= ANSI_CHARSET;
    : lf.lfPitchAndFamily=35;
    : lf.lfHeight= 10;
    : [red]strcpy(lf.lfFaceName, "Tahoma"); // why not specifying the name?[/red]
    :
    : hNFont=CreateFontIndirect(&lf);
    : [red]hDefault=[/red]SelectObject(hDC,hNFont);
    :
    : TextOut(hDC...
    : [red]SelectObject(hDC,hDefault);[/red]
    : DeleteObject(hNFont);
    : ...
    : ....
    :
    : EndPaint(hWnd,&ps);
    :
    : break;
    : [/code]
    :
    :
    : Where did I go wrong?
    :
    : Thanks for your help.
    : Regards,
    : Jikko
    :



  • JikkoJikko Posts: 3Member
    : [b][red]This message was edited by AsmGuru62 at 2005-10-25 4:0:27[/red][/b][hr]
    : :
    : : Hi,
    : :
    : : I have trouble with CreateIndirectFont(). When I run my program for a while the font size automatically change. Why could this happen?
    : : Here is part of my code.
    : : [code]
    : : case WM_PAINT:
    : : ...
    : : hDC = BeginPaint ( hWnd, &ps);
    : :
    : : lf.lfWeight= FW_NORMAL;
    : : lf.lfCharSet= ANSI_CHARSET;
    : : lf.lfPitchAndFamily=35;
    : : lf.lfHeight= 10;
    : : [red]strcpy(lf.lfFaceName, "Tahoma"); // why not specifying the name?[/red]
    : :
    : : hNFont=CreateFontIndirect(&lf);
    : : [red]hDefault=[/red]SelectObject(hDC,hNFont);
    : :
    : : TextOut(hDC...
    : : [red]SelectObject(hDC,hDefault);[/red]
    : : DeleteObject(hNFont);
    : : ...
    : : ....
    : :
    : : EndPaint(hWnd,&ps);
    : :
    : : break;
    : : [/code]
    : :



    Hi,

    Thanks for your reply.
    Would you please, explain more detail why do I have to add a few more line? I just made copy&paste&modify from my Windows programming book.

    My best,
    Teerapong
  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : : [b][red]This message was edited by AsmGuru62 at 2005-10-25 4:0:27[/red][/b][hr]
    : : :
    : : : Hi,
    : : :
    : : : I have trouble with CreateIndirectFont(). When I run my program for a while the font size automatically change. Why could this happen?
    : : : Here is part of my code.
    : : : [code]
    : : : case WM_PAINT:
    : : : ...
    : : : hDC = BeginPaint ( hWnd, &ps);
    : : :
    : : : lf.lfWeight= FW_NORMAL;
    : : : lf.lfCharSet= ANSI_CHARSET;
    : : : lf.lfPitchAndFamily=35;
    : : : lf.lfHeight= 10;
    : : : [red]strcpy(lf.lfFaceName, "Tahoma"); // why not specifying the name?[/red]
    : : :
    : : : hNFont=CreateFontIndirect(&lf);
    : : : [red]hDefault=[/red]SelectObject(hDC,hNFont);
    : : :
    : : : TextOut(hDC...
    : : : [red]SelectObject(hDC,hDefault);[/red]
    : : : DeleteObject(hNFont);
    : : : ...
    : : : ....
    : : :
    : : : EndPaint(hWnd,&ps);
    : : :
    : : : break;
    : : : [/code]
    : : :
    :
    :
    :
    : Hi,
    :
    : Thanks for your reply.
    : Would you please, explain more detail why do I have to add a few more line? I just made copy&paste&modify from my Windows programming book.
    :
    : My best,
    : Teerapong
    :
    [blue]The book you are using is wrong. Use Petzold's book or use MSDN:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/devcons_1vsk.asp

    The quote: "Do not delete a drawing object (pen or brush) while it is still selected into a DC."
    [/blue]
Sign In or Register to comment.