Using Our Control
The end-user will make use of our control SimpleButton, using the functions, custom messages, and constants (properties) that we define and are available for use in our SimpleButton.inc file.
Just to remind ourselves, these are the external functions available to the end-user:
SimpleButtonRegister PROTO
SimpleButtonCreate PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
SimpleButtonGetProperty PROTO :DWORD, :DWORD
SimpleButtonSetProperty PROTO :DWORD, :DWORD, :DWORD
SimpleButtonGetState PROTO :DWORD
SimpleButtonSetState PROTO :DWORD, :DWORDAnd the custom messages for our control are:
SB_GETPROPERTY EQU WM_USER + 1800
SB_SETPROPERTY EQU WM_USER + 1799
SB_GETSTATE EQU WM_USER + 1798
SB_SETSTATE EQU WM_USER + 1797With very little code we can create our control, all we need to define is the text to display and the resource id we will use for our control:
.const
IDC_SB1 EQU 1001 ; resource id to use
.data
SBText DB 'SimpleButton Rules!',0 ; text to display
.data?
hSB1 DD ? ; handle for SimpleButton controlAnd we then call our SimpleButtonCreate function and save the returned handle (in eax) in a variable:
Our SimpleButtonCreate function takes a number of parameters:
hWndParent(DWORD) is the parent handle of our main dialog window, with which to create a child control for.xpos(DWORD) is the left position of our control relative to the parent's client space.ypos(DWORD) is the top position of our control relative to the parent's client space.controlwidth(DWORD) is the width of our control.controlheight(DWORD) is the height of our controldwResourceID(DWORD) is the resource id used by our controldwStyle(DWORD) is a combination of constants (flags) that define some features of our control.
The dwStyle parameter can accept windows style flags: WS_CHILD, WS_VISIBLE, and flags we defined for our controls usage in SimpleButton.inc:
With our example code above, we create our control with the the text aligned in the center (SBBS_CENTER) and an option to show a hand cursor when the mouse moves over our control (SBBS_HAND), and we simulate a small movement of our control when it is clicked (SBBS_PUSHBUTTON) - the SimpleButton controil moves very slightly down when the left click button is pressed and back again when the left click button is released.
Additional properties of our control which are defined in our SimpleButton.inc file allow us to change the look and feel. This is the full list of properties (constant values) that we define for SimpleButton:
The end-user can choose which properties are set, with default values having been applied to the control when we initialized it (see Initializing Our Control section for details)
For example we can set the text color of our control, the border color and the border color when the mouse moves over our control:
We can optionally use our custom message SB_SETPROPERTY (instead of the SimpleButtonSetProperty function) with the SendMessage api call, to also set our control's properties:
As we have specified the resource id defined for our control (IDC_SB1), we can handle processing of when our control is clicked using the standard WM_COMMAND message in our example project's main dialog message processing procedure:
In the example code above, we show a simple MessageBox when our SimpleButton control is clicked.
Last updated
Was this helpful?