Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.