Creating Controls in Assembler
  • Preface
    • Author
    • Guidelines
  • Introduction
    • Controls & Modern UI Design
    • The HotMenu Quest
  • Our First Control
    • External End-User Functions
    • Internal Functions
  • Registering Our Control
  • Creating Our Control
  • Inside Our Control
    • On Creation: WM_CREATE
    • On Destroying: WM_NCDESTROY
    • Handling Other Messages For Our Control
  • Initializing Our Control
  • Painting Our Control
  • Using Our Control
  • Control Properties
    • The Memory Used To Store Properties
    • Property Structures & Constants
    • Using Macros To Get/Set Properties
    • Using The Win32 API To Get/Set Properties
    • Internal Wrapper Functions
  • Additional Resources
    • RadASM Auto-complete
    • The ModernUI Framework
Powered by GitBook
On this page

Was this helpful?

  1. Control Properties

Using Macros To Get/Set Properties

PreviousProperty Structures & ConstantsNextUsing The Win32 API To Get/Set Properties

Last updated 5 years ago

Was this helpful?

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 .

The macros then called the or 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:

...
_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 section and for why).

It is also possible to make use of the / api calls, which make use of - which is faster than / with a , but use of / with both atoms types are still slower than / as far as I am aware.

RegisterClassEx
GetWindowLong
SetWindowLong
Control Properties
here
GetProp
SetProp
integer atoms
GetProp
SetProp
string atoms
GetProp
SetProp
GetWindowLong
SetWindowLong