First I really get confused with the WM_NOTIFY message and the variables structures which inputs("A pointer to an NMHDR structure that contains the notification code and additional information. For some notification messages, this parameter points to a larger structure that has the NMHDR structure as its first member."). I actually want to catch when the user changes an item in the Tree-View. I use for this the NM_CLICK message but I found this isn't effective for changing item selection with the keyboard. That's way I write this but I doesn't working:
1 2 3 4 5 6 7 8 9
case WM_NOTIFY:
{
if(((LPNMHDR)lParam)->idFrom==IDC_TREE1||((LPNMTREEVIEW)lParam)->hdr.idFrom==IDC_TREE1)
if(((LPNMTREEVIEW)lParam)->hdr.code==TVN_SELCHANGING||((LPNMHDR)lParam)->code==NM_CLICK)
{
//Do my code
}
}
break;
I will be happy if you help me an explain me why this code doesn't work.
Any answers? Did this community don't know anything about the Tree-View notifications just like the web? Or if this is old is there something like new, free from bugs Tree-View like control?
No I come just from this. I'll really not more using Win32 but for now I need this for my app version which I currently releasing. Anybody help me? (what "whinEing"?)
OK I created a test project which created just one treeview.
(As I only created just one control which was the treeview I did not check whichcontrol the WM_NOTIFY message is coming from - but you should add the check to your code if needed)
case WM_NOTIFY: //we will trap this to do stuff with the treview
{
LPNMHDR pnmh = (LPNMHDR)lParam;
switch (pnmh->code)
{
case TVN_SELCHANGED:
{
LPNMTREEVIEW pnmtv = (LPNMTREEVIEW) lParam; //
//Test 1 - Check if selection was changed by keyboard
if (pnmtv->action ==TVC_BYKEYBOARD)
{
SetWindowText(hWnd, _T("Selection changed by keystroke"));
}
//test 2 - if not selected by keyboard then check for mouse selection
elseif(pnmtv->action ==TVC_BYMOUSE )
{
SetWindowText(hWnd, _T("Selection changed by mouse"));
}
else //if neither of the above
{
SetWindowText(hWnd, _T("Selection changed by Act Of GOD"));
}
break;
}
default:
break;
}
return 0;
}
case WM_NOTIFY: //we will trap this to do stuff with the treview
{
LPNMHDR pnmh = (LPNMHDR)lParam;
switch (pnmh->code)
{
case TVN_SELCHANGED:
{
LPNMTREEVIEW pnmtv = (LPNMTREEVIEW) lParam; //
//Test 1 - Check if selection was changed by keyboard or mouse
if (pnmtv->action ==TVC_BYKEYBOARD || pnmtv->action ==TVC_BYMOUSE )
{
SetWindowText(hWnd, _T("Selection changed by keystroke or mouse"));
}
else //if not by keyboard or mouse
{
SetWindowText(hWnd, _T("Selection changed by Act Of GOD"));
}
break;
}
default:
break;
}
return 0;
}