Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8494751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:23:04+00:00 2026-06-10T23:23:04+00:00

I try to add an empty markup to a ListView , but when I

  • 0

I try to add an empty markup to a ListView, but when I use SetWindowTheme or AutoResizeColumns, the markup disappears. Here’s an example:

internal static class ExtensionMethods
{
    public static void SetDoubleBuffered(this ListView listview, bool value)
    {
        PropertyInfo pi = typeof(ListView).GetProperty("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance);
        pi.SetValue(listview, value);
    }

    public static void SetWindowTheme(this ListView listview, string pszSubAppName, string pszSubIdList)
    {
        NativeMethods.SetWindowTheme(listview.Handle, pszSubAppName, pszSubIdList);
    }
}

internal static class NativeMethods
{
    public const Int32 WM_NOTIFY = 0x004e;
    public const Int32 WM_LBUTTONDBLCLK = 0x0203;
    public const Int32 WM_USER = 0x0400;
    public const UInt32 LVN_FIRST = unchecked(0u - 100u);
    public const UInt32 LVN_GETEMPTYMARKUP = LVN_FIRST - 87;
    public const Int32 L_MAX_URL_LENGTH = 2084;

    [StructLayout(LayoutKind.Sequential)]
    public struct NMHDR
    {
        public IntPtr hwndFrom;
        public IntPtr idFrom;
        public UInt32 code;
    }

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public struct NMLVEMPTYMARKUP
    {
        public NMHDR hdr;
        public UInt32 dwFlags;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = L_MAX_URL_LENGTH)]
        public String szMarkup;
    }

    [DllImport("uxtheme.dll", CharSet = CharSet.Unicode)]
    public static extern Int32 SetWindowTheme(IntPtr hWnd, String pszSubAppName, String pszSubIdList);
}

public partial class MainForm : Form
{
    private ListView listView1 = new ListView();

    public MainForm()
    {
        InitializeComponent();

        this.Controls.Add(listView1);

        listView1.Dock = DockStyle.Fill;
        listView1.View = View.Details;
        listView1.Columns.Add("Test");

        listView1.SetDoubleBuffered(true);

        // listView1.SetWindowTheme("Explorer", null);
        // listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
    }

    protected override void WndProc(ref Message m)
    {
        switch (m.Msg)
        {
            case NativeMethods.WM_NOTIFY:
                var nmhdr = (NativeMethods.NMHDR)m.GetLParam(typeof(NativeMethods.NMHDR));
                switch (nmhdr.code)
                {
                    case NativeMethods.LVN_GETEMPTYMARKUP:
                        if (Control.FromHandle(nmhdr.hwndFrom) == listView1)
                        {
                            var markup = (NativeMethods.NMLVEMPTYMARKUP)m.GetLParam(typeof(NativeMethods.NMLVEMPTYMARKUP));
                            markup.szMarkup = "This is an empty ListView.";
                            Marshal.StructureToPtr(markup, m.LParam, false);
                            m.Result = new IntPtr(1);
                            return;
                        }
                        break;
                }
                break;
        }
        base.WndProc(ref m);
    }
}

This works. But if I uncomment either line of

    // listView1.SetWindowTheme("Explorer", null);
    // listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);

the empty markup disappears. How do I set empty markup while using SetWindowTheme and AutoResizeColumns?

Update

I wrote an example of C version that confirms the empty mark can work with SetWindowTheme and something like AutoResizeColumns in Win32 level. But why not C#?

#define _CRT_SECURE_NO_DEPRECATE
#define WIN32_LEAN_AND_MEAN
#define STRICT

#include <tchar.h>
#include <Windows.h>
#include <windowsx.h>
#include <CommCtrl.h>
#include <Uxtheme.h>

#pragma comment(lib, "uxtheme.lib")
#pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
BOOL MainWindow_OnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct);
void MainWindow_OnDestroy(HWND hWnd);
void MainWindow_OnSize(HWND hWnd, UINT state, int cx, int cy);
void MainWindow_OnPaint(HWND hWnd);
LRESULT MainWindow_OnNotify(HWND hWnd, int idFrom, LPNMHDR pnmhdr);

#define ID_LISTVIEW 100

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
  WNDCLASSEX wcex = { 0 };
  HWND hWnd;
  BOOL ret;
  MSG msg;

  wcex.cbSize = sizeof(wcex);
  wcex.lpfnWndProc = WindowProc;
  wcex.hInstance = hInstance;
  wcex.hIcon = (HICON)LoadImage(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED);
  wcex.hCursor = (HCURSOR)LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED);
  wcex.lpszClassName = TEXT("MainWindow");

  if (!RegisterClassEx(&wcex))
  {
    return 1;
  }

  hWnd = CreateWindow(wcex.lpszClassName, TEXT("Win32Test"), WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND_DESKTOP, NULL, hInstance, NULL);
  if (!hWnd)
  {
    return 1;
  }

  ShowWindow(hWnd, nCmdShow);
  UpdateWindow(hWnd);

  while ((ret = GetMessage(&msg, NULL, 0, 0)) != 0)
  {
    if (ret == -1)
    {
      return 1;
    }
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }

  return msg.wParam;
}

LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  switch (uMsg)
  {
    HANDLE_MSG(hWnd, WM_CREATE, MainWindow_OnCreate);
    HANDLE_MSG(hWnd, WM_DESTROY, MainWindow_OnDestroy);
    HANDLE_MSG(hWnd, WM_SIZE, MainWindow_OnSize);
    HANDLE_MSG(hWnd, WM_PAINT, MainWindow_OnPaint);
    HANDLE_MSG(hWnd, WM_NOTIFY, MainWindow_OnNotify);
  default:
    return DefWindowProc(hWnd, uMsg, wParam, lParam);
  }
}

BOOL MainWindow_OnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct)
{
  HWND h_listview = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL, WS_CHILD | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hWnd, (HMENU)ID_LISTVIEW, GetModuleHandle(NULL), NULL);
  LVCOLUMN lvc = { 0 };

  SetWindowTheme(h_listview, TEXT("Explorer"), NULL);
  ListView_SetExtendedListViewStyle(h_listview, LVS_EX_DOUBLEBUFFER);
  ListView_SetView(h_listview, LV_VIEW_DETAILS);
  lvc.mask = LVCF_TEXT;
  lvc.pszText = TEXT("Column 1");
  ListView_InsertColumn(h_listview, 0, &lvc);
  ListView_SetColumnWidth(h_listview, 0, LVSCW_AUTOSIZE_USEHEADER);

  return TRUE;
}

void MainWindow_OnDestroy(HWND hWnd)
{
  PostQuitMessage(0);
}

void MainWindow_OnSize(HWND hWnd, UINT state, int cx, int cy)
{
  MoveWindow(GetDlgItem(hWnd, ID_LISTVIEW), 11, 11, cx - 22, cy - 22, TRUE);
}

void MainWindow_OnPaint(HWND hWnd)
{
  PAINTSTRUCT ps;

  BeginPaint(hWnd, &ps);

  FillRect(ps.hdc, &ps.rcPaint, GetSysColorBrush(COLOR_3DFACE));

  EndPaint(hWnd, &ps);
}

LRESULT MainWindow_OnNotify(HWND hWnd, int idFrom, LPNMHDR pnmhdr)
{
  switch (pnmhdr->code)
  {
  case LVN_GETEMPTYMARKUP:
    {
      if (pnmhdr->hwndFrom == GetDlgItem(hWnd, ID_LISTVIEW))
      {
        NMLVEMPTYMARKUP *pmarkup = (NMLVEMPTYMARKUP *)pnmhdr;
        _tcscpy(pmarkup->szMarkup, TEXT("This is an empty ListView."));
        return TRUE;
      }
      return FORWARD_WM_NOTIFY(hWnd, idFrom, pnmhdr, DefWindowProc);
    }
  default:
    return FORWARD_WM_NOTIFY(hWnd, idFrom, pnmhdr, DefWindowProc);
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:23:06+00:00Added an answer on June 10, 2026 at 11:23 pm

    I can move

        listView1.SetWindowTheme("Explorer", null);
        listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
    

    into Form‘s Load event. This works, but I don’t know why.

    I can also override OnHandleCreated, and move those two lines into OnHandleCreated. I also don’t know why.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to add a class to a td-element using javascript with the internet
I try to add a class to a link with jquery <a rel=/Career/ href=/Career/></a>
I am trying to add empty header or footer on ListView to create a
When i try to add a <img> tag, IE8 automatically add a ' Empty
I try to add an addons system to my Windows.Net application using Reflection; but
i try to add facebook like button on my root domain that will like
I try to add the android coverflow in my own android projet when myt
I try to add dots between the page title and the page number in
I try to add Message.framework to my project frameworks directory. After that I compile
When I try to add struct in two-dimensional array cin>>array[1][items.stoka_ime]; in error list write

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.