very sorry for the double post, but I have another situation related to this, and really don't want to start a new thread.
I got it working, but am now stumped with another very tedious problem. it is not working how I would like it to. here is how I am handling WM_NOTIFY:
Code:
case WM_NOTIFY:
lpnmhdr = (LPNMHDR)lParam;
hMenu = CreatePopupMenu();
if(lpnmhdr->hwndFrom == hwndList) {
if(lpnmhdr->code == NM_RCLICK) {
iSelect = ListView_GetSelectionMark(hwndList);
if(iSelect != -1) {
AppendMenu(hMenu, MF_GRAYED | MF_STRING, IDM_ADD, "Add");
AppendMenu(hMenu, MF_STRING, IDM_REMOVE, "Remove");
GetCursorPos(&pt);
TrackPopupMenu(hMenu, TPM_LEFTALIGN, pt.x, pt.y, 0, hwndDlg, 0);
}
else {
AppendMenu(hMenu, MF_STRING, IDM_ADD, "Add");
AppendMenu(hMenu, MF_GRAYED | MF_STRING, IDM_REMOVE, "Remove");
GetCursorPos(&pt);
TrackPopupMenu(hMenu, TPM_LEFTALIGN, pt.x, pt.y, 0, hwndDlg, 0);
}
}
}
DestroyMenu(hMenu);
break;
take a close look at the calls to AppendMenu. as you can see, here is how I am trying to make the menu look:
IF we have right clicked on a listview item = IDM_ADD is set MF_GRAYED (disabled)
ELSE we have not right clicked on a listview item = IDM_REMOVE is set MF_GRAYED
this makes sense, since if an item is selected (right clicked in this case), we should only want to be able to remove it from the list. and if we are right clicking open space, we don't want to remove it (that wouldn't make sense), but we want to be able to add an item instead.
so here is my problem. if I click open space it works fine, IDM_REMOVE is MF_GRAYED. but as soon as I click an item, the if(iSelect != -1) conditional no longer applies, IDM_ADD stays disabled, even if I click off the item. so you don't have to delve into msdn, I will tell you now that that conditional is testing if a listview item has been right clicked (ListView_GetSelectionMark returns -1 if no item is selected).
I have tried enabling the items like this:
Code:
if(iSelect != -1) {
AppendMenu(hMenu, MF_GRAYED | MF_STRING, IDM_ADD, "Add");
AppendMenu(hMenu, MF_ENABLED | MF_STRING, IDM_REMOVE, "Remove");
GetCursorPos(&pt);
TrackPopupMenu(hMenu, TPM_LEFTALIGN, pt.x, pt.y, 0, hwndDlg, 0);
break;
}
else {
AppendMenu(hMenu, MF_ENABLED | MF_STRING, IDM_ADD, "Add");
AppendMenu(hMenu, MF_GRAYED | MF_STRING, IDM_REMOVE, "Remove");
GetCursorPos(&pt);
TrackPopupMenu(hMenu, TPM_LEFTALIGN, pt.x, pt.y, 0, hwndDlg, 0);
break;
}
but it makes no difference (as expected ).
I am left puzzled here. I don't know what could possibly fix this problem, if anything. I have absolutely no clue why it doesn't work like it should . each right click is a WM_NOTIFY message, Windows should call my dialog callback with the NM_RCLICK message every time I right click, and the conditional testing if it is on an item should be evaluated each time.
would anyone please be able to shed some light here? if not, I will give up on this whole menu thing and stick to buttons (at least I can send messages to buttons), but that would be a last resort.
any help at all would be greatly appreciated, sorry for all the recent questions, this is my first serious GUI'd project with the Win32 API. thank you in advance.