Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
500 views
in Technique[技术] by (71.8m points)

c# - get a button font from other applications

hi first sorry for my English i try to get a word under mouse

now my problem how to get the font of button

i try to use

 IntPtr dc=    GetDC(button1.Handle);
 IntPtr last_font = SelectObject(dc, Font.ToHfont());
         Font fon = Font.FromHdc(dc);

but it gave me the font of the form

and some time gave me error Only TrueType fonts are supported. This is not a TrueType font

after some trying with ch0kee answer

i get new result with this

 StringBuilder Buff = new StringBuilder(1024);
 IntPtr fxx = GetTextFace(dc, 1024, Buff); 

but Buff always return "system"

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should sent WM_GETFONT (0x0031) message to a button. See http://msdn.microsoft.com/en-us/library/ms632624(v=vs.85).aspx After processing that message handle of the font is returned.

Windows Forms uses pair message WM_SETFONT (0x0030) to set window font, you may see this via Reflector.NET in Control.OnFontChanged method.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...