Récupérer et modifier la position d'une fenêtre


Propriétés du code


Date de création : 24/12/2006 à 15:14:00
1 Commentaire(s)
  MadMatt

 

Présentation


Voilà 2 fonctions très simples à utiliser pour récupérer et modifier la position d'une fenetre.

Pour SetWindowPosition, j'ai été obligé de mettre les parametres en Variant, pour voir l'explication :
http://www.vbfrance.com/infomsg_TESTER-PRESENCE-PARAMETRE-OPTIONNEL_863670.aspx

Si vous trouvez une autre idée pour gérer la présence ou non de parametres optionnels, n'hésitez pas ;)

 

Code


' Le type RECT
Public Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
Public Type POINTAPI
    X As Long
    Y As Long
End Type
' Le placement d'une fenetre
Public Declare Function GetWindowPlacement Lib "user32" (ByVal hWnd As Long, lpWndPl As WINDOWPLACEMENT) As Long
Public Declare Function SetWindowPlacement Lib "user32" (ByVal hWnd As Long, lpWndPl As WINDOWPLACEMENT) As Long
Public Type WINDOWPLACEMENT
    Length As Long
    Flags As Long
    ShowCmd As Long
    ptMinPosition As POINTAPI
    ptMaxPosition As POINTAPI
    rcNormalPosition As RECT
End Type
Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_SHOWNOACTIVATE = 4



'---------------------------------------------------------------------------------------
' Procedure : GetWindowPosition
' DateTime  : 23/12/2006 19:35
' Author    : Vb System Library
' Purpose  : Renvoie la position de la fenetre sous forme de type Rect
' Params    : hWnd : Handle de la fenetre
'---------------------------------------------------------------------------------------
Public Function GetWindowPosition(ByVal hWnd As Long) As RECT
    Dim tmpRect As RECT
    GetWindowRect hWnd, tmpRect
    GetWindowPosition = tmpRect
End Function


'---------------------------------------------------------------------------------------
' Procedure : SetWindowPosition
' DateTime  : 23/12/2006 19:35
' Author    : Vb System Library
' Purpose  : Renvoie la position de la fenetre sous forme de type Rect
' Params    : hWnd : Handle de la fenetre
'---------------------------------------------------------------------------------------
Public Function SetWindowPosition(ByVal hWnd As Long, Optional ByVal Left As Variant, Optional Top As Variant, Optional Width As Variant, Optional Height As Variant)
    Dim WndPl As WINDOWPLACEMENT
    WndPl.Length = Len(WndPl)
    GetWindowPlacement hWnd, WndPl
    If (Not IsMissing(Left)) And IsNumeric(Left) Then
        WndPl.rcNormalPosition.Right = WndPl.rcNormalPosition.Right - WndPl.rcNormalPosition.Left + Left
        WndPl.rcNormalPosition.Left = Left
    End If
    If (Not IsMissing(Top)) And IsNumeric(Top) Then
        WndPl.rcNormalPosition.Bottom = WndPl.rcNormalPosition.Bottom - WndPl.rcNormalPosition.Top + Top
        WndPl.rcNormalPosition.Top = Top
    End If
    If (Not IsMissing(Width)) And IsNumeric(Width) Then WndPl.rcNormalPosition.Right = WndPl.rcNormalPosition.Left + Width
    If (Not IsMissing(Height)) And IsNumeric(Height) Then WndPl.rcNormalPosition.Bottom = WndPl.rcNormalPosition.Top + Height
    SetWindowPlacement hWnd, WndPl
End Function


 

Historique


Voici l'historique des modifications de ce code :
Le 30/12/2006 par MadMatt : Legere modif

 
 

Modifier le code

Seul les admins et l'auteur du code lui même peuvent modifier ce code.

 

Commentaires


De MadMatt le 24/12/2006 à 15:20


Au passage, j'ai mis la version 1.0.2 de la librairie en ligne

 

Ajouter un commentaire


Vous devez être connecté pour pouvoir poster un commentaire.

 
 

Valid HTML 4.01 Transitional Valid CSS

Site web de Vb System Library version 1.3
Developpement et design réalisé par : Matthieu Napoli (MadMatt)
© 2007 Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
Temps d'execution de la page : 0.793 s
www.mnapoli.fr