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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| Option Explicit
Private Enum DWMWINDOWATTRIBUTE
DWMWA_NCRENDERING_ENABLED = 1
DWMWA_NCRENDERING_POLICY
DWMWA_TRANSITIONS_FORCEDISABLED
DWMWA_ALLOW_NCPAINT
DWMWA_CAPTION_BUTTON_BOUNDS
DWMWA_NONCLIENT_RTL_LAYOUT
DWMWA_FORCE_ICONIC_REPRESENTATION
DWMWA_FLIP3D_POLICY
DWMWA_EXTENDED_FRAME_BOUNDS
DWMWA_LAST
End Enum
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function DwmGetWindowAttribute Lib "dwmapi.dll" (ByVal hwnd As Long, ByVal dwAttribute As Long, ByRef pvAttribute As Any, ByVal cbAttribute As Long) As Long
Dim Col As Long, Lig As Long
Public Function fPosCel(Rng As Range) As RECT
Dim P As Long, ptpx As Double
ptpx = ppx(72)
For P = 1 To ActiveWindow.Panes.Count
With ActiveWindow.Panes(P)
If Not Intersect(Rng, .VisibleRange) Is Nothing Then
fPosCel.Left = .PointsToScreenPixelsX(Rng.Left) / ptpx
fPosCel.Top = .PointsToScreenPixelsY(Rng.Top) / ptpx
fPosCel.Right = Rng.Width
fPosCel.Bottom = Rng.Height
Exit For
End If
End With
Next
End Function
Public Function fMarges(Usf_Caption As String, Usf_Left As Double, Usf_Top As Double) As RECT
Dim LngResult As Long, LngHwnd As Long, DblPpx As Double, BoolFreeze As Boolean
DblPpx = ppx(72)
If ActiveWindow.FreezePanes = True Then BoolFreeze = True: Call Libere(False)
LngHwnd = FindWindow(vbNullString, Usf_Caption)
LngResult = DwmGetWindowAttribute(LngHwnd, DWMWA_EXTENDED_FRAME_BOUNDS, fMarges, LenB(fMarges))
If fMarges.Left <> 0 Then
fMarges.Left = Usf_Left - (fMarges.Left / DblPpx)
fMarges.Top = Usf_Top - (fMarges.Top / DblPpx)
End If
If BoolFreeze Then Call Refige(True)
End Function
Private Function ppx(Nb As Long) As Double
With CreateObject("WScript.Shell")
ppx = .RegRead("HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics\AppliedDPI") / Nb
End With
End Function
Private Sub Libere(Comment As Boolean)
With ActiveWindow
Col = .SplitColumn
Lig = .SplitRow
.FreezePanes = Comment
End With
End Sub
Private Sub Refige(Comment As Boolean)
With ActiveWindow
.SplitColumn = Col
.SplitRow = Lig
.FreezePanes = Comment
End With
End Sub |
Partager