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, but it is permissible to kill a different control in the notification handler. If is absolutely necessary to kill a control while processing one of its notification messages, 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 CB.MSG

    CASE %WM_COMMAND

      IF CB.CTLMSG = %BN_CLICKED AND CB.CTL = %MyBtn THEN

        DIALOG POST CB.HNDL, %WM_USER + 999&, 0, 0

      END IF

    CASE %WM_USER + 999&

      CONTROL KILL CB.HNDL, %MyBtn

      FUNCTION = 1

  END SELECT

END FUNCTION