11 out of 17 rated this helpful - Rate this topic

EnableWindow function

Applies to: desktop apps only

Enables or disables mouse and keyboard input to the specified window or control. When input is disabled, the window does not receive input such as mouse clicks and key presses. When input is enabled, the window receives all input.

Syntax

BOOL WINAPI EnableWindow(
  __in  HWND hWnd,
  __in  BOOL bEnable
);

Parameters

hWnd [in]

Type: HWND

A handle to the window to be enabled or disabled.

bEnable [in]

Type: BOOL

Indicates 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

Type: BOOL

If the window was previously disabled, the return value is nonzero.

If the window was not previously disabled, the return value is zero.

Remarks

If the window is being disabled, the system sends a WM_CANCELMODE message. If the enabled state of a window is changing, the system sends a WM_ENABLE message after the WM_CANCELMODE message. (These messages are sent before EnableWindow returns.) If a window is already disabled, 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 keyboard focus and be activated. If a child window is disabled, it is ignored when the system tries to determine which window should receive mouse messages.

By default, a window is enabled when it is created. To create a window that is initially disabled, an application can specify the WS_DISABLED style in the CreateWindow or CreateWindowEx function. After a window has been created, an application can use EnableWindow 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 keyboard focus, nor can a user gain access to it.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

See also

Reference
CreateWindow
CreateWindowEx
IsWindowEnabled
WM_ENABLE
Conceptual
Keyboard Input

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
disabling a listview doesn't disable mousewheel

disabling a listview doesn't disable mousewheel (can still scroll)

SendMessage or PostMessage ?
Is WM_ENABLE sent or posted ? It was told like in Delphi in long-running message handler, the effect of some control disabled is not applied to its behavior, until the call to UpdateWindow ( or to ProcessMessages secondary loop) is made. So it seems like WM_ENABLE is posted, not sent.
Take care if using this to disable a dialog box control
Some care is needed if using this to disable a dialog box control.  If the control had focus when it becomes disabled, the focus might be stranded.  See http://blogs.msdn.com/b/oldnewthing/archive/2004/08/04/208005.aspx
Sample Code(C#)

[DllImport("user32.dll")]
public static extern IntPtr FindWindow(String sClassName, String sAppName);
[DllImport("user32.dll")]
public static extern bool EnableWindow(IntPtr hwnd, bool bEnable);

public void SampleFunction()
{
IntPtr hwnd=FindWindow(null,"Form");
EnableWindow(hwnd,"false");//to enable set boolean value to true
}