Announcement

Collapse
No announcement yet.

Treeview - NM_CLICK

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Treeview - NM_CLICK

    Is there any way to determine which node the user has clicked on via the NM_CLICK message or does that have to be determined via the TVN_SELCHANGING message and the NM_TREEVIEW structure?
    Walt Decker

    #2
    Try the following:

    Code:
    Local pNMTV  As NM_TREEVIEW Ptr
    
    pNMTV = lParam
    
    hNode = @pNMTV.itemNew.hItem
    Paul Squires
    FireFly Visual Designer (for PowerBASIC Windows 10+)
    Version 3 now available.
    http://www.planetsquires.com

    Comment


      #3
      See this post for another way to determine which item has been clicked.
      User to user discussions about the PB/Win (formerly PB/DLL) product line. Discussion topics include PowerBASIC Forms, PowerGEN and PowerTree for Windows.
      Rgds, Dave

      Comment


        #4
        Perhaps I should explain what I'm trying to do.

        I have two treeviews. Each has the same number of root nodes with the same text, but they may have a different number of children items with different text. I want to enable one-click expansion and contraction of both treeview root nodes when a user clicks on either control. The synchronization of the treeviews is no problem but the one-click aspect is.

        Another aspect is suppressing the highlight when the user selects either a root node or child item. I have not found a way to do that.
        Walt Decker

        Comment


          #5
          Stupid Question

          from "commctrl.inc":

          Code:
              FUNCTION TreeView_Expand (BYVAL hWnd AS DWORD, BYVAL hitem AS LONG, _
                 BYVAL CODE AS DWORD) AS LONG
                  FUNCTION = SendMessage(hWnd, %TVM_EXPAND, CODE, hitem)
              END FUNCTION
          What is "CODE"?
          Walt Decker

          Comment


            #6
            From the WinAPI help file:

            Code:
            Action flag. This parameter can be one of the following values:
            
            Value	Meaning
            TVE_COLLAPSE	Collapses the list.
            TVE_COLLAPSERESET	Collapses the list and removes the child items. Note that TVE_COLLAPSE must also be specified.
            TVE_EXPAND	Expands the list.
            TVE_TOGGLE	Collapses the list if it is currently expanded or expands it if it is currently collapsed.
            Paul Squires
            FireFly Visual Designer (for PowerBASIC Windows 10+)
            Version 3 now available.
            http://www.planetsquires.com

            Comment


              #7
              this link http://www.powerbasic.com/support/pb...ight=walk+tree includes code to suppress the "flashing" of the cursor and also HITTEST code and a link to Steve Rossell's Treeview example which is very useful for many TreeView applications.

              Comment


                #8
                Paul:

                Thanks. I saw that but I kept thinking, "Sending TVM_EXPAND twice doesn't make sense." Guess there was a small mental block there.

                Dave:

                Thanks for the link. I've been following that thread. It may not be necessary to hook the NM_CLICK message.

                Chris:

                Thanks for the link.
                Walt Decker

                Comment


                  #9
                  >It may not be necessary to hook the NM_CLICK message

                  If your application is as described... you want to synchronize the selection and expand/collapse status of the two treeview contols.... it is NOT necessary at all.

                  Just pick up the WM_NOTIFY/TVN_SELCHANGED (or CHANGING) and the WM_NOTIFY/TVN_ITEMEXPANDED (or EXPANDING) notifications.

                  Now... for EXTRA credit... handle both controls with the same code WITHOUT ever interrogating which control actually generated the notification message.

                  (Yes, it can be done).

                  MCM
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                    #10
                    Michael:

                    I'm already doing that. I use two arrays containing the item handles of the root items. I interrogate the NM_TREEVIEW structure for the itemnew element handle then parse through the arrays until I find the element handle then expand/contract both. There probably is another method, but this is the one I'm using.

                    By the way, in the TV_ITEM structure there is a "state" element and a "statemask" element. If you know what the "state" element is, e.g. "TVIS_EXPANDED", why do you have to know which bits, from the "statemask" element, are valid?
                    Walt Decker

                    Comment


                      #11
                      By the way, in the TV_ITEM structure there is a "state" element and a "statemask" element. If you know what the "state" element is, e.g. "TVIS_EXPANDED", why do you have to know which bits, from the "statemask" element, are valid?
                      'State' is not an integer, it's a set of BIT flags. You need the statemask to tell which of those bit flags are valid.
                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                        #12
                        Michael:

                        Just pick up the WM_NOTIFY/TVN_SELCHANGED (or CHANGING) and the WM_NOTIFY/TVN_ITEMEXPANDED (or EXPANDING) notifications.
                        That's what I'm doing.


                        According to the WinAPI help the state element can be zero or one or more of the TVIS_ constants. If one ANDs the state element with the TVIS_ constants of interest, what good is the statemask? Seems kinda redundant to me.
                        Last edited by Walt Decker; 16 Dec 2008, 05:24 PM.
                        Walt Decker

                        Comment


                          #13
                          Must AND statemask vs State BEFORE testing vs TVIS_xxxx values.

                          ie if Statemask AND State AND TVIS_xxx = TVIS THEN it's true.
                          If state AND TVIS_xxxx then ... it's only true of Statemask AND TVIS_xxxx is true.

                          When retrieving state (TVM_GETITEMSTATE) you will only get valid bits for those bits which on ON in the transmitted statemask. Normally you'd set that mask to &hFFFF because you want all state bits, but that is not a requirement.
                          Michael Mattias
                          Tal Systems (retired)
                          Port Washington WI USA
                          [email protected]
                          http://www.talsystems.com

                          Comment


                            #14
                            Michael:

                            Thanks, that helps a heep.

                            One more question. In the NM_TREEVIEW structure there is a "action" element. Do you know what that can contain? Is it the same as the NMHDR.code element or different?
                            Walt Decker

                            Comment


                              #15
                              My SDK doc (which you could have looked up yourself at MSDN)
                              action
                              Notification-specific action flag.
                              Suggests you will be interested in this member based on which notification code you are processing.... in which case the doc for same should be with the doc for that notification code. (the TVN_xxxxx values). (Also available at MSDN).


                              MCM
                              Michael Mattias
                              Tal Systems (retired)
                              Port Washington WI USA
                              [email protected]
                              http://www.talsystems.com

                              Comment


                                #16
                                That description is also in the winapi help.

                                Yes, I could have looked it up on MSDN. Being on dial-up doing so takes forever. I've ordered the latest SDK but it hasn't arrived.

                                Thanks for your help and insight.
                                Walt Decker

                                Comment

                                Working...
                                X
                                😀
                                🥰
                                🤢
                                😎
                                😡
                                👍
                                👎