Question

I have a custom control created using CreateWindowEx with the WS_BORDER style. Everything works fine apart from the border appearing in a different colour to other controls in the dialog box. The border in my control is black, the other controls have a blue border. I've tried calling EnableThemeDialogTexture(_dialogHandle, ETDT_ENABLE) after creating the control, as well as the logic from http://www.patchou.com/projects/richedit/ but to no avail. I'm using C++ and the Winapi. ie. no MFC, no .Net. Any guidance very much appreciated.

EDIT: Here's the logic that worked for me:

HDC hdc = GetWindowDC(hwnd);
HTHEME themeHandle = OpenThemeData(hwnd, L"Edit");
if(themeHandle)
{
    int cxBorder = GetSystemMetrics(SM_CXBORDER);
    int cyBorder = GetSystemMetrics(SM_CYBORDER);
    RECT rc;
    GetClientRect(hwnd, &rc);                   
    OffsetRect(&rc, cxBorder, cyBorder);
    ExcludeClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom);
    InflateRect(&rc, cxBorder, cyBorder);
    DrawThemeBackground(themeHandle, hdc, 0, 0, &rc, NULL);
    CloseThemeData(themeHandle);
 }

ReleaseDC(hwnd, hdc);
Was it helpful?

Solution

You have to draw the border yourself, using the theme from another control (for example, the listview or treeview control). For a custom child control, drawing the border is quite easy - simply handle the WM_NCPAINT message. The part ID and state ID when you draw the border should both be 0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top