Const VerticalScrollBarBordersPixels As Long = 2 * 2.5 'Borders around the Vertical Scroll Bar
Const HorizontalScrollBarBordersPixels As Long = 2 * 4 'Borders around the Horizontal Scroll Bar
Const StatusBarHeightPixels = 26
With Window
EVRRS = ExactVisibleRangeRECTToScreen(Window)
EVRRW.Left = EVRRS.Left - .PointsToScreenPixelsX(0) + CXBORDER
EVRRW.Right = EVRRS.Right - .PointsToScreenPixelsX(0) + IIf(.DisplayVerticalScrollBar, CXBORDER, 0)
EVRRW.Top = EVRRS.Top - .PointsToScreenPixelsY(0) + CYBORDER
EVRRW.Bottom = EVRRS.Bottom - .PointsToScreenPixelsY(0) + IIf(Application.DisplayStatusBar, CYBORDER, 0)
End With
Oui, je sais bien mais cette méthode RangeFromPoint et la méthode Usable donnent un résultat différent de 1 pixel en H et V en maximisé (en réduit je sais pas, je vais essayer en forçant les tailles de fenêtre).c'est le principe du getpixel en fait sauf que la on a un object retourné
si c'est pas nothing on est donc dedans
donc il ne peut pas y avoir d'erreur puisque je descend pixel par pixel et va a droite pixel par pixel
Si tu ne le fais pas tu ne peux pas vérifier visuellement dans le brouillard des marges droite et basse.maintenant pour corriger l'affichage du userform je n'utilise pas dwm
With Window.Panes(1)
EVRRS = ExactVisibleRangeRECTToScreen(Window)
EVRRW.Left = EVRRS.Left - .PointsToScreenPixelsX(0) + CXBORDER
EVRRW.Right = EVRRS.Right - .PointsToScreenPixelsX(0)
EVRRW.Top = EVRRS.Top - .PointsToScreenPixelsY(0) + CYBORDER
EVRRW.Bottom = EVRRS.Bottom - .PointsToScreenPixelsY(0)
End With
Option Explicit
#If VBA7 Then
Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare PtrSafe Function GetDpiForWindow Lib "user32" (ByVal hwnd As LongPtr) As Long
#Else
Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function GetDpiForWindow Lib "user32" (ByVal hwnd As Long) As Long
#End If
Public Function GetDpi() As Long
GetDpi = GetDpiForWindow(ActiveWindow.hwnd)
End Function
Sub a()
Const SM_CXEDGE = 45
Const SM_CYEDGE = 46
MsgBox "DPI = " & GetDpi & vbCrLf & _
"SM_CXEDGE = " & GetSystemMetrics(SM_CXEDGE) & vbCrLf & _
"SM_CYEDGE = " & GetSystemMetrics(SM_CYEDGE)
End Sub
Constant | Index | Pixels | Points |
SM_CXSCREEN | 0 | 1920 | 1440 |
SM_CYSCREEN | 1 | 1080 | 810 |
SM_CXVSCROLL | 2 | 17 | 12,75 |
SM_CYHSCROLL | 3 | 17 | 12,75 |
SM_CYCAPTION | 4 | 23 | 17,25 |
SM_CXBORDER | 5 | 1 | 0,75 |
SM_CYBORDER | 6 | 1 | 0,75 |
SM_CXDLGFRAME | 7 | 3 | 2,25 |
SM_CYDLGFRAME | 8 | 3 | 2,25 |
SM_CYVTHUMB | 9 | 17 | 12,75 |
SM_CXHTHUMB | 10 | 17 | 12,75 |
SM_CXICON | 11 | 32 | 24 |
SM_CYICON | 12 | 32 | 24 |
SM_CXCURSOR | 13 | 32 | 24 |
SM_CYCURSOR | 14 | 32 | 24 |
SM_CYMENU | 15 | 20 | 15 |
SM_CXFULLSCREEN | 16 | 1920 | 1440 |
SM_CYFULLSCREEN | 17 | 1017 | 762,75 |
SM_CYKANJIWINDOW | 18 | 0 | 0 |
SM_MOUSEPRESENT | 19 | 1 | 0,75 |
SM_CYVSCROLL | 20 | 17 | 12,75 |
SM_CXHSCROLL | 21 | 17 | 12,75 |
SM_DEBUG | 22 | 0 | 0 |
SM_SWAPBUTTON | 23 | 0 | 0 |
SM_RESERVED1 | 24 | 0 | 0 |
SM_RESERVED2 | 25 | 0 | 0 |
SM_RESERVED3 | 26 | 0 | 0 |
SM_RESERVED4 | 27 | 0 | 0 |
SM_CXMIN | 28 | 136 | 102 |
SM_CYMIN | 29 | 39 | 29,25 |
SM_CXSIZE | 30 | 36 | 27 |
SM_CYSIZE | 31 | 22 | 16,5 |
SM_CXFRAME | 32 | 4 | 3 |
SM_CYFRAME | 33 | 4 | 3 |
SM_CXMINTRACK | 34 | 136 | 102 |
SM_CYMINTRACK | 35 | 39 | 29,25 |
SM_CXDOUBLECLK | 36 | 4 | 3 |
SM_CYDOUBLECLK | 37 | 4 | 3 |
SM_CXICONSPACING | 38 | 93 | 69,75 |
SM_CYICONSPACING | 39 | 75 | 56,25 |
SM_MENUDROPALIGNMENT | 40 | 0 | 0 |
SM_PENWINDOWS | 41 | 0 | 0 |
SM_DBCSENABLED | 42 | 0 | 0 |
SM_CMOUSEBUTTONS | 43 | 16 | 12 |
SM_CMETRICS | 44 | 0 | 0 |
SM_CXEDGE | 45 | 2 | 1,5 |
SM_CYEDGE | 46 | 2 | 1,5 |
SM_CXMINSPACING | 47 | 199 | 149,25 |
SM_CYMINSPACING | 48 | 34 | 25,5 |
SM_CXSMICON | 49 | 16 | 12 |
SM_CYSMICON | 50 | 16 | 12 |
SM_CYSMCAPTION | 51 | 23 | 17,25 |
SM_CXSMSIZE | 52 | 22 | 16,5 |
SM_CYSMSIZE | 53 | 22 | 16,5 |
SM_CXMENUSIZE | 54 | 19 | 14,25 |
SM_CYMENUSIZE | 55 | 19 | 14,25 |
SM_ARRANGE | 56 | 8 | 6 |
SM_CXMINIMIZED | 57 | 199 | 149,25 |
SM_CYMINIMIZED | 58 | 34 | 25,5 |
SM_CXMAXTRACK | 59 | 1940 | 1455 |
SM_CYMAXTRACK | 60 | 1100 | 825 |
SM_CXMAXIMIZED | 61 | 1936 | 1452 |
SM_CYMAXIMIZED | 62 | 1056 | 792 |
SM_NETWORK | 63 | 3 | 2,25 |
64 | 0 | 0 | |
65 | 0 | 0 | |
66 | 0 | 0 | |
SM_CLEANBOOT | 67 | 0 | 0 |
SM_CXDRAG | 68 | 4 | 3 |
SM_CYDRAG | 69 | 4 | 3 |
SM_SHOWSOUNDS | 70 | 0 | 0 |
SM_CXMENUCHECK | 71 | 15 | 11,25 |
SM_CYMENUCHECK | 72 | 15 | 11,25 |
SM_SLOWMACHINE | 73 | 0 | 0 |
SM_MIDEASTENABLED | 74 | 0 | 0 |
SM_MOUSEWHEELPRESENT | 75 | 1 | 0,75 |
SM_XVIRTUALSCREEN | 76 | 0 | 0 |
SM_YVIRTUALSCREEN | 77 | 0 | 0 |
SM_CXVIRTUALSCREEN | 78 | 1920 | 1440 |
SM_CYVIRTUALSCREEN | 79 | 1080 | 810 |
SM_CMONITORS | 80 | 1 | 0,75 |
SM_SAMEDISPLAYFORMAT | 81 | 1 | 0,75 |
SM_IMMENABLED | 82 | 1 | 0,75 |
SM_CXFOCUSBORDER | 83 | 1 | 0,75 |
SM_CYFOCUSBORDER | 84 | 1 | 0,75 |
85 | 4 | 3 | |
SM_TABLETPC | 86 | 0 | 0 |
SM_MEDIACENTER | 87 | 0 | 0 |
SM_STARTER | 88 | 0 | 0 |
SM_SERVERR2 | 89 | 0 | 0 |
90 | 0 | 0 | |
SM_MOUSEHORIZONTALWHEELPRESENT | 91 | 0 | 0 |
SM_CXPADDEDBORDER | 92 | 4 | 3 |
93 | 964 | 723 | |
SM_DIGITIZER | 94 | 0 | 0 |
SM_MAXIMUMTOUCHES | 95 | 0 | 0 |
Constant | Index | Pixels | Points |
SM_CXSCREEN | 0 | 1920 | 1152 |
SM_CYSCREEN | 1 | 1080 | 648 |
SM_CXVSCROLL | 2 | 21 | 12,6 |
SM_CYHSCROLL | 3 | 21 | 12,6 |
SM_CYCAPTION | 4 | 29 | 17,4 |
SM_CXBORDER | 5 | 1 | 0,6 |
SM_CYBORDER | 6 | 1 | 0,6 |
SM_CXDLGFRAME | 7 | 3 | 1,8 |
SM_CYDLGFRAME | 8 | 3 | 1,8 |
SM_CYVTHUMB | 9 | 21 | 12,6 |
SM_CXHTHUMB | 10 | 21 | 12,6 |
SM_CXICON | 11 | 40 | 24 |
SM_CYICON | 12 | 40 | 24 |
SM_CXCURSOR | 13 | 32 | 19,2 |
SM_CYCURSOR | 14 | 32 | 19,2 |
SM_CYMENU | 15 | 25 | 15 |
SM_CXFULLSCREEN | 16 | 1920 | 1152 |
SM_CYFULLSCREEN | 17 | 1001 | 600,6 |
SM_CYKANJIWINDOW | 18 | 0 | 0 |
SM_MOUSEPRESENT | 19 | 1 | 0,6 |
SM_CYVSCROLL | 20 | 21 | 12,6 |
SM_CXHSCROLL | 21 | 21 | 12,6 |
SM_DEBUG | 22 | 0 | 0 |
SM_SWAPBUTTON | 23 | 0 | 0 |
SM_RESERVED1 | 24 | 0 | 0 |
SM_RESERVED2 | 25 | 0 | 0 |
SM_RESERVED3 | 26 | 0 | 0 |
SM_RESERVED4 | 27 | 0 | 0 |
SM_CXMIN | 28 | 166 | 99,6 |
SM_CYMIN | 29 | 47 | 28,2 |
SM_CXSIZE | 30 | 46 | 27,6 |
SM_CYSIZE | 31 | 28 | 16,8 |
SM_CXFRAME | 32 | 4 | 2,4 |
SM_CYFRAME | 33 | 4 | 2,4 |
SM_CXMINTRACK | 34 | 166 | 99,6 |
SM_CYMINTRACK | 35 | 47 | 28,2 |
SM_CXDOUBLECLK | 36 | 4 | 2,4 |
SM_CYDOUBLECLK | 37 | 4 | 2,4 |
SM_CXICONSPACING | 38 | 116 | 69,6 |
SM_CYICONSPACING | 39 | 94 | 56,4 |
SM_MENUDROPALIGNMENT | 40 | 0 | 0 |
SM_PENWINDOWS | 41 | 0 | 0 |
SM_DBCSENABLED | 42 | 0 | 0 |
SM_CMOUSEBUTTONS | 43 | 16 | 9,6 |
SM_CMETRICS | 44 | 0 | 0 |
SM_CXEDGE | 45 | 2 | 1,2 |
SM_CYEDGE | 46 | 2 | 1,2 |
SM_CXMINSPACING | 47 | 199 | 119,4 |
SM_CYMINSPACING | 48 | 34 | 20,4 |
SM_CXSMICON | 49 | 20 | 12 |
SM_CYSMICON | 50 | 20 | 12 |
SM_CYSMCAPTION | 51 | 29 | 17,4 |
SM_CXSMSIZE | 52 | 28 | 16,8 |
SM_CYSMSIZE | 53 | 28 | 16,8 |
SM_CXMENUSIZE | 54 | 24 | 14,4 |
SM_CYMENUSIZE | 55 | 24 | 14,4 |
SM_ARRANGE | 56 | 8 | 4,8 |
SM_CXMINIMIZED | 57 | 199 | 119,4 |
SM_CYMINIMIZED | 58 | 34 | 20,4 |
SM_CXMAXTRACK | 59 | 1942 | 1165,2 |
SM_CYMAXTRACK | 60 | 1102 | 661,2 |
SM_CXMAXIMIZED | 61 | 1938 | 1162,8 |
SM_CYMAXIMIZED | 62 | 1048 | 628,8 |
SM_NETWORK | 63 | 3 | 1,8 |
64 | 0 | 0 | |
65 | 0 | 0 | |
66 | 0 | 0 | |
SM_CLEANBOOT | 67 | 0 | 0 |
SM_CXDRAG | 68 | 4 | 2,4 |
SM_CYDRAG | 69 | 4 | 2,4 |
SM_SHOWSOUNDS | 70 | 0 | 0 |
SM_CXMENUCHECK | 71 | 19 | 11,4 |
SM_CYMENUCHECK | 72 | 19 | 11,4 |
SM_SLOWMACHINE | 73 | 0 | 0 |
SM_MIDEASTENABLED | 74 | 0 | 0 |
SM_MOUSEWHEELPRESENT | 75 | 1 | 0,6 |
SM_XVIRTUALSCREEN | 76 | 0 | 0 |
SM_YVIRTUALSCREEN | 77 | 0 | 0 |
SM_CXVIRTUALSCREEN | 78 | 1920 | 1152 |
SM_CYVIRTUALSCREEN | 79 | 1080 | 648 |
SM_CMONITORS | 80 | 1 | 0,6 |
SM_SAMEDISPLAYFORMAT | 81 | 1 | 0,6 |
SM_IMMENABLED | 82 | 1 | 0,6 |
SM_CXFOCUSBORDER | 83 | 1 | 0,6 |
SM_CYFOCUSBORDER | 84 | 1 | 0,6 |
85 | 4 | 2,4 | |
SM_TABLETPC | 86 | 0 | 0 |
SM_MEDIACENTER | 87 | 0 | 0 |
SM_STARTER | 88 | 0 | 0 |
SM_SERVERR2 | 89 | 0 | 0 |
90 | 0 | 0 | |
SM_MOUSEHORIZONTALWHEELPRESENT | 91 | 0 | 0 |
SM_CXPADDEDBORDER | 92 | 5 | 3 |
93 | 964 | 578,4 | |
SM_DIGITIZER | 94 | 0 | 0 |
SM_MAXIMUMTOUCHES | 95 | 0 | 0 |
Constant | Index | Pixels | Points | |
SM_CXSCREEN | 0 | 1920 | 1152 | 125% |
SM_CYSCREEN | 1 | 1080 | 648 | 125% |
SM_CXVSCROLL | 2 | 21 | 12,6 | 125% |
SM_CYHSCROLL | 3 | 21 | 12,6 | 125% |
SM_CXVSCROLL | 2 | 17 | 12,75 | 100% |
SM_CYHSCROLL | 3 | 17 | 12,75 | 100% |