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?

Initializing Our Control

PreviousHandling Other Messages For Our ControlNextPainting Our Control

Last updated 5 years ago

Was this helpful?

_SB_Init function is called from the WM_CREATE message of the _SB_WndProc main window messaging function. It initializes our SimpleButton with some default values: like colors for background and text and others like default font to use. In _SB_Init we also check the dwStyle flags passed to the SimpleButton control (via direct call to , call to SimpleButtonCreate or via dialog resource child control creation) and we can override the dwStyle flags specified and/or force specific flags to be used or excluded (in case the end-user forgot), for example we can set our control to always use WM_CHILD plus WM_VISIBLE etc:

...
; get style and check it is our default at least
Invoke GetWindowLong, hControl, GWL_STYLE
mov dwStyle, eax
and eax, WS_CHILD or WS_VISIBLE or WS_CLIPCHILDREN
.IF eax != WS_CHILD or WS_VISIBLE or WS_CLIPCHILDREN
    mov eax, dwStyle
    or eax, WS_CHILD or WS_VISIBLE or WS_CLIPCHILDREN
    mov dwStyle, eax
    Invoke SetWindowLong, hControl, GWL_STYLE, dwStyle
.ENDIF
...

We also set some default values for our control's external properties, like standard colors that might be used for text and background when creating our control. So some of the default values we will set for our control's properties are:

...
Invoke __SetExtProperty, hControl, @SimpleButtonTextColor, SBRGBCOLOR(51,51,51)
Invoke __SetExtProperty, hControl, @SimpleButtonBackColor, SBRGBCOLOR(255,255,255)
Invoke __SetExtProperty, hControl, @SimpleButtonBorderColor, SBRGBCOLOR(204,204,204)
Invoke __SetExtProperty, hControl, @SimpleButtonBorderStyle, SBES_ALL
...

Only some of the external properties are shown for brevity, the ones that are shown are define in SimpleButton.inc as:

@SimpleButtonTextColor   EQU 4
@SimpleButtonBackColor   EQU 24
@SimpleButtonBorderColor EQU 44
@SimpleButtonBorderStyle EQU 64
SBRGBCOLOR MACRO red:REQ, green:REQ, blue:REQ
    EXITM < red or green shl 8 or blue shl 16 >
ENDM

Here is our what our SimpleButton control will look like, in the image below, if it is created with the default property values we have assigned to it in our initialization function _SB_Init:

For color properties () we make use of a macro called SRGBCOLOR that is included in SimpleButton.inc:

Note that it doesnt make use of the blue text color and border shown in our earlier image in the section.

So by implementing this initialization routine for the end-user, it means they can use the SimpleButton control straight away, or they can choose to modify any of the external properties to customize it to their requirements after the control is created, whichever suits. See the section later on for more details.

CreateWindowEx
COLORREF
Our First Control
Control Properties