Solved

virtual ListView in a dialog

Posted on 1998-04-02
8
552 Views
Last Modified: 2013-12-04
I'm trying to write a small program consisting of a dialog with a virtual listview.
Problem is, the listview always seems to be empty.

I'm using MSVC 4.2 plus the latest comctl32 (headers, lib and DLL).

WinMain() inits the common controls and calls DialogBox().

The dialog template is taken from an .RC file and looks like:

    IDD_GROUPS DIALOG DISCARDABLE  0, 0, 259, 206
    STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION |
        WS_SYSMENU
    CAPTION "List"
    FONT 8, "MS Sans Serif"
    BEGIN
        CONTROL         "List1",IDC_LIST,"SysListView32",LVS_REPORT |
                        LVS_NOCOLUMNHEADER | LVS_NOSORTHEADER | WS_BORDER |
                        WS_TABSTOP | 0x1000,7,49,171,150
        DEFPUSHBUTTON   "Exit",IDCANCEL,186,185,66,14
    END

(I'm using the constant 0x1000 because the resource editor of MSVC 4.2 does not recognize the symbollic LVS_OWNERDATA).

The Dialog procedure looks like:

    BOOL CALLBACK DlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        static HWND hListBox = NULL;

        switch (msg)
        {
            case WM_INITDIALOG:
                hListBox = GetDlgItem(hwndDlg, IDC_LIST);
                ListView_SetItemCount(10);
                break;

            case WM_NOTIFY:
                switch (reinterpret_cast<NMHDR*>(lParam)->code)
                {
                    case LVN_GETDISPINFO:
                        NMLVDISPINFO* pInfo = reinterpret_cast<NMLVDISPINFO*>(lParam);

                        if (pInfo->item.mask & LVIF_TEXT)
                            lstrcpyn(pInfo->item.pszText, "this is a line", pInfo->item.cchTextMax);

                        break;
                }
                break;

            case WM_COMMAND:
                switch (LOWORD(wParam))
                {
                    case IDCANCEL:
                        EndDialog(hwndDlg, wParam);
                        return TRUE;
                }
   
        } // end of message switch

        return FALSE;   // Default dialog procedure will do further processing
    }

If I put a breakpoint on the line with lstrcpyn(), I see the correct data being copied.  However, the listview seems empty :-(

What am I doing wrong?
0
Comment
Question by:alexo
  • 5
  • 2
8 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1412506
If the list view control was created with the LVS_OWNERDATA style (a virtual list view), the ListView_SetItemCountEx macro should be used instead of ListView_SetItemCount.
0
 
LVL 11

Author Comment

by:alexo
ID: 1412507
I'll try it.
0
 
LVL 11

Author Comment

by:alexo
ID: 1412508
This is totally wrong.
The ListView_SetItemCount() and ListView_SetItemCountEx() macros are defined as:

    #if (_WIN32_IE >= 0x0300)
    // these flags only apply to LVS_OWNERDATA listviews in report or list mode
    #define LVSICF_NOINVALIDATEALL  0x00000001
    #define LVSICF_NOSCROLL         0x00000002
    #endif

    #define LVM_SETITEMCOUNT        (LVM_FIRST + 47)
    #define ListView_SetItemCount(hwndLV, cItems) \
      SNDMSG((hwndLV), LVM_SETITEMCOUNT, (WPARAM)cItems, 0)

    #if (_WIN32_IE >= 0x0300)
    #define ListView_SetItemCountEx(hwndLV, cItems, dwFlags) \
      SNDMSG((hwndLV), LVM_SETITEMCOUNT, (WPARAM)cItems, (LPARAM)dwFlags)
    #endif

The only difference is the dwFlags argument to the LVM_SETITEMCOUNT message.
Since I *want* to invalidate all items and change scroll position when the number of items changes, the dwFlags argument should be set to 0 and the ListView_SetItemCount() macro is perfectly adequate.
Just to be on the safe side, I tested ListView_SetItemCountEx().  No change.
0
 
LVL 11

Author Comment

by:alexo
ID: 1412509
The code in WM_INITDIALOG seems to be OK.  Planted some GetLastError() funcs and they all indicate success.
Also it doesn't make a difference if I return TRUE or FALSE in response to LVN_GETDISPINFO.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 11

Author Comment

by:alexo
ID: 1412510
InitCommonControlsEx() with ICC_LISTVIEW_CLASSES succeeds.
0
 
LVL 7

Accepted Solution

by:
linda101698 earned 100 total points
ID: 1412511
I'm posting the solution so it can be saved.

Linda Gardner
Customer Service @ Experts Exchange

Solution that worked for alexo:
InitCommonControlsEx() with ICC_LISTVIEW_CLASSES succeeds.
0
 
LVL 11

Author Comment

by:alexo
ID: 1412512
Linda, that is not the solution that worked.
I added a comment for that question saying what was the procedure.  However, it seems to be gone now.  What happened?  Was I censored?
If you can tell me what happened to my comment I'll give you an "A" :-)

For the record:
A listview in "report" mode needs to have at least one column.  The colums must be added explicitly because the listview defaults to 0 columns.
0
 
LVL 7

Expert Comment

by:linda101698
ID: 1412513
Thanks for posting the correct solution :-)

I don't know what happened to your post.  I thought the message I copied was what HAD worked for you.  I'm glad you came in and posted the correct solution.  The other could have messed someone up.

Linda
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
Create your own, high-performance VM backup appliance by installing NAKIVO Backup & Replication directly onto a Synology NAS!
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now