VB and VBA Users Source Code: Get and set hidden form properties or flags
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Get and set hidden form properties or flags
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Friday, March 09, 2001
Hits:
607
Category:
Windows API
Article:
Occasionally it is useful to mark forms from other applications, with hidden properties eg. When scanning for specific dialogs, add a flag/property to a form to mark it as having been processed or read. The following routines lets you set, get and delete hidden numerical flags on forms. Option Explicit Private Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hwnd As Long, ByVal lpString As String) As Long Private Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hwnd As Long, ByVal lpString As String, ByVal hData As Long) As Long Private Declare Function RemoveProp Lib "user32" Alias "RemovePropA" (ByVal hwnd As Long, ByVal lpString As String) As Long Private Declare Function EnumProps Lib "user32" Alias "EnumPropsA" (ByVal hwnd As Long, ByVal lpEnumFunc As Long) As Long Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As String) As Long Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Long) As Long Private zasProperties() As String, zlCount As Long 'Purpose : Removes a property value from a form. 'Inputs : lHwnd The handle to the form ' sProperty The name of the property to delete 'Outputs : Returns True on success, else returns False 'Author : Andrew Baker 'Date : 14/01/2001 12:20 'Notes : 'Revisions : Function FormPropertyDelete(ByVal lHwnd As Long, sProperty As String) As Boolean 'Remove the property FormPropertyDelete = RemoveProp(lHwnd, sProperty) End Function 'Purpose : Sets a property value on a form. 'Inputs : lHwnd The handle to the form ' sProperty The name of the property to set ' lValue The value of the property 'Outputs : Returns True on success, else returns False 'Author : Andrew Baker 'Date : 14/01/2001 12:20 'Notes : 'Revisions : Function FormPropertySet(ByVal lHwnd As Long, sProperty As String, lValue As Long) As Boolean 'Set the property FormPropertySet = SetProp(lHwnd, sProperty, lValue) End Function 'Purpose : Gets a property value from a form. 'Inputs : lHwnd The handle to the form ' sProperty The name of the property to set 'Outputs : Returns the value of the property. 'Author : Andrew Baker 'Date : 14/01/2001 12:20 'Notes : 'Revisions : Function FormPropertyGet(ByVal lHwnd As Long, sProperty As String) As Long 'Get the property FormPropertyGet = GetProp(lHwnd, sProperty) End Function 'Purpose : Returns a list of the properties associate with a form. 'Inputs : lHwnd The handle to the form 'Outputs : Returns a 1 based 2d array of properties and values. 'Author : Andrew Baker 'Date : 14/01/2001 12:20 'Notes : 'Revisions : Function FormProperties(ByVal lHwnd As Long) As Variant 'Reset variables Erase zasProperties zlCount = 0 'Begin the enumeration EnumProps lHwnd, AddressOf zPropertiesEnum 'Return the properties FormProperties = zasProperties End Function Private Function zPropertiesEnum(ByVal lHwnd As Long, ByVal lpsProperties As Long, ByVal hData As Long) As Boolean Dim sBuffer As String 'Create Buffer sBuffer = Space(lstrlen(lpsProperties)) 'Copy the string to sBuffer lstrcpy sBuffer, lpsProperties 'Store property name and value zlCount = zlCount + 1 If zlCount = 1 Then ReDim zasProperties(1 To 2, 1 To 1) Else ReDim Preserve zasProperties(1 To 2, 1 To zlCount) End If zasProperties(1, zlCount) = sBuffer zasProperties(2, zlCount) = FormPropertyGet(lHwnd, sBuffer) 'Continue zPropertiesEnum = True End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder