Puoi farlo solo per i controlli 'veri' cioè quelli che espongono la proprietà hWnd, per cui sono esclusi Label, Shape, Line, ecc...
Il codice è questo:
codice:
' Dichiarazioni
Private Declare Function GetWindowRect Lib "user32" _
(ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Sub GetControlPosition(ByVal hWnd As Long)
Dim r As Long
Dim wCtrl As Long 'larghezza finestra
Dim hCtrl As Long 'altezza finestra
Dim rc As RECT
r = GetWindowRect(hWnd, rc)
wCtrl = (rc.Right - rc.Left)
hCtrl = (rc.Bottom - rc.Top)
End Sub
Ovviamente come avviene con tutte le funzioni API i valori ricavati sono in pixels , che eventualmente puoi convertire in Twips moltiplicandoli per Screen.TwipsPerPixelX e Screen.TwipsPerPixelY.
Ad esempio:
rc.Left * Screen.TwipsPerPixelX
wCtrl * Screen.TwipsPerPixelX