How do you place sub-controls inside a group window?

When I turn on general support for the visual control style (InitCommonControls ()), and I use any theme other than Windows Classic Theme, the buttons inside the group window appear with a black border with square corners.

Windows Classic Theme looks fine, and also when I turn off the visual style.

I am using the following code:

group_box = CreateWindow(TEXT("BUTTON"), TEXT("BS_GROUPBOX"), 
    WS_CHILD | WS_VISIBLE | BS_GROUPBOX | WS_GROUP,
    10, 10, 200, 300,
    hwnd, NULL, hInstance, 0);

push_button = CreateWindow(TEXT("BUTTON"), TEXT("BS_PUSHBUTTON"),
    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
    40, 40, 100, 22,
    group_box, NULL, hInstance, 0);

EDIT: problem arises with switches

EDIT: I do not use any dialogs / resources, only CreateWindow / Ex.

I am compiling in Visual C ++ 2008 Express SP1 with a common manifest

Screenshot http://img.ispankcode.com/black_border_issue.png

+3
source share
4 answers

, . , ( , ). "CreateWindow" group_box hwnd (.. ).

, , . - groupbox . , RECT, . , :

// Calculate the client area of a dialog that corresponds to the perceived
// client area of a groupbox control. An extra padding in dialog units can
// be specified (preferably in multiples of 4).
//
RECT getClientAreaInGroupBox(HWND dlg, int id, int padding = 0) {
    HWND group = GetDlgItem(dlg, id);
    RECT rc;
    GetWindowRect(group, &rc);
    MapWindowPoints(0, dlg, (POINT*)&rc, 2);

    // Note that the top DUs should be 9 to completely avoid overlapping the
    // groupbox label, but 8 is used instead for better alignment on a 4x4
    // design grid.
    RECT border = { 4, 8, 4, 4 };
    OffsetRect(&border, padding, padding);
    MapDialogRect(dlg, &border);

    rc.left += border.left;
    rc.right -= border.right;
    rc.top += border.top;
    rc.bottom -= border.bottom;
    return rc;
}

, Tab. .

+4

, , Static Edge Client Edge . .

CreateWindow CreateWindowEx, , , , CreateWindow. , WS_EX_STATICEDGE, WS_EX_WINDOWEDGE and WS_EX_CLIENTEDGE

: , , - , .

+1

, ( hwnd)

, / , WM_PAINT WM_PRINTCLIENT

0

Ahh yes black background with switches and group boxes. Although I'm not sure that this will work on VC ++ 2008, but at the same time, the solution for VB6 themed applications was to first install the radio controls on the PictureBox (shared container), and then add this to the group box.

Its worth making!

-2
source

Source: https://habr.com/ru/post/1698431/


All Articles