Problem mit null-terminated string
-
Hallo zusammen,
ich möchte in der Struktur LogFont, die Schriftart "Tahoma" einsetzen (lfFaceName).
ich habe es schon so versucht aber es funktionirt nicht:
LOGFONT lf; lf.lfFaceName="Tahoma";
Da kommt aber die Fehlermeldung: error C2440: '=' : cannot convert from 'char [7]' to 'unsigned short [32]'.
Wie mache ich es richtig?typedef struct tagLOGFONT { LONG lfHeight; LONG lfWidth; LONG lfEscapement; LONG lfOrientation; LONG lfWeight; BYTE lfItalic; BYTE lfUnderline; BYTE lfStrikeOut; BYTE lfCharSet; BYTE lfOutPrecision; BYTE lfClipPrecision; BYTE lfQuality; BYTE lfPitchAndFamily; TCHAR lfFaceName[LF_FACESIZE]; } LOGFONT;
lfFaceName
Specifies a null-terminated string that specifies the typeface name of the font. The length of this string must not exceed 32 characters, including the terminating null character. The EnumFontFamilies function can be used to enumerate the typeface names of all currently available fonts. If lfFaceName is an empty string, GDI uses the first font that matches the other specified attributes.
-
lstrcpy(lf.lfFaceName, TEXT("Tahoma"));
-
Hoi,
Das kann nicht gehen, da lfFaceName ein C-String ist, sprich: Char-Vektor.
Du kannst C-Strings nicht mit = zuweisen!
TCHAR ist je nachdem entweder als char (ANSI) oder als wchar_t (UNICODE) definiert.Du musst bspw. die Funktion strcpy benutzen, also so:
ANSI:
LOGFONT lf; // ... strcpy(lf.lfFaceName, TEXT("Tahoma"));
UNICODE:
LOGFONT lf; // ... wcscpy(lf.lfFaceName, TEXT("Tahoma"));
UNABHÄNGIG ( + Maximalbeschränkung der zu kopierenden Zeichen):
#include <Shlwapi.h> // ... LOGFONT lf; // ... StrCpyN(lf.lfFaceName, TEXT("Tahoma"), LF_FACESIZE);
-
Danke schön,
hat funktioniert.
Gruß spacehelix