BEGIN MDIEVENTS ... END MDIEVENTS statements

Purpose: In a MDIGUI program, code that is responsible for monitoring and responding to messages and commands like mouse clicks, button presses, radio controls and so on is placed in the BEGIN MDIEVENTS ... END MDIEVENTS block.

It is important to remember that this block is a callback routine which can be called several times before any specific task contained in the block is completed. For this reason, it is best that any variables which must be dimensioned in the BEGIN MDIEVENTS ... END MDIEVENTS block, should be dimensioned as STATIC or DIM RAW. When DIM or LOCAL are used, BCX emits code to automatically clear the variable to zero and so if a callback occurs before a task is completed the DIM or LOCAL variables will be cleared to zero and the task will fail.


 Syntax :

 BEGIN MDIEVENTS ProcedureName
   ' Messages and Commands
 END MDIEVENTS [MAIN]

 Parameters:

  • ProcedureName parameter specifying a name for the MDIEVENTS loop. The loop must be named.
  • MAIN [OPTIONAL] parameter which is used, when there is more than one event loop in the program, to indicate that this instance of the END MDIEVENTS statement is the end of the main program.

Remarks:

This BCX code,


 BEGIN MDIEVENTS ProcedureName
   SELECT CASE CBMSG
   CASE WM_LBUTTONDOWN
     SetWindowText(Stat1,"left mouse button down :-(")
 
   CASE WM_LBUTTONUP
     SetWindowText(Stat1,"LEFT MOUSE BUTTON UP   :-)")
   END SELECT
 END MDIEVENTS

which uses a procedure name, translates to


 LRESULT CALLBACK ProcedureName(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
 {
   while(1)
   {
     if(Msg==WM_LBUTTONDOWN)
       {
         SetWindowText(Stat1,"left mouse button down :-(");
         break;
       }
     if(Msg==WM_LBUTTONUP)
       {
         SetWindowText(Stat1,"LEFT MOUSE BUTTON UP   :-)");
       }
     break;
   }
  return DefFrameProc(hWnd,BCX_hwndMDIClient,Msg,wParam,lParam);
 }

This BCX code


 BEGIN MDIEVENTS ProcedureName
   SELECT CASE CBMSG
   CASE WM_LBUTTONDOWN
     SetWindowText(Stat1,"left mouse button down :-(")
 
   CASE WM_LBUTTONUP
     SetWindowText(Stat1,"LEFT MOUSE BUTTON UP   :-)")
   END SELECT
 END MDIEVENTS MAIN

which uses a procedure name and the MAIN statement appended to END MDIEVENTS, translates to


 LRESULT CALLBACK ProcedureName(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
 {
   while(1)
   {
     if(Msg==WM_LBUTTONDOWN)
       {
         SetWindowText(Stat1,"left mouse button down :-(");
         break;
       }
     if(Msg==WM_LBUTTONUP)
       {
         SetWindowText(Stat1,"LEFT MOUSE BUTTON UP   :-)");
       }
     break;
   }
   if(Msg==WM_DESTROY)
     {
        PostQuitMessage(0);
        return 0;
     }
  return DefFrameProc(hWnd,BCX_hwndMDIClient,Msg,wParam,lParam);
 }

This WM_DESTROY handler,


 if(Msg==WM_DESTROY)
   {
    PostQuitMessage(0);
   }

is automatically generated by the BEGIN MDIEVENTS ... END MDIEVENTS statements when a ProcedureName is specified and the MAIN statement is appended to the END MDIEVENTS statement.

Therefore, in this instance, it is redundant to include


 CASE WM_DESTROY
 PostQuitMessage(0)

in the BCX code of the MDIEVENTS loop.