Partager via


DrawFocusRectColor

4/8/2010

This function is used to draw a focus rectangle in a style and color that are based on the current theme.

Syntax

BOOL DrawFocusRectColor (
   HDC hdc,
   const RECT* lprc,
   UINT uFlags
);

Parameters

  • hdc
    [in] Handle to the device context.
  • lprc
    [in] Pointer to a RECT structure that specifies the coordinates of the bounding rectangle for the window.
  • uFlags
    [in] Flags specifying the properties of the focus rectangle.

    Value Description

    DFRC_FOCUSCOLOR

    DrawFocusRectColor will use the brush obtained from GetSysColorBrush, with the color index set to COLOR_HIGHLIGHT, to render the focus rectangle. This means that the focus color will be based on the theme setting.

    DFRC_SELECTEDBRUSH

    DrawFocusRectColor will use the brush that is selected into the device context using SelectObject. Users can change the brush to the desired style and color. In addition, the brush can be used to erase this focus rectangle by using background color and the same style.

Return Value

Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError function.

Code Example

The following code example demonstrates how to use DrawFocusRectColor.

Note

To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.

LRESULT DlgProcOwnerDrawnFocus(HWND hDlg, UINT msg, UINT wParam, LONG lParam)
{
    // One of the children of this dialog is an owner drawn button
    LPDRAWITEMSTRUCT lpdis;
    LRESULT lRet = FALSE;
    
    switch (msg)
    {
        case WM_DRAWITEM:
            // State of owner drawn button has changed and we need to update it
            lpdis = (LPDRAWITEMSTRUCT) lParam;
            // Fill button background
            FillRect(lpdis->hDC, &lpdis->rcItem, GetSysColorBrush(COLOR_WINDOW));
            
            if (lpdis->itemState & ODS_FOCUS)
            {
                // If button has focus, we want to draw a focus rect in
                // a color appropriate for theme
                DrawFocusRectColor(lpdis->hDC, &lpdis->rcItem, DFRC_FOCUSCOLOR);
            }
            // Do more drawing code
            // Tell system that we handled the message
            lRet = TRUE;
            break;
        // Handling for other messages
    }
    return lRet;
}

Requirements

Header aygshell.h
Library aygshell.lib
Windows Embedded CE Windows Embedded CE 6.0 and later

See Also

Reference

Shell Functions