Listview selection change
Hi. I've got a listview and I want to detect when a selection change has occurred. Just to learn how I've not been using resource files for this project and have been using CreateWindowEx for creating all the windows. Here's how I create the listview:
Code:
hwndArray[conferenceList] =
CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, "",
LVS_SHOWSELALWAYS | WS_BORDER | WS_CHILD | WS_VISIBLE |
LVS_REPORT | LVS_EX_GRIDLINES | LVS_SINGLESEL | LBS_NOTIFY,
5, 5, 300, 280, hwnd, (HMENU)ID_CONFERENCELIST, g_hinst, NULL);
And here's how I have been trying to detect selection changes:
Code:
case WM_NOTIFY: {
NMHDR* nm = (NMHDR*) lParam;
if ( nm->idFrom == ID_CONFERENCELIST && nm->code == LVN_ITEMCHANGED ) {
LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
if ( (pnmv->uChanged & LVIF_STATE) &&
(pnmv->uNewState & LVIS_SELECTED) !=
(pnmv->uOldState & LVIS_SELECTED) ) {
if (pnmv->uNewState & LVIS_SELECTED)
MessageBox( 0,"Item has been selected",0,0);
else
MessageBox( 0,"Item has been deselected",0,0);
// Specific item: pnmv->iItem
}
}
}
or
Code:
case WM_COMMAND: {
// PROCESS SELECTION CHANGE MESSAGES
switch( LOWORD(wParam) ) {
case ID_CONFERENCELIST: {
switch ( HIWORD(wParam) ) {
case LBN_SELCHANGE: {
MessageBox(NULL, "Selection has changed", 0, 0 );
} break;
}
}
}
But none of those two methods work. Am I doing something stupid here? I've been using this and this as references and these methods appear to work for them...
'Not working' means the message boxes I've put up don't appear. It's also weird cause if I leave the WM_NOTIFY message in the code the main window that is created (not the conferenceList one) just flashes up and closes. No matter if I put in my style parameters or the ones from the aforementioned links. If notify is commented out the main window stays (feels like the ignore/get thing). The main window is created via.
Code:
hwnd = CreateWindowEx( 0, CLASS_NAME, "Conference catalog",
WS_SYSMENU, (screenWidth-570)/2, (screenHeight-315)/2, 570, 315,
0, 0, g_hinst, 0 );
Thanks.