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 AS USHORT, Procedure, [Number AS LONG])

Parameters:

  • Data type: USHORT
    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.
  • Data type: Identifier
    Procedure Specifies the InstanceName of the user-defined MSGHANDLER procedure to be called if CBMSG = SysMessage.
  • Data type: LONG
    Number [OPTIONAL] A user defined 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 CBMSG = 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 AS USHORT INLINE "SendMessage(hWnd, SysMessage2, 0, 0) : EXIT FUNCTION"

Parameters:

  • Data type: USHORT
    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] A qualifier which specifies that the SendMessage statement has been written inline. The MSGHANDLER procedure is not called with the INLINE syntax.
  • Data type: USHORT
    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, SysMessage2, 0, 0)

  EXIT FUNCTION

END IF

MSGHANDLER macro

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:

  • Data type: Identifier
    InstanceName Specifies the name of the MSGHANDLER procedure.
  • Data type: USHORT
    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.
  • Data type: LRESULT
    LReturn [OPTIONAL] If the MSGHANDLER procedure produces a return value then it is returned in LReturn.

    👉 LReturn is a case sensitive system variable.

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, 400, 300)
  BCX_SET_FORM_COLOR(Form1, QBCOLOR(31))
  BCX_SETICON(Form1, 123)
  Button1 = BCX_BUTTON("Modal", Form1,  98, 270,  20, 96, 24)
  BCX_BUTTON("Modeless",        Form1,  99, 270,  50, 96, 24)
  BCX_BUTTON("Modal Form",      Form1, 100, 270,  80, 96, 24)
  BCX_BUTTON("Non-Modal Form",  Form1, 105, 270, 110, 96, 24)
  BCX_BUTTON("Close",           Form1, 104, 270, 140, 96, 24)
  CENTER(Form1)
  SHOW(Form1)
  SetFocus(Button1)
    
  FUNCTION = BCX_MSGPUMP()
END FUNCTION
    
BEGIN EVENTS form1Proc
  HANDLE_MSG(WM_COMMAND, form1_command)
  HANDLE_MSG(WM_CLOSE, form1_close)
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
  LOCAL form2 AS HWND
  form2 = BCX_WND("CHILD1FORM", form2Proc, "Modal Form", Form1, 10, 10, 640, 400, nStyle, 0)
  BCX_SETICON(form2, 123)
  BCX_BUTTON("Modal",    form2, 101,560, 20, 72, 24)
  BCX_BUTTON("Modeless", form2, 102,560, 50, 72, 24)
  BCX_BUTTON("Close",    form2, 103,560, 80, 72, 24)
  SHOWMODAL(form2)
    
  FUNCTION = 0
END FUNCTION
    
FUNCTION LoadForm3 ()
  LOCAL nStyle
  LOCAL form3 AS HWND
  form3 = BCX_WND("CHILD2FORM", form3Proc, "Non-Modal Form", Form1, 120, 120, 640, 400, nStyle, 0)
  BCX_SETICON(form3, 123)
  BCX_BUTTON("Modal",    form3, 201, 560, 20, 72, 24)
  BCX_BUTTON("Modeless", form3, 202, 560, 50, 72, 24)
  BCX_BUTTON("Close",    form3, 203, 560, 80, 72, 24)
  SHOW(form3)
    
  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