EnableWindow

2.x

  BOOL EnableWindow(hwnd, fEnable)    
  HWND hwnd; /* handle of window, */  
  BOOL fEnable; /* flag for enabling or disabling input */

The EnableWindow function enables or disables mouse and keyboard input to the given window or control. When input is disabled, the window ignores input such as mouse clicks and key presses. When input is enabled, the window processes all input.

Parameters

hwnd

Identifies the window to be enabled or disabled.

fEnable

Specifies whether to enable or disable the window. If this parameter is TRUE, the window is enabled. If the parameter is FALSE, the window is disabled.

Return Value

The return value is nonzero if the window was previously disabled. Otherwise, the return value is zero.

Comments

If the enabled state of the window is changing, a WM_ENABLE message is sent before this function returns. If a window is already disabled, all its child windows are implicitly disabled, although they are not sent a WM_ENABLE message.

A window must be enabled before it can be activated. For example, if an application is displaying a modeless dialog box and has disabled its main window, the application must enable the main window before destroying the dialog box. Otherwise, another window will receive the input focus and be activated. If a child window is disabled, it is ignored when Windows tries to determine which window should receive mouse messages.

By default, a window is enabled when it is created. An application can specify the WS_DISABLED style in the CreateWindow or CreateWindowEx function to create a window that is initially disabled. After a window has been created, an application can use the EnableWindow function to enable or disable the window.

An application can use this function to enable or disable a control in a dialog box. A disabled control cannot receive the input focus, nor can a user access it.

Example

The following example enables a Save push button in a dialog box, depending on whether a user-specified filename exists:

static char szFileName[128];

case WM_INITDIALOG:

    /* If a filename is specified, enable the Save push button. */

    EnableWindow(GetDlgItem(hdlg, IDOK),
        (szFileName[0] == '\0' ? FALSE : TRUE));
    return TRUE;

See Also

IsWindowEnabled