The message handling for the dialog does not take place using PeekEvent, GetEvent, DoEvents, or Sleep. Instead message processing is part of the main message loop of the GFA-BASIC IDE program. Whenever a message for GFA Editor Extension dialog box arrives it is dispatched to the Gfa_CB sub which should handle your dialog box message.
The syntax for the dialog callback sub is:
Sub Gfa_CB(hDlg%, Msg%, wParam%, lParam%, RetVal%, ValidRet?)
The hDlg% parameter is the window (dialog) to which the message is sent. The Msg% parameter is the message number, which is usually a constant such as WM_COMMAND or WM_SIZE. The wParam% and lParam% parameters differ for each message, as does the return value; you must look up the specific message to see what they mean. Often, wParam or the return value is ignored, but not always.
The Gfa_CB has two additional parameters (ByRef) that allow you to return a value to default window procedure for the dialog box. For instance, when you handled a certain message you can set the ValidRet? variable to True and provide a return value by setting the RetVal% variable. What value RetVal must have is defined in the Windows API SDK. It often says something like: "If you handle this message return zero (or..)".
There can be only one Gfa_CB sub per editor extension. So, inside the Gfa_CB sub you must determine which dialog # the message is for. Note that a dialog box is defined using an ID number (0..31) and that the dialog is accessed using its ID number.
To obtain the target dialog box number you must obtain the ID number from the hDlg% parameter, which specifies the windows handle for the dialog box. The window handles for the dialog boxes are retrieved using the Dlg() function. Dlg(id) expects a number between 0 and 31 and returns the window handle of that dialog box. The target dialog box ID is determined by iterating over the dialog box ID values, 0 to 31, until hDlg% equals Dlg(id).
The following example illustrates the message handling mechanism in a GFA Editor Extension for three dialogs:
Sub Gfa_CB(hDlg%, Msg%, wParam%, lParam%, RetVal%, ValidRet?)
If hDlg% = Dlg(1)
Handle_Dlg1(hDlg%, Msg%, wParam%, lParam%, RetVal%, ValidRet?)
Else If hDlg% = Dlg(2)
Handle_Dlg2(hDlg%, Msg%, wParam%, lParam%, RetVal%, ValidRet?)
Else If hDlg% = Dlg(3)
Handle_Dlg3(hDlg%, Msg%, wParam%, lParam%, RetVal%, ValidRet?)
EndIf
EndSub
Sub Handle_Dlg1(hDlg%, Msg%, wParam%, lParam%, RetVal%, ValidRet?)
// Code
EndSub
Sub Handle_Dlg2(hDlg%, Msg%, wParam%, lParam%, RetVal%, ValidRet?)
// Code
EndSub
Sub Handle_Dlg3(hDlg%, Msg%, wParam%, lParam%, RetVal%, ValidRet?)
// Code
EndSub
Once a message is arrived in the callback subroutine, there are two alternatives in processing possible.
1. Create a large switch case branch based on the Msg% variable and handle the message directly (preferred).
2. Store the parameters in global variables and process the message in Gfa_Second. This is kind of the same as messages were handled in GFA-BASIC for Windows 3.1 using MENU(). (This method is mentioned by GFA, but it is not recommended.)
{Created by Sjouke Hamstra; Last updated: 20/08/2023 by James Gaite; Other Contributors: Jean-Marie Melanson}