# 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](https://msdn.microsoft.com/en-us/library/windows/desktop/ms632680\(v=vs.85\).aspx), 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](https://msdn.microsoft.com/en-us/library/vs/alm/dd183449\(v=vs.85\).aspx)) 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`:

![](https://1360532193-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4RZOFkX1E1dh3zOsvP%2F-M4RZO_Ar6T8AKLPZMHq%2F-M4RZQA5aVR2xOZ-_YYD%2FSimpleButtonDemoDefaults.gif?generation=1586395987839121\&alt=media)

Note that it doesnt make use of the blue text color and border shown in our earlier image in the [Our First Control](https://fearless.gitbook.io/creating-controls-in-assembler/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](https://fearless.gitbook.io/creating-controls-in-assembler/control-properties) section later on for more details.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fearless.gitbook.io/creating-controls-in-assembler/initializing-our-control.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
