Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

virtual ListView in a dialog

Posted on 1998-04-02
8
Medium Priority
?
562 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
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…
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…

636 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