Rubrik: Fenster | 22.03.05 |
EnumPropsEx-Funktion Diese Funktion enumeriert alle Fenstereigenschaften und ermittelt deren Parameternamen und -werte. | ||
Betriebssystem: Win95, Win98, WinNT 3.1, Win2000, WinME | Views: 8.273 |
Deklaration:
Declare Function EnumPropsEx Lib "user32.dll" _ Alias "EnumPropsExA" ( _ ByVal hWnd As Long, _ ByVal lpEnumFunc As Long, _ ByVal lParam As Long) As Long
Beschreibung:
Diese Funktion enumeriert alle Fenstereigenschaften und ermittelt deren Parameternamen und-werte.
Parameter:
hWnd | Erwartet das Fensterhandle des Fensters, dessen Eigenschaften enumeriert werden sollen. |
lpEnumFunc | Erwartet die Adresse der Funktion, die für jede gefundene Eigenschaft aufgerufen werden soll. Diese Callback-Funktion benötigt drei Long-Parameter und eine Long-Rückgabe. Der erste Parameter der Funktion istdas Fensterhandle, bei dem der Parameter gefunden wurde, gefolgt von dem Handle der Daten, die der Eigenschaft zugeordnet sind und einem Parameter der denWert von "lParam" enthält. Soll nach einem Callback-Aufruf die Enumeration fortgesetzt werden, so muss derWert "1" zurückgegeben werden, andernfalls geben Sie den Wert "0" zurück. |
lParam | Hier kann ein zusätzlicherWert übergeben werden, der in dem dritten Parameter der Callback-Funktion übergeben wird. |
Rückgabewert:
Ist die Funktion erfolgreich, so liefert sie den letzten Rückgabewert der Callback-Funktion, andernfalls wird derWert "-1" zurückgegeben.
Beispiel:
' Fügen Sie den folgenden Code in ein öffentliches Modul ein Private Declare Function lstrlen Lib "kernel32.dll" _ Alias "lstrlenA" ( _ ByVal lpString As Any) As Long Private Declare Function lstrcpy Lib "kernel32.dll" _ Alias "lstrcpyA" ( _ ByVal lpString1 As Any, _ ByVal lpString2 As Any) As Long Private Declare Function GlobalAlloc Lib "kernel32.dll" ( _ ByVal wFlags As Long, _ ByVal dwBytes As Long) As Long Private Declare Function GlobalLock Lib "kernel32.dll" ( _ ByVal hMem As Long) As Long Private Declare Function GlobalUnlock Lib "kernel32.dll" ( _ ByVal hMem As Long) As Long Public Declare Function GlobalFree Lib "kernel32.dll" ( _ ByVal hMem As Long) As Long ' einige der GlobalAlloc wFlags-Konstanten Private Const GMEM_ZEROINIT = &H40 Private Const GMEM_MOVEABLE = &H2
' Wird bei jeder gefundenen Eigenschaft von Windows aufgerufen Public Function PropEnumProcEx(ByVal hWnd As Long, ByVal lpszString As _ Long, ByVal hData As Long, ByVal dwData As Long) As Long Dim PropName As String, Retval As Long, pData As Long ' Name der Eigenschaft ermitteln PropName = Space(lstrlen(lpszString)) Retval = lstrcpy(PropName, lpszString) ' Hinzufügen des Namens in eine Combobox fall es eine ' String-Eigenschaft ist pData = GlobalLock(hData) If lstrlen(pData) < 0 Then With Form1.Combo1 If PropName = "" Then .AddItem "Unbekannt" .ItemData(.NewIndex) = hData Else .AddItem PropName End If End With End If Call GlobalUnlock(hData) ' Enumeration fortsetzen PropEnumProcEx = 1 End Function
' Erstellt einen Speicherblock mit String-Inhalt Public Function StringToHandle(ByVal Value As String) As Long Dim hGlobal As Long, pGlobal As Long ' Speicherblock erstellen und Pointer ermitteln hGlobal = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, lstrlen(Value) * 3) pGlobal = GlobalLock(hGlobal) ' String in den Speicher kopieren Call lstrcpy(pGlobal, Value) ' Speicherblock freigeben Call GlobalUnlock(hGlobal) StringToHandle = hGlobal End Function
' Ermittelt einen String anhand eines Handles Public Function HandleToString(ByVal Value As Long) As String Dim TmpStr As String, pGlobal As Long ' Speicherblock Pointer ermitteln pGlobal = GlobalLock(Value) ' String aus den Speicher kopieren TmpStr = Space(lstrlen(pGlobal)) Call lstrcpy(TmpStr, pGlobal) ' Speicherblock freigeben Call GlobalUnlock(Value) HandleToString = TmpStr End Function ' Der nun folgende Code muss in eine Form geschrieben werden Private Declare Function EnumPropsEx Lib "user32.dll" _ Alias "EnumPropsExA" ( _ ByVal hWnd As Long, _ ByVal lpEnumFunc As Long, _ ByVal lParam As Long) As Long Private Declare Function GetProp Lib "user32.dll" _ Alias "GetPropA" ( _ ByVal hWnd As Long, _ ByVal lpString As String) As Long Private Declare Function RemoveProp Lib "user32.dll" _ Alias "RemovePropA" ( _ ByVal hWnd As Long, _ ByVal lpString As String) As Long Private Declare Function SetProp Lib "user32.dll" _ Alias "SetPropA" ( _ ByVal hWnd As Long, _ ByVal lpString As String, _ ByVal hData As Long) As Long
' einige Fenstereigenschaften hinzufügen Private Sub Form_Load() Dim Retval As Long Call SetProp(Me.hWnd, "Autor", StringToHandle("LonelySuicide666")) Call SetProp(Me.hWnd, "Datum", StringToHandle("08.08.1979")) Call SetProp(Me.hWnd, "Website", StringToHandle("http://www.vbapihelpline.de")) Call SetProp(Me.hWnd, "E-Mail", StringToHandle("webmaster@vbapihelpline.de")) ' Alle Eigenschaften des Fensters enumerieren Call EnumPropsEx(Me.hWnd, AddressOf PropEnumProcEx, 0&) Combo1.ListIndex = 0 End Sub
' Eigenschaft bei Auswahl auslesen Private Sub Combo1_Click() Dim Retval As Long ' Eigenschaft auslesen und anzeigen If Combo1.Text = "Unbekannt" Then Retval = Combo1.ItemData(Combo1.ListIndex) Else Retval = GetProp(Me.hWnd, Combo1.Text) End If Label1.Caption = HandleToString(Retval) End Sub
' Beim Entladen Speicherblöcke und Fenstereigenschaften entfernen Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Dim Retval As Long, i As Integer For i = 0 To Combo1.ListCount - 1 Retval = GetProp(Me.hWnd, Combo1.List(i)) Call RemoveProp(Me.hWnd, Combo1.List(i)) Call GlobalFree(Retval) Next i End Sub