Solved

virtual ListView in a dialog

Posted on 1998-04-02
8
554 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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
 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Microservice architecture adoption brings many advantages, but can add intricacy. Selecting the right orchestration tool is most important for business specific needs.
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

770 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