Search code examples
cwinapidesktop-application

why Macro function,ListView_GetSelectedColumn(),doesn't work? it returns nothing


I am trying to get the selected column index of the ListView control, but the macro function ListView_GetSelectedColumn returns ZERO, no matter how I click.

a = ListView_GetSelectedCount(lpNmhdr->hwndFrom);
a = 999;
a = ListView_GetSelectedColumn(lpNmhdr->hwndFrom);
a = SendMessage(lpNmhdr->hwndFrom, LVM_GETSELECTEDCOLUMN, 0, 0);

screenshot showing a has value 0 at breakpoint in debugger


Solution

  • I can reproduce your issue. But I get it working after the following steps. This is my test result:

    enter image description here

    To use ListView_GetSelectedColumn, specify Comctl32.dll version 6 in the manifest. Create a manifest and enable your application to use visual styles.

    Refer to ListView_GetSelectedColumn macro and Enabling Visual Styles.

    Three steps you need to complete:

    1. Link to ComCtl32.lib and call InitCommonControls. (You have already done.)
    2. Add a file called YourApp.exe.manifest to your source tree that has the XML manifest format. For me as follows:

    enter image description here

    1. Add the manifest to your application's resource file as follows:

    enter image description here