Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function sets the mouse or style capture to a specified window that belongs to the current thread. After you call this function for a window, the window captures mouse input that occurs while the mouse cursor remains within the window. The window also captures mouse input that occurs when the user presses a mouse button while the mouse cursor is located within the window and continues to hold the mouse button down while moving the mouse. Only one window at a time can capture the mouse or stylus.

Syntax

HWND SetCapture(
  HWND 
hWnd 
); 

Parameters

hWnd

[in] Handle to the window in the current thread that is to capture the mouse.

Return Value

The handle of the window that had previously captured the mouse indicates success. NULL indicates that no window previously captured the mouse.

Remarks

Only the foreground window can capture the mouse. When a background window attempts to do so, the window receives messages only for mouse events that occur when the cursor hot spot is within the visible portion of the window. Also, even if the foreground window has captured the mouse, the user can still click another window, bringing it to the foreground.

When the window no longer requires all mouse input, the thread that created the window should call the ReleaseCapturefunction to release the mouse.

This function cannot be used to capture mouse input meant for another process.

Requirements

Header windows.h
Library coredll.lib
Windows Embedded CE Windows CE 1.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also