1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| #If Win64 Then
Public Function ChoisirPolice(Handle As LongPtr, PoliceParDefaut As Police) As Police
Dim Boite As CHOOSEFONT, laPolice As LOGFONT, hMem As LongPtr, pMem As LongPtr
Dim resultat As Long, Retour As Police, rep
#Else
Public Function ChoisirPolice(Handle As Long, PoliceParDefaut As Police) As Police
Dim Boite As CHOOSEFONT, laPolice As LOGFONT, hMem As Long, pMem As Long
Dim resultat As Long, Retour As Police, rep
#End If
'*****************************************
'definit la police par defaut à afficher
laPolice.lfStrikeOut = PoliceParDefaut.Barre
laPolice.lfWeight = IIf(PoliceParDefaut.Gras, FW_GRAS, FW_NORMAL)
laPolice.lfItalic = PoliceParDefaut.Italique
laPolice.lfUnderline = PoliceParDefaut.Souligne
laPolice.lfHeight = -PoliceParDefaut.Taille * GetDeviceCaps(GetDC(Handle), LOGPIXELSY) / 72
If PoliceParDefaut.Nom = "" Then PoliceParDefaut.Nom = "Tahoma"
laPolice.lfFaceName = PoliceParDefaut.Nom & vbNullChar 'Nom de la police par defaut
'******************************************
' Creer une structure LOGFont en memoire.
hMem = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len(laPolice))
'Verouille et recupere le pointeur vers la structure
pMem = GlobalLock(hMem)
'Copie la structure
CopyMemory ByVal pMem, laPolice, Len(laPolice)
'Initialise la boite de dialogue
Boite.lStructSize = Len(Boite)
Boite.hwndOwner = Handle
'Affecte la police par defaut
Boite.lpLogFont = pMem
'defini la taille (10*La taille de la police)
Boite.iPointSize = 120 'PoliceParDefaut.Taille * 10
'Personalise la boite
Boite.flags = CF_BOTH Or CF_EFFECTS Or CF_FORCEFONTEXIST Or _
CF_INITTOLOGFONTSTRUCT Or CF_LIMITSIZE Or _
CF_NOSCRIPTSEL
'Fixe la couleur
Boite.rgbColors = PoliceParDefaut.Couleur
Boite.nFontType = REGULAR_FONTTYPE
'Definit les tailles possibles
Boite.nSizeMin = 6
Boite.nSizeMax = 72
'''''''''''''''''''
'Ouvre la boite
'''''''''''''''''''
resultat = CHOOSEFONT(Boite)
If resultat <> 0 Then
CopyMemory laPolice, ByVal pMem, Len(laPolice)
'Prepare le resultat
Retour.Nom = Left(laPolice.lfFaceName, InStr(laPolice.lfFaceName, vbNullChar) - 1)
Retour.Taille = Boite.iPointSize \ 10
Retour.Couleur = Boite.rgbColors
Retour.Gras = laPolice.lfWeight > FW_NORMAL
Retour.Italique = laPolice.lfItalic
Retour.Souligne = laPolice.lfUnderline
Retour.Barre = laPolice.lfStrikeOut
End If
'libere la memoire
resultat = GlobalUnlock(hMem)
rep = GlobalFree(hMem)
ChoisirPolice = Retour
End Function |
Partager