can wxFont be created from native handle ? (msw)

Vadim Zeitlin vadim at wxwidgets.org
Thu Apr 24 10:36:39 PDT 2008


On Thu, 24 Apr 2008 17:20:05 +0200 Harry <"harry dot news at armadillo dot fr"@riobu.com> wrote:

H> The quick-and-dirty solution would be to wrap up the Windows font 
H> handles (HFONT) as wxFont.
H> Can this be done ? And how ?

 By using wxFont::Create(wxNativeFontInfo, HFONT). wxNativeFontInfo itself
can be obtained from LOGFONT, i.e. something like this should work
(warning, this code is completely untested and does no error checking):

	// create a wxFont from the given HFONT, taking ownership of it
	wxFont CreateFontFromHFONT(HFONT hfont)
	{
		LOGFONT lf;
		::GetObject(hfont, sizeof(lf), &lf);
		wxFont font;
		font.Create(wxNativeFontInfo(lf), hfont);
		return font;
	}

 Regards,
VZ

-- 
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/



More information about the wx-users mailing list