TabControl在显示溢出箭头时剪切客户区

时间:2011-07-19 20:19:50

标签: c winapi windows-xp tabcontrol

此错误仅在XP上使用通用控件v6(启用主题)时出现(似乎适用于7和2008)。我想知道其他人是否可能看过这个 bug 功能。

当您有一个包含大量标签的单行TabControl时,如果没有足够的空间显示所有标签,则应显示一对箭头。这很好,除了客户区也被剪裁,这根本不好。

我错过了什么吗?我玩了tabcontrol的窗口风格,但到目前为止没有运气。

为了说明这一点,实际上最好看到它的实际效果:

#define UNICODE
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>

LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);

HWND htab, hbut;

int WINAPI WinMain (HINSTANCE instance,
                    HINSTANCE previnst,
                    LPSTR args,
                    int wndState)
{
    int i;
    MSG messages;
    WNDCLASSEX wincl = {
        .hInstance = instance, .lpszClassName = L"WindowsApp",
        .lpfnWndProc = WindowProcedure, .style = CS_DBLCLKS, .cbSize = sizeof wincl,
        .hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1)
    };

    InitCommonControls();

    wincl.hIcon   = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor(NULL, IDC_ARROW);

    if (!RegisterClassEx (&wincl))
        return 0;

    HWND hwnd = CreateWindow(L"WindowsApp", L"Windows App", WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 544, 375, HWND_DESKTOP, NULL, instance, NULL);

    htab = CreateWindowEx(WS_EX_CONTROLPARENT, WC_TABCONTROL,
        L"MyTab", WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, 10, 10, 514, 325, hwnd,
        (HMENU) 10, instance, NULL);

    hbut = CreateWindow(
        WC_BUTTON, L"My nice button that is clipped", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
        10, 30, 494, 285, htab, (HMENU) IDOK, instance, NULL
    );

    for (i = 0; i < 10; i ++)
    {
        WCHAR  myBuf[100];
        TCITEM tc = {.mask = TCIF_TEXT, .pszText = myBuf};
        wsprintf(myBuf, L"My super tab %d", i + 1);
        TabCtrl_InsertItem(htab, i, &tc);
    }

    SendMessage(hbut, WM_SETFONT, (LPARAM) GetStockObject(DEFAULT_GUI_FONT), FALSE);
    SendMessage(htab, WM_SETFONT, (LPARAM) GetStockObject(DEFAULT_GUI_FONT), FALSE);

    ShowWindow(hwnd, wndState);

    while (GetMessage (&messages, NULL, 0, 0))
    {
        TranslateMessage(&messages);
        DispatchMessage(&messages);
    }
    return messages.wParam;
}

LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    RECT r;
    switch (message) {
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    case WM_SIZE:
        GetClientRect(hwnd, &r);
        MoveWindow(htab, 10, 10, r.right-20, r.bottom - 20, TRUE);
        MoveWindow(hbut, 10, 30, r.right-40, r.bottom - 60, TRUE);
        break;
    case WM_COMMAND:
        break;
    default:
        return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return 0;
}

1 个答案:

答案 0 :(得分:0)

不幸的是我无法测试它(我有Win7)但是根据http://msdn.microsoft.com/en-us/library/hh298367%28v=VS.85%29.aspx你需要在制表符控件和父窗口上有剪辑兄弟。您还可以尝试使用选项卡控件的adjust rect消息来获取按钮的位置。