can wxFont be created from native handle ? (msw)

Harry harry dot news at armadillo dot fr
Fri Apr 25 10:59:33 PDT 2008




Vadim, thanks for the answer.
It almost works, except that wxNativeFontInfo has no constructor with 
LOGFONT.
I found an undocumented function in fontutil.cpp which I use as follows:

extern wxFont wxCreateFontFromLogFont(const LOGFONT *logFont);

wxFont CreateFontFromHFONT(HFONT hfont)
{
    LOGFONT   lf;
    ::GetObject(hfont, sizeof lf, &lf);
    return wxCreateFontFromLogFont(&lf);
}

Regards
Harry

Vadim Zeitlin wrote:
> 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
>
>   


More information about the wx-users mailing list