Using Macros To Get/Set Properties
When I was using the earlier technique of allocating as much bytes as I wanted in
cbWndExtra (without realising or coming across any downsides) I used a series of macros to help get/set the variables and constants to help define the offsets the macro would get/set, for example:
@Style EQU 0h ; some style flags @MouseOverFlag EQU 4h ; 0 = no mouse over, 1 = mouse is over control @SelectedState EQU 8h ; 0 = not selected, 1 = selected @ControlFont EQU 12 ; hFont ...
With the constants defined and appropriate named (using a prefix of '@') we could then define macros to get and set our property values. Each constant is an offset into the extra window bytes allocated by
cbWndExtra during the control's registration via RegisterClassEx.
Here is and example of some macros used to get and set the various 'properties' as defined above as constants:
_GetMouseOverFlag MACRO hControl:REQ Invoke GetWindowLong, hControl, @MouseOverFlag ENDM _SetMouseOverFlag MACRO hControl:REQ, ptrControlData:REQ Invoke SetWindowLong, hControl, @MouseOverFlag, ptrControlData ENDM _GetSelectedState MACRO hControl:REQ Invoke GetWindowLong, hControl, @SelectedState ENDM _SetSelectedState MACRO hControl:REQ, ptrControlData:REQ Invoke SetWindowLong, hControl, @SelectedState, ptrControlData ENDM
The macros could then be placed in code and used like so:
... _SetMouseOverFlag hControl, TRUE ... ... _GetSelectedState hControl mov bState, eax ...
Using macros to get and set our control's properties is still a valid technique if the amount of data store for these properties is less than 40 bytes (see the Control Properties section and here for why).
It is also possible to make use of the GetProp / SetProp api calls, which make use of integer atoms - which is faster than GetProp / SetProp with a string atoms, but use of GetProp / SetProp with both atoms types are still slower than GetWindowLong / SetWindowLong as far as I am aware.