Solved

virtual ListView in a dialog

Posted on 1998-04-02
8
557 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Choosing a Backup Solution 4 85
Solaris SUN OS 4.1.3 cloning 6 97
How to configure a 3 month and a 2 years backup schedule on TSM 6.4 4 96
Authentication of Web Services 3 110
How to fix error ""Failed to validate the vCentre certificate. Either install or verify the certificate by using the vSphere Data Protection Configuration utility" when you are trying to connect to VDP instance from Vcenter.
By default, Carbonite Server Backup manages your encryption key for you using Advanced Encryption Standard (AES) 128-bit encryption. If you choose to manage your private encryption key, your backups will be encrypted using AES 256-bit encryption.
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

740 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