HANDLE_MSG macro

Purpose: The HANDLE_MSG macro procedure, typically placed in the BEGIN EVENTS ... END EVENTS loop, is used with the MSGHANDLER macro, to provide a module based alternative for System-Defined Message handling in BCX.


 Syntax 1:

 HANDLE_MSG(SysMessage%, Procedure, LReturn)

 Parameters:

  • SysMessage% specifies the System-Defined Message as a message-identifier or the message-identifier constant value. For example, WM_PAINT or, the message-identifier constant value, 0x000F defined in the winuser.h header file.
  • Procedure specifies the InstanceName of the user-defined MSGHANDLER procedure to be called if Msg = Message.
  • LReturn% [OPTIONAL] specifies an user defined integer value to be returned by the procedure. If a return value is not specified then the parameter is ignored.

Remarks:


 HANDLE_MSG(WM_CREATE, Form1_OnCreate, 0) 

translates to

 
 IF Msg = WM_CREATE THEN
   Form1_OnCreate(hWnd, wParam, lParam, 0)
 END IF

HANDLE_MSG INLINE macro

Purpose: The HANDLE_MSG INLINE macro procedure, typically placed in the BEGIN EVENTS ... END EVENTS loop, is used for System-Defined Message handling in BCX. The INLINE form of the macro is much simpler to use if you only have a single line of code. If you have more code then use the form described above in Syntax 1.


 Syntax 2:

 HANDLE_MSG SysMessage1% INLINE "SendMessage(hWnd, SysMessage2%, 0, 0) : EXIT FUNCTION" 

 Parameters:

  • SysMessage1% specifies a System-Defined Message as a message-identifier or the message-identifier constant value. For example, the message-identifier WM_PAINT or the message-identifier constant value 0x000F defined in the winuser.h header file.
  • INLINE [REQUIRED] qualifier which specifies that the SendMessage statement has been written inline. The MSGHANDLER procedure is not called with the INLINE syntax.
  • SysMessage2% specifies a System-Defined Message as a message-identifier or the message-identifier constant value. For example, WM_PAINT or, the message-identifier constant value, 0x000F defined in the winuser.h header file.

Remarks:


 HANDLE_MSG SysMessage1% INLINE "SendMessage(hWnd, SysMessage2%, 0, 0) : EXIT FUNCTION" 

translates to


 IF Msg = SysMessage1 THEN
 
   SendMessage(hWnd, WM_CLOSE, 0, 0)
 
   EXIT FUNCTION
 
 END IF

MSGHANDLER macro procedure

Purpose: A MSGHANDLER macro procedure module is built to process the message from the HANDLE_MSG function.


 Syntax:
 
 MSGHANDLER InstanceName()
 
 ' your code goes here
 
 LRETURN = SendMessage(hWnd, SysMessage%, 0,0)
 
 END HANDLER
 

 Parameters:

  • InstanceName specifies the name of the MSGHANDLER procedure.
  • SysMessage1% specifies a System-Defined Message as a message-identifier or the message-identifier constant value. For example, the message-identifier WM_PAINT or the message-identifier constant value 0x000F defined in the winuser.h header file.
  • LReturn% [OPTIONAL] If the MSGHANDLER procedure produces a return value then it is returned in LReturn%.

Remarks:

 
 MSGHANDLER Form1_OnCreate()
 
 ' your code goes here
 
 LReturn = SendMessage(hWnd, SysMessage%, 0,0)
 
 END HANDLER
 

translates to


 FUNCTION Form1_OnCreate(hWnd, wParam, lParam, LReturn) AS LONG
 
   ' your code goes here
 
   LRETURN = SendMessage(hWnd, SysMessage%, 0, 0)
 
   FUNCTION = LReturn
 
 END FUNCTION

Example:


 GUI NOMAIN, PIXELS
 
 FUNCTION WINMAIN()
   GLOBAL Form1 AS CONTROL
   GLOBAL Button1 AS CONTROL
 
   Form1 = BCX_WND("MAINFORM", form1Proc, _
     "Multi-Form GUI NoMain / Dialog Test", _
                         0, 0, 0, 800, 600)

   BCX_SET_FORM_COLOR(Form1,QBCOLOR(31))
   BCX_SETICON(Form1, 123)
   Button1 = BCX_BUTTON("Modal", Form1,  98, 690,  20, 96, 24)
   BCX_BUTTON("Modeless",        Form1,  99, 690,  50, 96, 24)
   BCX_BUTTON("Modal Form",      Form1, 100, 690,  80, 96, 24)
   BCX_BUTTON("Non-Modal Form",  Form1, 105, 690, 110, 96, 24)
   BCX_BUTTON("Close",           Form1, 104, 690, 140, 96, 24)
   CENTER(Form1)
   SHOW(Form1)
   SetFocus( Button1)
 
   FUNCTION = BCX_MSGPUMP()
 END FUNCTION
 
 BEGIN EVENTS form1Proc
   SELECT CASE Msg
     HANDLE_MSG(WM_COMMAND, form1_command)
     HANDLE_MSG(WM_CLOSE, form1_close)
   END SELECT
 END EVENTS MAIN
 
 MSGHANDLER form1_command
 IF CBCTLMSG = BN_CLICKED THEN
   IF CBCTL = 98 THEN
     BCX_MDIALOG(DialogOne, "BCX Modal Dialog", Form1, 110, 110, 110, 110)
   END IF
   IF CBCTL = 99 THEN
     BCX_DIALOG(DialogTwo, "BCX Modeless Dialog", Form1, 110, 110, 110, 110)
   END IF
   IF CBCTL = 100 THEN
     LoadForm2()
   END IF
   IF CBCTL = 105 THEN
     LoadForm3()
   END IF
   IF CBCTL = 104 THEN
     SendMessage( Form1, WM_CLOSE, 0, 0)
   END IF
 END IF
 END HANDLER
 
 MSGHANDLER form1_close
 LReturn = DestroyWindow(hWnd)
 END HANDLER
 
 '----------------------------------------------------
 
 BEGIN MODAL DIALOG AS DialogOne
 
   SELECT CASE CBMSG
   CASE WM_INITDIALOG
     CENTER(hWnd)
     SHOW(hWnd)
   END SELECT
 
 END DIALOG
 
 '----------------------------------------------------
 
 BEGIN DIALOG AS DialogTwo
 
   SELECT CASE CBMSG
   CASE WM_INITDIALOG
     CENTER(hWnd)
     SHOW(hWnd)
   END SELECT
 
 END DIALOG
 
 FUNCTION LoadForm2()
   LOCAL nStyle = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | _
                  WS_CLIPSIBLINGS | WS_BORDER
   LOCAL form AS HWND
   'EnableWindow(Form1, FALSE)

   form = BCX_WND("CHILD1FORM", form2Proc, _
                        "Modal Form", Form1, _
                10, 10, 640, 400, nStyle, 0)

   BCX_SETICON(form, 123)
   BCX_BUTTON("Modal",    form, 101,560, 20, 72, 24)
   BCX_BUTTON("Modeless", form, 102,560, 50, 72, 24)
   BCX_BUTTON("Close",    form, 103,560, 80, 72, 24)
   CENTER(form)
   SHOWMODAL(form)
 
   FUNCTION = 0
 END FUNCTION
 
 FUNCTION LoadForm3()
   LOCAL nStyle = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | _
                  WS_CLIPSIBLINGS | WS_BORDER
   LOCAL form AS HWND

   form = BCX_WND("CHILD2FORM", _
                      form3Proc, _
               "Non-Modal Form", _
                          Form1, _
    10, 10, 640, 400, nStyle, 0)

   BCX_SETICON(form, 123)
   BCX_BUTTON("Modal",    form, 201, 560, 20, 72, 24)
   BCX_BUTTON("Modeless", form, 202, 560, 50, 72, 24)
   BCX_BUTTON("Close",    form, 203, 560, 80, 72, 24)
   CENTER(form)
   SHOW(form)
 
   FUNCTION = 0
 END FUNCTION
 
 BEGIN EVENTS form3Proc
   SELECT CASE CBMSG
   CASE WM_CREATE
     STATIC nWndNo = 0
     SetWindowText( hWnd, "Window No. " & TRIM$(STR$(++nWndNo)))
   CASE WM_COMMAND
     IF CBCTLMSG = BN_CLICKED THEN
       IF CBCTL = 201 THEN
         BCX_MDIALOG(DialogOne, "BCX Modal Dialog", hWnd, 110, 110, 110, 110)
       END IF
       IF CBCTL = 202 THEN
         BCX_DIALOG(DialogTwo, "BCX Modeless Dialog", hWnd, 110, 110, 110, 110)
       END IF
       IF CBCTL = 203 THEN
         SendMessage( hWnd, WM_CLOSE, 0, 0)
       END IF
     END IF
   CASE WM_CLOSE
     DestroyWindow(hWnd)
   END SELECT
 END EVENTS
 
 BEGIN EVENTS form2Proc
   SELECT CASE CBMSG
   CASE WM_COMMAND
     IF CBCTLMSG = BN_CLICKED THEN
       IF CBCTL = 101 THEN
         BCX_MDIALOG(DialogOne, "BCX Modal Dialog", hWnd, 110, 110, 110, 110)
       END IF
       IF CBCTL = 102 THEN
         BCX_DIALOG(DialogTwo, "BCX Modeless Dialog", hWnd, 110, 110, 110, 110)
       END IF
       IF CBCTL = 103 THEN
         SendMessage( hWnd, WM_CLOSE, 0, 0)
       END IF
     END IF
   CASE WM_CLOSE
     ENDMODAL(hWnd)
     SetFocus( Form1)
   END SELECT
 END EVENTS