DrawFocusRect function (winuser.h)

The DrawFocusRect function draws a rectangle in the style used to indicate that the rectangle has the focus.


BOOL DrawFocusRect(
  [in] HDC        hDC,
  [in] const RECT *lprc


[in] hDC

A handle to the device context.

[in] lprc

A pointer to a RECT structure that specifies the logical coordinates of the rectangle.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero.


DrawFocusRect works only in MM_TEXT mode.

Because DrawFocusRect is an XOR function, calling it a second time with the same rectangle removes the rectangle from the screen.

This function draws a rectangle that cannot be scrolled. To scroll an area containing a rectangle drawn by this function, call DrawFocusRect to remove the rectangle from the screen, scroll the area, and then call DrawFocusRect again to draw the rectangle in the new position.

Windows XP: The focus rectangle can now be thicker than 1 pixel, so it is more visible for high-resolution, high-density displays and accessibility needs. This is handled by the SPI_SETFOCUSBORDERWIDTH and SPI_SETFOCUSBORDERHEIGHT in SystemParametersInfo.


For an example, see "Creating an Owner-Drawn List Box" in Using List Boxes.


Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header winuser.h (include Windows.h)
Library User32.lib
DLL User32.dll
API set ext-ms-win-ntuser-draw-l1-1-0 (introduced in Windows 8)

See also


Painting and Drawing Functions

Painting and Drawing Overview