Initializing Our Control

_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 CreateWindowEx, 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

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

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:

Note that it doesnt make use of the blue text color and border shown in our earlier image in the Our First Control 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 Control Properties section later on for more details.

Last updated