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?

  1. Inside Our Control

Handling Other Messages For Our Control

PreviousOn Destroying: WM_NCDESTROYNextInitializing Our Control

Last updated 5 years ago

Was this helpful?

Along with handling the WM_CREATE & WM_NCDESTROYmessages, we have to handle a few more: enabling/disabling our control, setting text, setting fonts, when our control is painted and other features we may wish to include, such as mouse and keyboard interaction (if applicable to our control).

We handle our own painting in our SimpleButton like so with these two messages:

...
.ELSEIF eax == WM_ERASEBKGND
    mov eax, 1
    ret

.ELSEIF eax == WM_PAINT
    Invoke _SB_Paint, hWin
    mov eax, 0
    ret
...

With the above code, we are specifying that we will handle erasing of our control's background ourself and painting of our SimpleButton control via our own paint function _SB_Paint see for more details.

We can also allow our SimpleButton control to be enabled or disabled via a standard WM_ENABLE message, which forces a repaint of our control. And similarly we can allow a font change and repaint via a WM_SETFONT message.

...
.ELSEIF eax == WM_ENABLE
    Invoke __SetIntProperty, hWin, @SimpleButtonEnabledState, wParam
    Invoke InvalidateRect, hWin, NULL, TRUE
    mov eax, 0

.ELSEIF eax == WM_SETTEXT
    Invoke DefWindowProc, hWin, uMsg, wParam, lParam
    Invoke InvalidateRect, hWin, NULL, TRUE
    ret

.ELSEIF eax == WM_SETFONT
    Invoke __SetExtProperty, hWin, @SimpleButtonTextFont, lParam
    .IF lParam == TRUE
        Invoke InvalidateRect, hWin, NULL, TRUE
    .ENDIF

Our custom messages (SB_GETPROPERTY ,SB_SETPROPERTY, SB_GETSTATE and SB_SETSTATE) are included as well and are just simple calls to our internal helper functions (or framework library if using one):

...
.ELSEIF eax == SB_GETPROPERTY ; wParam = dwProperty, lParam = NULL. 
    Invoke __GetExtProperty, hWin, wParam ; EAX = dwPropertyValue
    ret

.ELSEIF eax == SB_SETPROPERTY ; wParam = dwProperty, lParam = dwPropertyValue
    Invoke __SetExtProperty, hWin, wParam, lParam
    ret
.ELSEIF eax == SB_GETSTATE ; wParam = NULL, lParam = NULL. 
    Invoke __GetIntProperty, hWin, @SimpleButtonSelectedState ; EAX = dwState
    ret

.ELSEIF eax == SB_SETSTATE ; wParam = TRUE/FALSE, lParam = NULL
    Invoke __SetIntProperty, hWin, @SimpleButtonSelectedState, wParam
    Invoke InvalidateRect, hWin, NULL, TRUE ; repaint control
    ret    
...

Other standard messages are used to handle mouse interactions: the mouse moving over our control, leaving it, clicking on it etc via WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MOUSEMOVE, WM_MOUSELEAVE and other standard win32 api messages.

Painting Our Control