1

I am trying to make a beautiful table and am using LVS_OWNERDRAWFIXED style to draw my own table design. So, I want to change the header item height of the table but can't do this. I am using the code below to change item height but its just changing item width. What am I doing wrong here, anyone know?

        HDITEM hi = { 0 };
        hi.mask = HDI_FORMAT | HDI_HEIGHT;
        Header_GetItem(hHeader, i, &hi);
        hi.fmt = HDF_OWNERDRAW;
        hi.cxy = 70; // this always sets width instead of height
        Header_SetItem(hHeader, i, &hi);

There is no much information about header resizing online, maybe someone knows what is the problem here?

  • `HDI_HEIGHT` and `HDI_WIDTH` are the same value (you can verify this by looking at the declarations in `commctrl.h`), which means you can only set a header item's width using `Header_SetItem()`. A ListView's header has the same height as the ListView's items, unless you set the header to use a dfferent font – Remy Lebeau Jan 28 '22 at 23:06
  • 1
    https://stackoverflow.com/questions/3904572/c-sharp-listview-colum-header-height-windows-form – Hans Passant Jan 28 '22 at 23:10

1 Answers1

2

I solved this problem myself. I got the list view header HWND and set SetWindowSubclass() on that, then in the subclass method I caught HDM_LAYOUT event and put there the code below:

    case HDM_LAYOUT: {
        LPHDLAYOUT pHL = reinterpret_cast<LPHDLAYOUT>(lParam);
        RECT* pRect = pHL->prc;
        WINDOWPOS* pWPos = pHL->pwpos;
        int r = DefSubclassProc(hWnd, uMsg, wParam, lParam);
        pWPos->cy = 50; // Header height
        pRect->top = 50; // Header offset top
        return r;
    }

This all works perfect, thanks for your answers anyways.