Récupérer et modifier le titre d'une fenetre


Propriétés du code


Date de création : 24/11/2006 à 23:51:00
0 Commentaire(s)
  MadMatt

 

Présentation


Cette fonction renvoie le titre d'une fenetre (sa propriété Caption en gros), selon le handle passé.

hWnd est le handle de la fenetre (son numéro identificateur)

 

Code


' Déclarations API
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long



' Renvoie le titre de la fenêtre
Public Function GetWindowCaption(ByVal hWnd As Long) As String
    Dim Length As Long
    ' On récupère la longueur de la chaine et on formate une chaine à cette longueur
    Length = GetWindowTextLength(hWnd)
    GetWindowCaption = Space$(Length + 1)
    ' On récupère le nom de la fenetre
    Length = GetWindowText(hWnd, GetWindowCaption, Length + 1)
    GetWindowCaption = Left$(GetWindowCaption, Len(GetWindowCaption) - 1)
End Function


' Modifie le titre de la fenetre
Public Function SetWindowCaption(ByVal hWnd As Long, ByVal Caption As String)
    SetWindowText hWnd, Caption
End Function


 

Historique


Voici l'historique des modifications de ce code :
03/12/2006 : Petite correction
24/12/2006 : essai
24/12/2006 : ajout de la fonction de modification
Le 30/12/2006 par MadMatt : Petit bug daffichage

 
 

Modifier le code

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

 

Commentaires


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.008 s
www.mnapoli.fr