Windows programming

Moderators: None (Apply to moderate this forum)
Number of threads: 3670
Number of posts: 9122

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
CreateIndirectFont() Posted by Jikko on 24 Oct 2005 at 10:10 AM

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
Report
Re: CreateIndirectFont() Posted by AsmGuru62 on 25 Oct 2005 at 3:58 AM
This message was edited by AsmGuru62 at 2005-10-25 4:0:27

:
: 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;
: 	strcpy(lf.lfFaceName, "Tahoma"); // why not specifying the name?
: 
: 		  hNFont=CreateFontIndirect(&lf);
: 		  hDefault=SelectObject(hDC,hNFont);
: 
: 		  TextOut(hDC...			
: 		  SelectObject(hDC,hDefault);
: 		  DeleteObject(hNFont);
: 		...
:                 ....
: 
: 	EndPaint(hWnd,&ps);
: 
: 		 break;
: 

:
:
: Where did I go wrong?
:
: Thanks for your help.
: Regards,
: Jikko
:



Report
Re: CreateIndirectFont() Posted by Jikko on 27 Oct 2005 at 4:44 AM
: This message was edited by AsmGuru62 at 2005-10-25 4:0:27

: :
: : 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;
: : 	strcpy(lf.lfFaceName, "Tahoma"); // why not specifying the name?
: : 
: : 		  hNFont=CreateFontIndirect(&lf);
: : 		  hDefault=SelectObject(hDC,hNFont);
: : 
: : 		  TextOut(hDC...			
: : 		  SelectObject(hDC,hDefault);
: : 		  DeleteObject(hNFont);
: : 		...
: :                 ....
: : 
: : 	EndPaint(hWnd,&ps);
: : 
: : 		 break;
: : 

: :



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
Report
Re: CreateIndirectFont() Posted by AsmGuru62 on 28 Oct 2005 at 4:10 AM
: : This message was edited by AsmGuru62 at 2005-10-25 4:0:27

: : :
: : : 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;
: : : 	strcpy(lf.lfFaceName, "Tahoma"); // why not specifying the name?
: : : 
: : : 		  hNFont=CreateFontIndirect(&lf);
: : : 		  hDefault=SelectObject(hDC,hNFont);
: : : 
: : : 		  TextOut(hDC...			
: : : 		  SelectObject(hDC,hDefault);
: : : 		  DeleteObject(hNFont);
: : : 		...
: : :                 ....
: : : 
: : : 	EndPaint(hWnd,&ps);
: : : 
: : : 		 break;
: : : 

: : :
:
:
:
: 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
:
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."




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.