LOGFONT structure
-
Hai All, In my application i want to set the lfHeight of the text using the LOGFONT structure. How can i use the LOGFONT structure and Font::FromLogFont in MC++? . I simply redefined the LOGFONT structure and uses it FromLogFont method. But runtime exception occures. Anyone have any idea?? Thanks in Advance Anish
-
Hai All, In my application i want to set the lfHeight of the text using the LOGFONT structure. How can i use the LOGFONT structure and Font::FromLogFont in MC++? . I simply redefined the LOGFONT structure and uses it FromLogFont method. But runtime exception occures. Anyone have any idea?? Thanks in Advance Anish
The function takes a pointer to a System::Object. You must cast the LOGFONT structure to a System::Object, using either __try_cast or reinterpret_cast. The other overload also takes a pointer to the device context in addition to the Object pointer.
-
The function takes a pointer to a System::Object. You must cast the LOGFONT structure to a System::Object, using either __try_cast or reinterpret_cast. The other overload also takes a pointer to the device context in addition to the Object pointer.
-
Hai, I couldn't get it. Also runtime exception occures even i type caste the LOGFONT structure. Can you show a simple piece of code using LOGFONT structure and Font::FromLogFont method thank u
you needn't use FromLogFont, you can set it as this:
LOGFONT lf; CFont* pFont; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = 20; lf.lfWeight = 900; strcpy(lf.lfFaceName, _T("Tahoma")); pFont = CFont::FromHandle(::CreateFontIndirect(&lf)); SetFont(pFont);
were rgrtgrtvrtrt rtrtb brt tyuhjghj hbhbnh hnjm 1234567? -
you needn't use FromLogFont, you can set it as this:
LOGFONT lf; CFont* pFont; memset(&lf, 0, sizeof(LOGFONT)); lf.lfHeight = 20; lf.lfWeight = 900; strcpy(lf.lfFaceName, _T("Tahoma")); pFont = CFont::FromHandle(::CreateFontIndirect(&lf)); SetFont(pFont);
were rgrtgrtvrtrt rtrtb brt tyuhjghj hbhbnh hnjm 1234567?I came across this over at the MSDN site: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkPlatformInvokeTutorial.asp[^] It's written for C# programmers, but, you use the same attribute in C++. Also, if you just want to set only the Font height, and leave all the other LOGFONT structure members in their default settings (except for the Face Name), you can just use the appropriate Font constructor from the .NET Framework class library (without calling the FromLogfont method). This is the simplest approach. You instantiate with the new operator, the same way you do for all Form controls. It occurred to me that the GDI LOGFONT structure is unmanaged code, and the Interop Marshaler makes the data conversions from managed to unmanaged and back again (if necessary). The problem with the LOGFONT struct, is that the original definition takes the lfFaceName mamber as an array of type TCHAR. Since this could be either ANSI or Unicode, the size of the array is not known at compile time. I assume the Interop Marshaler does not convert these values correctly (and, you'd think they'd note that in the documentation for the FromLogfont method). And, so you must specify this explicitly with the MarshalAs pseudo-custom attribute. There are lengthy explanations of the inner workings of Interop marshaling in Adam Nathan's book, ".NET and COM: The Complete Interoperability Guide".