Tree-View problem

Hi all, I'm new here.

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.
Last edited on
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?
See if this helps
http://msdn.microsoft.com/en-us/library/windows/desktop/bb773544(v=vs.85).aspx

Anyway it looks like your logic is flawed.
I'm writing this from my phone and it's driving me nuts
so I'll edit it later from my pc.

(and a little less whineing in future -thanks)
Last edited on
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)

Example 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
    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
                    else if(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;
        }



Example 2;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    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;
        }
    
Sorry this don't work for me. Maybe this work only on UNICODE characters?
Sorry this don't work for me. Maybe this work only on UNICODE characters?
is not really a good enough reply.

Im sure my use of the TVN messages and action code is correct and the examples are correct.

So what did not work for you??

Maybe OP does not include <tchar.h> header, as few tutorials uses it .
Topic archived. No new replies allowed.