2

因为我不喜欢 ListView 与 Explorer 主题结合报表视图中的网格线的方式,所以我想在网格线打开时关闭主题。问题是,一旦应用了 Explorer 主题,就无法将 ListView 恢复为其原始外观。

我尝试了NULL,L""L" "作为SetWindowTheme参数的各种组合,但似乎没有任何东西可以修复绘图错误。我已经在 Windows 8 和 10 上进行了测试。

有绘图错误的 ListView

#define WINVER 0x500
#define _WIN32_IE 0x400
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <uxtheme.h>
#include <tchar.h>
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "comctl32.lib")
#pragma comment(lib, "uxtheme.lib")

HWND hMain;
HWND hList;
UINT Step = 0;

void CALLBACK Steps(HWND h, UINT, UINT_PTR idEvent, DWORD)
{
    switch(++Step)
    {
    case 1:
        SetTimer(h, idEvent, 3333, Steps);
        SetWindowTextA(hMain, "Correct; Narrow selection gap");
        SetFocus(hList);
        break;
    case 2:
        SetWindowTheme(hList, L"Explorer", NULL);
        SetWindowTextA(hMain, "Correct; Narrow selection gap and theme");
        break;
    case 3:
        SetWindowTheme(hList, NULL, NULL); // BUG: This disables the theme but does not fully restore the ListView!
        SetWindowTextA(hMain, "Incorrect; Wide selection gap!");
        break;
    case 4:
        PostQuitMessage(0);
        break;
    }
}

EXTERN_C DECLSPEC_NORETURN void WinMainCRTStartup()
{
    InitCommonControls();
    HINSTANCE hInst = GetModuleHandle(0);
    hMain = CreateWindowExA(0, (char*)32770, 0, WS_VISIBLE|WS_OVERLAPPEDWINDOW, 110, 110, 500, 100, 0, (HMENU) 0, hInst, NULL);
    hList = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL, WS_VISIBLE|WS_CHILD|LVS_REPORT|LVS_SHOWSELALWAYS, 0, 0, 500, 100, hMain, (HMENU) 0, hInst, NULL);
    SNDMSG(hList, CCM_SETVERSION, 5, 0), SNDMSG(hList, CCM_SETVERSION, 6, 0); // This does not help
    ListView_SetExtendedListViewStyle(hList, LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_DOUBLEBUFFER);
    LVCOLUMN lvc;
    lvc.mask = LVCF_TEXT|LVCF_SUBITEM|LVCF_WIDTH, lvc.iSubItem = 0, lvc.cx = 50;
    lvc.pszText = TEXT("Foo"), lvc.iSubItem = 1 + (UINT) SNDMSG(hList, LVM_INSERTCOLUMN, lvc.iSubItem, (SIZE_T) &lvc);
    lvc.pszText = TEXT("Bar"), lvc.iSubItem = 1 + (UINT) SNDMSG(hList, LVM_INSERTCOLUMN, lvc.iSubItem, (SIZE_T) &lvc);
    LVITEMA lvi;
    lvi.mask = LVIF_TEXT;
    lvi.iItem = 0, lvi.iSubItem = 0;
    lvi.pszText = const_cast<LPSTR>("Hello");
    SNDMSG(hList, LVM_INSERTITEMA, 0, (SIZE_T) &lvi);
    ListView_SetItemState(hList, 0, LVIS_FOCUSED|LVIS_SELECTED, ~UINT(0));
    
    SetTimer(hMain, 1, 50, Steps);
    MSG msg;
    while((int) GetMessage(&msg, NULL, 0, 0) > 0) TranslateMessage(&msg), DispatchMessage(&msg);
    ExitProcess(0);
}
4

0 回答 0