Convert MFC Fonts to c# Fonts

S

stulika19

hi,
I have an application developed in MFC( VC++ 6.0 ) where the
information all the parameters of CreateFont function of CFont is
stored in a file. Now I am rewriting the whole application in c#. But I
am not able to map all the paramters of CreateFont to the Font class
of c# and to provide backward compatibility it is important. Can
anyone suggest me a possible workaround for this problem????
 
N

Nicholas Paldino [.NET/C# MVP]

There really isn't any such thing as a MFC font. There is a
representation, yes, but it is just a wrapper over the font services that
are provided by the OS, which are available in .NET as well.

How are you storing the parameters in the file? If you can read this
file format in C# as well, you can call the CreateFont API function through
the P/Invoke layer, and then pass the handle to the static FromHfont method
on the Font class.

Either that, or you can probably create the font through the parameters
offered on the constructor of the Font instance.

Hope this helps.
 
S

stulika19

well as i wrote that theinformation is stored based on the parameters
of CreateFont function.The format is as below:
1. LoByte (Point size for Font)
2. LoByte (Point size for Font)
3. LoByte(LoWord(Height))
4. HiByte(LoWord(Height))
5. LoByte(HiWord(Height))
6. HiByte(HiWord(Height))
7. LoByte(LoWord(Width))
8. HiByte(LoWord(Width))
9. LoByte(HiWord(Width))
10. HiByte(HiWord(Width))
11. LoByte(LoWord(Escapement))
12. HiByte(LoWord(Escapement))
13. LoByte(HiWord(Escapement))
14. HiByte(HiWord(Escapement))
15. LoByte(LoWord(Orientation))
16. HiByte(LoWord(Orientation))
17. LoByte(HiWord(Orientation))
18. HiByte(HiWord(Orientation))
19. LoByte(LoWord(Weight))
20. HiByte(LoWord(Weight))
21. LoByte(HiWord(Weight))
22. HiByte(HiWord(Weight))
23. Italic(byte)
24. Underline(byte)
25. StrikeOut(byte)
26. CharSet(byte)
27. OutPrecision(byte)
28. ClipPrecision(byte)
29. Quality (byte)
30. PitchAndFamily(byte)
31. Length of face name (L)
For Length L following 2 bytes will be repeated
1. LoByte (character of face name)
2. HiByte (character of face name)

Here the first inforation i.e.Point size for Font is the value which we
get from the
CFontDialog::GetSize()
function and the rest of the information are the the parameters of the
CFont::CreateFont( int nHeight, int nWidth, int nEscapement, int
nOrientation, int nWeight, BYTE bItalic, BYTE bUnderline, BYTE
cStrikeOut, BYTE nCharSet, BYTE nOutPrecision, BYTE nClipPrecision,
BYTE nQuality, BYTE nPitchAndFamily, LPCTSTR lpszFacename ).

But i am not able to map all these parameters to their corresponding c#
values and thus cant open the application developed using the previous
version( MFC ) and see the fonts properly.

Can u put some more light on ur first suggestion i.e calling the
CreateFont API function through the P/Invoke layer and then passing the
handle to the static FromHfont method on the Font class???
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top