VBA et API : calcul largeur et hauteur d'une chaine de caractères

jmnpib Messages postés 4 Date d'inscription lundi 15 août 2005 Statut Membre Dernière intervention 17 août 2005 - 17 août 2005 à 14:57
cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 - 27 août 2005 à 19:43
Est-ce que quelqu'un sait comment utiliser les API pour calculer la largeur et la hauteur d'un chaine de caractères en fonction de la police et de la taille. Comme avec textwidth et textheight en VB mais qui n'existent ppas dans VBA

Un exemple serait le bienvenu....

Merci

7 réponses

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
17 août 2005 à 15:31
GetTextExtentPoint32

ciao...
BruNews, MVP VC++
0
cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 130
17 août 2005 à 15:33
Il s'agit de la fonction de l'API Windows GetTextExtendPoint32 qui se base sur la Font sélectionnée dans le DC.

DarK Sidious

Un API Viewer (pour le VB, VB.NET, C, C# et Delphi) : www.ProgOtoP.Com/popapi/
0
jmnpib Messages postés 4 Date d'inscription lundi 15 août 2005 Statut Membre Dernière intervention 17 août 2005
17 août 2005 à 16:01
GetTextExtendPoint32 : je n'y connais pas grand chose en API, mais le nom ça j'avais pu le trouver tout seul...

Ca ne fait rien, je vais débrouiller de mon côté.

Merci
0
cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 130
17 août 2005 à 16:29
Extrait de l'API Guide :



Private Type POINTAPI

X As Long

Y As Long

End Type

Private Type RECT

Left As Long

Top As Long

Right As Long

Bottom As Long

End Type

Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Private Declare Function ExtTextOut Lib "gdi32" Alias "ExtTextOutA"
(ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal wOptions As
Long, ByVal lpRect As Any, ByVal lpString As String, ByVal nCount As
Long, lpDx As Long) As Long

Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias
"GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal
cbString As Long, lpSize As POINTAPI) As Long

Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

'KPD-Team 1998

'URL: http://www.allapi.net/

'E-Mail: KPDTeam@Allapi.net

Dim Pt As POINTAPI, mWnd As Long, WR As RECT, nDC As Long

Dim TextSize As POINTAPI, CX As Long, CY As Long

'Get the current cursor position

GetCursorPos Pt

'Get the window under the cursor

mWnd = WindowFromPoint(Pt.X, Pt.Y)

'Get the window's position

GetWindowRect mWnd, WR

'Get the window'zs device context

nDC = GetWindowDC(mWnd)

'Get the height and width of our text

GetTextExtentPoint32 nDC, "Hello !", Len("Hello !"), TextSize

For CX = 1 To WR.Right - WR.Left Step TextSize.X

For CY = 1 To WR.Bottom - WR.Top Step TextSize.Y

'Draw the text on the window


ExtTextOut nDC, CX, CY, 0, ByVal 0&, "Hello !", Len("Hello !"),
ByVal 0&

Next

Next

End Sub

Private Sub Form_Paint()

Me.CurrentX = 0

Me.CurrentY = 0

Me.Print "Click on this form," + vbCrLf + "Hold the
mouse button," + vbCrLf + "drag the mouse over another window," +
vbCrLf + "release the mouse button" + vbCrLf + "and see what happens!"

End Sub


DarK Sidious

Un API Viewer (pour le VB, VB.NET, C, C# et Delphi) : www.ProgOtoP.com/popapi/
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_Kots Messages postés 2 Date d'inscription dimanche 18 janvier 2004 Statut Membre Dernière intervention 27 août 2005
27 août 2005 à 16:30
Tu peux utiliser tout simplement l'API GetCaret.
0
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
27 août 2005 à 16:46
Inconnu dans API Windows.

ciao...
BruNews, MVP VC++
0
cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 130
27 août 2005 à 19:43
Hein ??? GetCaret ???

1) Ca n'existe pas (à ma connaissance)



2) Mais ca n'a rien à voir avec la largeur et la hauteur d'un texte, il s'agit juste du curseur de texte un Caret !

DarK Sidious

Un API Viewer (pour le VB, VB.NET, C, C# et Delphi) : www.ProgOtoP.com/popapi/
0
Rejoignez-nous