System::Drawing::Font::ToLogFont example needed

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

I am trying to get a LOGFONT structure from the
System::Drawing::Font class using ToLogFont
(System::Object*) in a managed C++ application. I need
the LOGFONT for some legacy C++ code. I cannot figure out
how to give ToLogFont an Object* of a LOGFONT that it will
return me a good GDI LOGFONT structure. Any example of
how to do this would be much appreaciated!
 
Hi Bob,
Thanks for your post!
To use ToLogFont method in the Font class, you need first define a managed
class for the LOGFONT struct. After getting the information , you can create
a copy of LOGFONT structure.Here is a small sample for this:
<code>
#include "stdafx.h"

#using <mscorlib.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Runtime::InteropServices;
[StructLayout(LayoutKind::Sequential, CharSet=CharSet::Auto)]
__gc class LogFont
{
public:
int lfHeight;
int lfWidth;
int lfEscapement;
int lfOrientation;
int lfWeight;
char lfItalic;
char lfUnderline;
char lfStrikeOut;
char lfCharSet;
char lfOutPrecision;
char lfClipPrecision;
char lfQuality;
char lfPitchAndFamily;
[MarshalAs(UnmanagedType::ByValTStr, SizeConst=32)]
String* lfFaceName;
};
int _tmain()
{
// TODO: Please replace the sample code below with your own.
Font* f = new Font( "Comic Sans MS", 10 );
LogFont* lf = new LogFont();
f->ToLogFont(lf);
Console::WriteLine(lf->lfFaceName);
f->Dispose();
Console::Read();
return 0;
}
</code>
If you have anything unclear, please reply to the group.
Thanks!


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!
 
Back
Top