Creating Our Control
The SimpleButtonCreate
function will allow the user to create the SimpleButton control directly with this function. The parameters for SimpleButtonCreate
are hWndParent
, lpszText
, xpos
, ypos
, controlwidth
, controlheight
, dwResourceID
, and finally dwStyle
. This is more or less typical for creating a control with CreateWindowEx and as such we try to keep our function as similar to that as we can, so that it is easier for the end user to use.
Most of the parameters of the SimpleButtonCreate
function are self-explanatory: the width, height, position of the control, the text to display, the parent handle of our child control and the resource id number associated with the control.
The dwStyle
parameter gives us a number of options to allow us or the user to tailor the control to our requirements, based on the styles we define for its usage. Unfortunately their isn't much in the microsoft documentation to indicate what values we can pass to the dwStyle
parameter apart from the standard windows defined ones: WS_BORDER
, WS_VISIBLE
, WS_CHILD
etc
The most useful information I came across that explains the dwStyle
flags parameter of CreateWindowEx is from Raymond Chen's old new thing blog
The low 16 bits of the dwStyle parameter are defined by the implementer of the window class (by the person who calls RegisterClass)
That means we have 0x0
- 0xFFFF
reserved for defining styles for our controls - 65535 possible values or 16 values if we require bitmasked unique values (1111111111111111). And we can incorporate the standard style flags as well if we so desire (WS_BORDER
, WS_VISIBLE
etc). So our SimpleButton styles we will use are:
So our SimpleButtonCreate
function is just a wrapper to register the control if not already registered and a call to CreateWindowEx to create it, returning the handle to the newly created control in eax
. Also we check with the dwStyle
parameter which flags are passed to SimpleButtonCreate
, to ensure for example that WS_CHILD
and WS_VISIBLE
is included and any other flags we might want as well. This check is also performed in the _SB_Init
procedure in case our SimpleButton control was created via a dialog resource. Of course you are free to define how you want your control to behave at creation and what flags if any you want to force to be included or even excluded from use.
Here is our SimpleButtonCreate
function:
Last updated