Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 List view controls and I need to send the VM_NOTIFY for both of them..
The program compile and run but I see some issues if I toggle between them.
One of them shows correctly and the other shows only the first column and the second shows few words most of the rows are empty.

C++
LRESULT NotifyHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    LV_DISPINFOW *pLvdi = (LV_DISPINFOW *)lParam;
    ABRINFO *pAbr = (ABRINFO *)(pLvdi->item.lParam);

    if (wParam != ID_LISTVIEW)
	return 0L;

    switch(pLvdi->hdr.code)
	{
	case LVN_GETDISPINFOW:
	   switch (pLvdi->item.iSubItem)
	      {
		case 0:
		pLvdi->item.pszText = pAbr->szSymbol;
		break;
		case 1:
		pLvdi->item.pszText = pAbr->szDescription;
		break;
		default:
		break;
	}
	break;
        default:
	break;
	}
    return 0L;
}


This is the second one:

C++
LRESULT NotifyHandlerXP(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    LV_DISPINFOW *pLvdi = (LV_DISPINFOW *)lParam;
    XPINFO *pXP = (XPINFO *)(pLvdi->item.lParam);

    if(wParam != ID_LISTVIEW)
        return 0L;

    switch(pLvdi->hdr.code)
    {
    case LVN_GETDISPINFOW:
        switch(pLvdi->item.iSubItem)
        {
        case 0:
            pLvdi->item.pszText = pXP->szCharLevel;
            break;
        case 1:
            pLvdi->item.pszText = pXP->szXpNedded;
            break;
        case 2:
            pLvdi->item.pszText = pXP->szXpNeddedNextLvl;
            break;
        default:
            break;
        }
        default:
            break;
    }
    return 0L;
}


How to handle in the MainWndProc?

C++
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
   static HWND hWndListView;

   switch(msg)
     {
    case WM_NOTIFY:
        {
          return (NotifyHandler(hWnd, msg, wp, lp));
          return (NotifyHandlerXP(hWnd, msg, wp, lp));
          break;
        }
     default:
        return DefWindowProcW(hWnd, msg, wp, lp);
     }
   return 0;
}


What I have tried:

I only thought of an IF statement.. I'm working on it right now.

HWND CreateListView(HWND hWndParent)
hWndListView = CreateListView(hWnd);

HWND CreateListViewXP(HWND hWndParentXP)
hWndListView = CreateListViewXP(hWnd);

These are the 2 handlers for the both List View controls.
Posted
Updated 6-Jul-20 3:51am
v3

The WM_NOTIFY message is sent from a control, i.e. one of the ListViews, to its parent Window. The parent then needs to decide what action to take. In the case where the ListView needs to be updated you need to call the relevant handler for that ListView, not for both of them. The information in the WM_NOTIFY message tells you which control raised the notify event.
 
Share this answer
 
Comments
M@gelearn 6-Jul-20 5:28am    
Well I'm not sure how to do that.. but sound correctly the way you mention..
Ok thank you for now .. I'll figure out something..
Richard MacCutchan 6-Jul-20 8:55am    
Look at the documentation for the WM_NOTIFY message. Once you have the Windows handle for the ListView it is a simple matter to call the correct handler.
I was thinking about to use just one NotifyHandler for the both list View controls..
 
Share this answer
 
I was thinking about to use just one NotifyHandler for the both list View controls..

I did use

C++
case WM_NOTIFY:
        {
            (NotifyHandlerXP(hWnd, msg, wp, lp));
            (NotifyHandler(hWnd, msg, wp, lp));
            break;
        }


Otherwise the list won't show up ever.

But I realise the second list view control has the second Column that doesn't show items like it should. SO i did add another column and I change the cases from case 1 and case 2

C++
case LVN_GETDISPINFOW:
        switch(pLvdi->item.iSubItem)
        {
        case 0:
            pLvdi->item.pszText = pXP->szCharLevel;
            break;
        case 1:
            pLvdi->item.pszText = pXP->szXpNedded;
            break;
        case 2:
            pLvdi->item.pszText = pXP->szXpNeddedNextLvl;
            break;
        default:
            break;

to:

C++
case LVN_GETDISPINFOW:
        switch(pLvdi->item.iSubItem)
        {
        case 0:
            pLvdi->item.pszText = pXP->szCharLevel;
            break;
        case 1:
            break;
        case 2:
            pLvdi->item.pszText = pXP->szXpNedded;
            break;
        case 3:
            pLvdi->item.pszText = pXP->szXpNeddedNextLvl;
            break;
        default:
            break;

to case 2 and 3..

Now the list shows up and the second coumn remain empty.
 
Share this answer
 
Comments
Richard MacCutchan 6-Jul-20 8:57am    
Yes, because you are ignoring the second column.
M@gelearn 6-Jul-20 10:21am    
Yes Richard now I ignored cause I saw it never shows what it's suppose to show.. So in example I wrote up I Ignored totally and I passed over.. I just substitute the column and the second becomes 3rd and the third becomes the 4th..
I ignored cause I did want to.. I did it to see if the text shows over the next 3rd and 4th columns.. and yes it did showed But this was't the problem .. Like I mentioned I was having the same ID and the same NUM_ITEMLEN for the both of the controls which is not that great .. and change them to have different IDs.. And now works just fine..
Thank you however.. seems you show up every time when a problem is on the road.. :)


Ohh and by the way Sorry for the last post and the 1 Point offered.. I was really pissed off by other things and the code bugged .. I.. I think I show some apologies..
Hope you didn't get upset.. My bad as always .. Since I'm a beginner I ask left and right and I expect every time concrete answers.. but I know every of us is working and doesn't have time for every problem is on the forum.. So once again my apologies..
Ok I think I got it. Let's say I just let the case notify like this:

C++
case WM_NOTIFY:
        {
            (NotifyHandlerXP(hWnd, msg, wp, lp));
            (NotifyHandler(hWnd, msg, wp, lp));
            break;
        }


Then I changed the the ID_LISTVIEWXP and the NUM_ITEMLENXP for the second listview control in the header and now seems that the both list view are woking just fine..

I think this wasn't work because I had the same ID_LISTVIEW and the same NUM_ITEMLEN for both controls.
 
Share this answer
 
v2
Comments
Richard MacCutchan 6-Jul-20 10:44am    
That is still wrong. You must check which control the WM_NOTIFY message applies to, and send the information only to that control. You need to understand Windows message handling in more detail, see About Messages and Message Queues - Win32 apps | Microsoft Docs[^].
M@gelearn 6-Jul-20 11:01am    
Yes Richard I'm Reading about right now here:
https://docs.microsoft.com/en-us/windows/win32/controls/wm-notify

I know that my code it works and I'm actually aware that my problem with windows message handling is continuing.. I work hard to understand them since I begin to learn solo. No Teacher no nothing just from scratch .. Is not recommended, but I'm sure if I arrived here I can get higher, cause I like it. That's why I insist sometimes to the answers, and I ask for more info about it, because I'm not familiar with everything, so I wanna ask to be patient with me.. Thant's all.
Richard MacCutchan 6-Jul-20 13:00pm    
Nothing wrong with learning solo, but you still need to make use of the correct information. Here is a link to a set of tutorials that may help you: theForger's Win32 API Tutorial[^].
M@gelearn 7-Jul-20 0:50am    
Hehe..Already know this, that is what I was start with.. Ty very much..
M@gelearn 7-Jul-20 0:50am    
Hehe..Already know this, that is what I was start with.. Ty very much..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900