Archived

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

phil05

Win32 LOGFONT question

Recommended Posts

Aight, where do I define the font name?
LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg,
                               WPARAM wParam, LPARAM lParam)
{
    HDC         hDC;
    PAINTSTRUCT Ps;
    HFONT	    font;
    LOGFONT LogFont;

    switch(Msg)
    {
    case WM_PAINT:
	hDC = BeginPaint(hWnd, &Ps);
		        
        LogFont.lfStrikeOut = 0;
        LogFont.lfUnderline = 0;
        LogFont.lfHeight = 42;
        LogFont.lfEscapement = 0;
        LogFont.lfItalic = TRUE;

        font = CreateFontIndirect(&LogFont);
        SelectObject(hDC, font);
        TextOut(hDC, 20, 18, "James Kolowski", 14);

        DeleteObject(font);

	EndPaint(hWnd, &Ps);
	break;
    case WM_DESTROY:
	PostQuitMessage(WM_QUIT);
	break;
    default:
	return DefWindowProc(hWnd, Msg, wParam, lParam);
    }
    return 0;
}
 

Share this post


Link to post
Share on other sites
I tried this...

LogFont.lfFaceName = "Times New Roman";

And I got...

error C2440: ''='' : cannot convert from ''char [16]'' to ''char [32]''
There is no context in which this conversion is possible

Share this post


Link to post
Share on other sites
lstrcpy(LogFont.lfFaceName, "Times New Roman");

In C/C++ langauges you have to copy the bytes that make up the string unless you are using a string class which defines an = operator. It would be even better to use a string copy function that copies a certain number of characters to prevent buffer overflow.

#include <tchar.h>
.
.
.
_tcsncpy(LogFont.lfFaceName, "Times New Roman", LF_FACESIZE);

Share this post


Link to post
Share on other sites
Which example is more preferable to use? Either way, thanks for the help. It works nicely.

EDIT: Oh I understand now. Sounds good, thanks.

[edited by - philvaira on May 17, 2004 9:52:10 PM]

Share this post


Link to post
Share on other sites