471,599 Members | 927 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,599 software developers and data experts.

Convert MFC Fonts to c# Fonts

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????

Feb 13 '06 #1
2 3179
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<st*******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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????

Feb 13 '06 #2
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???

Feb 15 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jack Charbonneau | last post: by
4 posts views Thread by L | last post: by
13 posts views Thread by kbperry | last post: by
4 posts views Thread by Aaron Gray | last post: by
12 posts views Thread by ctclibby | last post: by
1 post views Thread by TKM | last post: by
2 posts views Thread by XIAOLAOHU | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.