HANDLE_CMD macro

Purpose:

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

Syntax 1:

HANDLE_CMD(CMD_ID AS USHORT, Procedure, [Number AS LONG])

Parameters:

  • Data type: USHORT
    CMD_ID Specifies the System-Defined WM_COMMAND Message as a message-identifier or the message-identifier constant value of a control or accelerator.
  • Data type: Identifier
    Procedure Specifies the InstanceName of the user-defined CMDHANDLER procedure to be called if CBCTL = CMD_ID.
  • 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_CMD(IDM_NEW, OnNewClick, 0)

translates to

IF  Msg = WM_COMMAND AND CBCTL = IDM_NEW THEN
  OnNewClick(hWnd, wParam, lParam, 0)
END IF

Example:

🔗 For a thorough demo of HANDLE_CMD macro, please see the example in the BCX_FRAMEWND section.


HANDLE_CMD INLINE macro

Purpose:

The HANDLE_CMD ... 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_CMD CMD_ID1 INLINE "SendMessage(hWnd, CMD_ID2, 0, 0) : EXIT FUNCTION"

Parameters:

  • Data type: USHORT
    CMD_ID Specifies the System-Defined WM_COMMAND Message as a message-identifier or the message-identifier constant value of a control or accelerator.
  • INLINE [REQUIRED] qualifier which specifies that the SendMessage statement has been written inline. The CMDHANDLER procedure is not called with the INLINE syntax.
  • Data type: USHORT
    CMD_ID2 Specifies the System-Defined WM_COMMAND Message as a message-identifier or the message-identifier constant value of a control or accelerator.

Remarks:

HANDLE_CMD CMD_ID1 INLINE "SendMessage(hWnd, CMD_ID2, 0, 0) : EXIT FUNCTION"

is translated to an intermediate BCX code

IF Msg = WM_COMMAND AND CBCTL = CMD_ID1 THEN

  SendMessage(hWnd, CMD_ID2, 0, 0)

  EXIT FUNCTION

END IF

before translation to C code.


CMDHANDLER macro procedure

Purpose:

A CMDHANDLER macro procedure module is built to process the message from the HANDLE_CMD function.

Syntax:

CMDHANDLER InstanceName()

' your code goes here

LReturn = SendMessage(hWnd, CMD_ID, 0, 0)

END HANDLER

Parameters:

  • Data type: Identifier
    InstanceName Specifies the name of the CMDHANDLER procedure.
  • Data type: USHORT
    CMD_ID The System-Defined WM_COMMAND Message as a message-identifier or the message-identifier constant value of a control or accelerator.
  • Data type: LRESULT
    LReturn [OPTIONAL] If the CMDHANDLER procedure produces a return value then it is returned in LReturn.

    👉 LReturn is a case sensitive system variable.

Remarks:

CMDHANDLER OnNewClick()

' your code goes here

LReturn = SendMessage(hWnd, IDM_NEW, 0, 0)

END HANDLER

is translated to an intermediate BCX code

FUNCTION OnNewClick (hWnd, wParam, lParam, LReturn) AS LRESULT

  ' your code goes here

  LReturn = SendMessage(hWnd, IDM_NEW, 0, 0)

  FUNCTION = LReturn

END FUNCTION

before translation to C code.

Example:

🔗 For a thorough demo of CMDHANDLER ... END HANDLER please see the example in the BCX_FRAMEWND section.