Dialog Low Level Event Handling

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Modules > UI (User Interface) > DIALOGS >

Dialog Low Level Event Handling

 

You can mimic the Win32 low level approach by passing callback function name to the DIALOG SHOW MODAL or DIALOG SHOW MODELESS commands.

 

You can see how cbDialog is used as such a callback function in the following example. Notice the callback function takes no parameters:

 

uses "UI"

 

'---Define a button ID

%ButtonClose = 1001

 

dWord hDlg

 

dialog new 0, "APPTITLE",-1,-1, 330, 203, %WS_POPUP | %WS_VISIBLE | %WS_CLIPCHILDREN | %WS_CAPTION | %WS_SYSMENU %WS_MINIMIZEBOX to hDlg

 

control add button, hDlg, %ButtonClose, "Click to kill", 90, 50, 150, 100

 

dialog show modal hDlg call cbDialog

 

'------------------------------------------------

' Callback function used to handle dialog events

'------------------------------------------------

callback function cbDialog() as long

 

  select case Callback_Message

    case %WM_Command

      if Callback_WPARAM = %ButtonClose then dialog end Callback_Handle

 

    case %WM_DESTROY

      msgbox Callback_Handle"Window is to be destroyed."

      

  end select 

 

end function

 

Please note mastering the low level dialog handling requires advanced knowledge and study of Win32 technology. This interface is therefore meant for experienced Win32 warriors who know what is %WM_COMMAND and what to expect from WPARAM and LPARAM for each of the messages.

 

Good starting point for study is Microsoft documentation here:

https://docs.microsoft.com/en-us/windows/win32/learnwin32/writing-the-window-procedure

 

Please note the difference that callback function in thinBasic does not retrieve the parameters so hWnd parameter is available for you via Callback_Handle, uMsg via Callback_Message, wparam via Callback_WParam and lparam via Callback_LParam.

 

If you don't have time to invest in this study, consider going the high level route.