CONTROL KILL statement

Purpose

Remove a control from a dialog.

Syntax

CONTROL KILL hDlg, id&

Remarks

hDlg refers to the dialog that owns the control. id& is the unique control identifier as assigned to the control with a CONTROL ADD statement.

The control is destroyed and removed from the dialog. The Callback Function for the control or dialog will no longer receive messages for the control.

Restrictions 

A control should not be destroyed while processing a notification message from the same control. That is, a control should not "commit suicide", but it is permissible to kill a different control in the notification handler. If a suicide condition is absolutely necessary, use the PostMessage API function (or the DIALOG POST or CONTROL POST statements) to post a user-defined message to the dialog callback, and kill the control when processing the user-defined message.

See also

Dynamic Dialog Tools, CONTROL DISABLE, CONTROL ENABLE

Example

' How to avoid "suicide" conditions

CALLBACK FUNCTION DlgCallBack() AS LONG

  SELECT CASE CBMSG

    CASE %WM_COMMAND

      IF CBCTLMSG = %BN_GOTFOCUS AND CBCTL = %MyBtn THEN

        DIALOG POST CBHNDL, %WM_USER + 999&, 0, 0

      END IF

    CASE %WM_USER + 999&

      CONTROL KILL CBHNDL, %MyBtn

      FUNCTION = 1

  END SELECT

END FUNCTION