On Mon, 28 May 2001 22:09:05 +0200, "Simon Veith Reinholt"
<haze@ostenfeld.dtu.dk> wrote:
>Er der en systemdefineret font? Eller hvor kan jeg finde et handle til den
>font windows bruger? Det kan vel ikke være meningen at hvert eneste program
>skal loade en font bare for at tegne en knap...
Jo!
Du skal bruge LOGFONT strukturen til at skabe din font, og derefter
sende en WM_SETFONT til knappen.
Inden dit program afsluttes skal du huske at kalde DeleteObject på din
font.
Jeg har skrevet en lille funktion, som jeg selv bruger til nemt at
hente de fonte, som jeg bruger (se nedenstående).
Så bruger jeg den sådan:
<snip>
HFONT hFont;
</snip>
<snip>
WM_CREATE:
SendMessage (hwnd, WM_SETFONT, (WPARAM) hFont = GetFont ("Tahoma",
13, FW_NORMAL), 0);
</snip>
<snip>
WM_DESTROY:
DeleteObject (hFont);
</snip>
Er det ikke nemt?
Hygge
Chris
PS. Sorry! Jeg udgiver under GPL, så hvis du bruger min funktion, så
vær venlig også at medtage license beskrivelsen.
/* GetFont.c
* Copyright (C) 2001 by Next Generation
* Written by Chris Hansen.
*
* This program is free software; you can redistribute it and/or
modify
* it under the terms of the GNU General Public License as published
by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
*
* NEXT GENERATION on the Web:
www.nextgeneration.dk
* CONTACT: info@nextgeneration.dk
*/
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
HFONT
GetFont (const char *lpFont, long fSize, long fWeight)
{
LOGFONT logfont;
HFONT hFont;
logfont.lfHeight = fSize;
logfont.lfWidth = 0;
logfont.lfEscapement = 0;
logfont.lfOrientation = 0;
logfont.lfWeight = fWeight;
logfont.lfItalic = 0;
logfont.lfUnderline = 0;
logfont.lfStrikeOut = 0;
logfont.lfCharSet = DEFAULT_CHARSET;
logfont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
lstrcpy (logfont.lfFaceName, lpFont);
hFont = CreateFontIndirect (&logfont);
return hFont;
}