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 RegisterClassExarrow-up-right.

The macros then called the GetWindowLongarrow-up-right or SetWindowLongarrow-up-right to get or set the value at the appropriate index offset.

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:

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 herearrow-up-right for why).

It is also possible to make use of the GetProparrow-up-right / SetProparrow-up-right api calls, which make use of integer atomsarrow-up-right - which is faster than GetProparrow-up-right / SetProparrow-up-right with a string atomsarrow-up-right, but use of GetProparrow-up-right / SetProparrow-up-right with both atoms types are still slower than GetWindowLongarrow-up-right / SetWindowLongarrow-up-right as far as I am aware.

Last updated