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
| Option Compare Database
Option Explicit
Private Const HWND_BOTTOM = 1 'Place la fenêtre en dessous de toutes les autres.
Private Const HWND_NOTOPMOST = -2 'Place la fenêtre au dessus de toutes les fenêtres qui n'ont pas l'attribut "TOPMOST" (et en dessous de ces dernières).
Private Const HWND_TOP = 0 'Place la fenêtre au premier niveau.
Private Const HWND_TOPMOST = -1 'Place la fenêtre au premier niveau, celle-ci conserve cet attribut même lorsqu'elle perd le focus.
Private Const SWP_HIDEWINDOW = &H80 'Cache la fenêtre.
Private Const SWP_NOACTIVATE = &H10 'N'active pas la fenêtre.
Private Const SWP_NOMOVE = &H2 'Garde la même position (les paramètres X et Y ne sont pas pris en compte).
Private Const SWP_NOSIZE = &H1 'Conserve les dimensions courantes (paramètres cx et cy pas pris en compte).
Private Const SWP_SHOWWINDOW = &H40 'Affiche la fenêtre.
Private Declare Function SetWindowPos Lib "user32" ( _
ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Const HWND_DESKTOP As Long = 0
Private Const LOGPIXELSX As Long = 88
Private Const LOGPIXELSY As Long = 90
Function TwipsPerPixelX() As Single
Dim lngDC As Long
lngDC = GetDC(HWND_DESKTOP)
TwipsPerPixelX = 1440& / GetDeviceCaps(lngDC, LOGPIXELSX)
ReleaseDC HWND_DESKTOP, lngDC
End Function
Function TwipsPerPixelY() As Single
Dim lngDC As Long
lngDC = GetDC(HWND_DESKTOP)
TwipsPerPixelY = 1440& / GetDeviceCaps(lngDC, LOGPIXELSY)
ReleaseDC HWND_DESKTOP, lngDC
End Function
Public Sub Move2K(ByVal hwnd As Long, ByVal Left As Long, ByVal Top As Long, ByVal Width As Long, ByVal Height As Long)
SetWindowPos hwnd, HWND_NOTOPMOST, _
Left \ TwipsPerPixelX, _
Top \ TwipsPerPixelY, _
Width \ TwipsPerPixelX, _
Height \ TwipsPerPixelY, 0
End Sub |
Partager