WM_SETFONT et taille de charactere

glipper Messages postés 246 Date d'inscription dimanche 2 juin 2002 Statut Membre Dernière intervention 11 septembre 2016 - 16 déc. 2005 à 18:01
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019 - 17 déc. 2005 à 23:38
Bonjour,
je voudrais changer la police et la taille des characteres dans une edit box. J'ai fait ceci dans mon InitDialog, mais ça n'a aucun effet. Je ne comprend pas trop. Si quelqu'un pouvais m'expliquer ...

HFONT hFont ;
LOGFONT Fonte ;
Fonte.lfHeight=0;
Fonte.lfWidth=0;
Fonte.lfEscapement=0;
Fonte.lfOrientation=0;
Fonte.lfWeight=FW_NORMAL;
Fonte.lfItalic=FALSE;
Fonte.lfUnderline=FALSE;
Fonte.lfStrikeOut=0;
Fonte.lfCharSet=DEFAULT_CHARSET;
Fonte.lfOutPrecision=OUT_RASTER_PRECIS;
Fonte.lfClipPrecision=CLIP_DEFAULT_PRECIS;
Fonte.lfQuality=DEFAULT_QUALITY;
Fonte.lfPitchAndFamily=DEFAULT_PITCH | FF_DONTCARE ;
strcpy(Fonte.lfFaceName, TEXT("Arial"));
hFont=CreateFontIndirect(&Fonte) ;
if (!hFont)
MessageBox(hwnd, "Impossible de charger la fonte... CreateFontIndirect() renvoie NULL", "Erreur", MB_ICONERROR);
else
SendMessage(GetDlgItem(hwnd, IDC_EDIT_HEURE),WM_SETFONT,(WPARAM)hFont,MAKELPARAM(TRUE,0)); ....

Glipper

4 réponses

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
16 déc. 2005 à 19:10
HFONT hFontBold = 0;
HWND hed;

void __stdcall PrepareFontBold(HWND hEdit)
{
RECT rct;
GetClientRect(hEdit, &rct);
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfWeight = FW_BOLD;
lf.lfHeight = (long)-(rct.bottom * 3 / 4);
hFontBold = CreateFontIndirect(&lf);
}

BOOL CALLBACK dlgProc(...)
{
switch(mssg) {
case WM_INITDIALOG:
hed = GetDlgItem(hdlg, IDED_TRUC);
PrepareFontBold(hed);
SendMessage(hed, WM_SETFONT, (WPARAM) hFontBold, 1);

ciao...
http://dev.winsysdev.com
BruNews, MVP VC++
0
glipper Messages postés 246 Date d'inscription dimanche 2 juin 2002 Statut Membre Dernière intervention 11 septembre 2016 1
17 déc. 2005 à 23:26
J'ai utilisé ton code, mais cela ne marchait toujours pas (il ne se passait rien). Apres consultation de msdn sur WM_SETFONT je me suis aperçu que ce n'etait pas compatible avec la fonction DialogBox.J'ai finalement créé ma fenetre avec CreateWindow et maintenant c'est bon. Merci beaucoup.

Glipper
0
vecchio56 Messages postés 6535 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 22 août 2010 14
17 déc. 2005 à 23:37
Dans une dialogBox, tous les controles utilisent la même police (c'est logique car celle ci est utilisée pour calculer la position et la taille de chaque controle)
0
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
17 déc. 2005 à 23:38
NENNI, WM_SETFONT va très bien sur les controles de dialog, il y en a d'ailleurs plein mes sources.

ciao...
http://dev.winsysdev.com
BruNews, MVP VC++
0
Rejoignez-nous