Occurs when a message for a Form is retrieved from the message queue.
Sub Form_Message(hWnd%, Mess%, wParam%, lParam%)
Sleep and DoEvents, but GetEvent and PeekEvent also, retrieve messages from the application message queue. Before the retrieved message is handled and dispatched to the window procedure of a window, the Message event sub is invoked. The Message event sub is only executed for the messages that are posted to the message queue, these include WM_PAINT, WM_MOVE, WM_SIZE, WM_COMMAND, WM_SYSCOMMAND, WM_CHAR, and WM_KEY*. Most of these messages have an accompanying sub event (Form_Paint, Form_Moved, Form_ReSize, Form_MenuEvent, Form_SysMenuOver, Form_Key*, etc. Before these event subs are executed GFA-BASIC 32 invokes the Message event sub passing the message number and its parameters.
One of the messages that is of interest is the WM_COMMAND message from standard (non-ocx) controls. This is message specifies exactly what happened with a control. The WM_COMMAND message is a good candidate to process in a Message event sub. It could also be handled in the MessageProc event sub, but this is a real callback subroutine allowing to handle messages at the lowest level. A big disadvantage of a call back procedure is the lack of debug capabilities. A Try/Catch handler is necessary to catch errors. The Message event sub is more robust.
Dlg 3D On
Global style%, style2%, File$
Dlg Base Unit
style% = WS_BORDER | WS_TABSTOP
style2% = BS_DEFPUSHBUTTON | WS_TABSTOP
Dialog # 1, 10, 10, 150, 100, "Test-Dialog"
RichEditCtrl "", 101, 50, 10, 80, 14, style%
PushButton "OK", IDOK, 10, 60, 40, 14, style2%
PushButton "CANCEL", IDCANCEL, 80, 60, 40, 14, style2%
EndDialog
ShowDialog # 1
// to fill the edit field
File$ = "GFA-User"
_Win$(Dlg(1, 101)) = File$
Do
Sleep
Until Me Is Nothing
Sub Dlg_1_Message(hWnd%, Mess%, wParam%, lParam%)
Select Mess
Case WM_COMMAND
Select wParam
Case IDOK
File$ = _Win$(Dlg(1, 101))
CloseDialog # 1
OpenW 1
Print File$ : Print
Print "End with Alt + F4"
EndSelect
EndSelect
EndSub
You can easily test in which order the sub events are called. For posted messages, those that are retrieved from the message queue using Sleep, the Message event is called before any other sub. Then the message is dispatched to the window procedure and the MessageProc is called. And finally, the event sub is invoked. For a WM_SIZE message the sequence is:
Win_1_Message()
Win_1_MessageProc()
Win_1_ReSize
The Message event sub does not work for Ocx Forms in an array or any Windows whose ID number is greater than 31; the relevant code is missing from the ocx and it is unlikely that this bug will ever be fixed.
{Created by Sjouke Hamstra; Last updated: 01/08/2022 by James Gaite; Other Contributors: Jean-Marie Melanson}