Results 1 to 22 of 22

Thread: Treeview api!!!

  1. #1

    Thread Starter
    Member FaRd0wN's Avatar
    Join Date
    Mar 2002
    Posts
    32

    Unhappy Treeview api!!!

    argh!!!

    Okay,

    a. does anyone know how to test if a treeview item is already bolded?

    b. does anyone know how to test if a treeview item is already italic?

    Yes i have been here:http://www.mvps.org/vbnet/

    they tell how to bold but i can't decern how to test if its bolded. no italics info.

    thanks.

  2. #2
    Addicted Member darrenl's Avatar
    Join Date
    Jul 2000
    Location
    Portsmouth, UK
    Posts
    148
    Strikes me that the answer to the Bold question is in the code provided on the VBNet site.

    the procedure Command3_Click is geting the selected items bold state and forcing the state to be bold once it has got it then sending a message back to the tree view control to set the new state.

    Look at the code, all you need to do is to get the Bold state and ignore the setting and sending parts.

    As far as I know there is no TVIS_ITALIC state for a treeview item.
    Dazzer

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. 'how about
    2. If TreeView1.Font.Bold = True Then
    3. 'or
    4. If TreeView1.Font.Italic = True Then

  4. #4

    Thread Starter
    Member FaRd0wN's Avatar
    Join Date
    Mar 2002
    Posts
    32
    hack, yes that would work but the treeview i am dealing with is not on my form/application.

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Then, you have no way of knowing what the name of the treeview control is, so, I don't know how you would be able to check its current state.

    What is the issue here? Perhaps another way to do whatever you need to do is possible. (PS: The fact the treeview is not yours would have been handy to know up front.)

  6. #6
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    I'd check into some TVM_* messages.
    Please rate my post.

  7. #7
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by Hack
    Then, you have no way of knowing what the name of the treeview control is, so, I don't know how you would be able to check its current state.
    Heard of the FindWindow and FindWindowEx API?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    Hobo,

    steady on mate.....

    Hack,


    Maybe he could use something like this in a FIndWindowEx Loop until he returns the treeview class name of a window (gets a bit dodgy if you have multiple treeviews on the form)

    Code:
    Option Explicit
    Private Declare Function apiGetClassName Lib "user32" Alias "GetClassNameA" _
       (ByVal hWnd As Long, ByVal lpClassName As String, ByVal _
       nMaxCount As Long) As Long
    
    
    Private Sub cmdGetClass_Click()
    'DO THIS UNTIL YOU FIND THE TREEVIEW CLASS.....
    Debug.Print GetWindowClass(RESULTOFFINDWINDOWEX.hWnd)
    End Sub
    
    Function GetWindowClass(hWnd As Long) As String
    
       '*************************************************************
       ' PURPOSE: Retrieve the class of the passed window handle.
       ' ARGUMENTS:
       '    hWnd: The window handle whose class is to be retrieved.
       ' RETURN:
       '    The window class name.
       '*************************************************************
       Dim Buff As String
       Dim BuffSize As Integer
       Buff = String$(255, " ")
       BuffSize = apiGetClassName(hWnd, Buff, 255)
       GetWindowClass = Left$(Buff, BuffSize)
    
    End Function
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Originally posted by TheHobo
    Heard of the FindWindow and FindWindowEx API?
    DOH!

    Sigh...sometimes I think I should have followed my grandfather's advice and become a plummer. Please excuse me while I retire to the men's room to wipe the egg off my face.

  10. #10
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    These are the messages I found covering treeview. Some are notification messages.

    VB Code:
    1. Private Const TVS_NOTOOLTIPS = &H80
    2. Private Const TVS_RTLREADING = &H40
    3. Private Const TVS_SHOWSELALWAYS = &H20
    4. Private Const TVS_SINGLEEXPAND = &H400
    5. Private Const TVS_TRACKSELECT = &H200

    and these projects on mvps.org.

    http://www.mvps.org/access/api/api0064.htm
    http://www.mvps.org/vbnet/index.html.../tveffects.htm

    [edited to truncate]
    Last edited by Shawn N; Mar 7th, 2002 at 05:08 PM.
    Please rate my post.

  11. #11
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by Shawn N
    These are the messages I found covering treeview. Some are notification messages.

    and these projects on mvps.org.

    http://www.mvps.org/access/api/api0064.htm
    http://www.mvps.org/vbnet/index.html.../tveffects.htm
    Hi Shawn. Quick question: can you read? If so, why don't you give this thread another shot, paying particular attention to what the questioner wants. After you do, let me know if you still think what you posted and those examples will work for him.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  12. #12
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Couldn't find a way to italicize a node so all I could test is bold. Oh and Hobo I got almost all of this coding from the 2nd link I posted. Pretty good for an illiterate programmer eh?
    Attached Files Attached Files
    Please rate my post.

  13. #13
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by Shawn N
    Couldn't find a way to italicize a node so all I could test is bold. Oh and Hobo I got almost all of this coding from the 2nd link I posted. Pretty good for an illiterate programmer eh?
    That's really good, Shawn. I commend you on a great program.

    But one more time, just to be safe, I want you to re-read the thread one more time, and pay particular attention to this post:

    Originally posted by FaRd0wN
    hack, yes that would work but the treeview i am dealing with is not on my form/application.
    If you still don't get my drift: the treeview that he wants to check for boldness is not on his form and is not in his application.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  14. #14
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    That's why I used the FindWindow & FindWindowEx API rather than using the treeview's "hWnd" property. Actually, I'll make some changes and see if it still works. Gimme 10 minutes...
    Please rate my post.

  15. #15
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I'm guessing you'd have to start with the first node (using the constants) then cycle through each one until you find the text you're looking for, then apply your code?

    I'm still stuck on trying to get the hwnd of the treeview (using AIM as a test).

    The definition of the FindWindow API:

    The FindWindow function retrieves the handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows.
    I'm not sure if you can search other applications by caption.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  16. #16
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    What a load of Window's CRAP. I compiled the project I posted to have a treeview control to work with. Then in another project, I used the same coding against the exe's treeview and whaddayaknow it gives me a big fat ZERO. All handles come out right (no zero handles) so I know that's not the problem.

    There's no reason for this since in the first project I used all API so there's no way for VB to give out any leniency.
    Please rate my post.

  17. #17
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Originally posted by The Hobo
    I'm guessing you'd have to start with the first node (using the constants) then cycle through each one until you find the text you're looking for, then apply your code?

    I'm still stuck on trying to get the hwnd of the treeview (using AIM as a test).

    The definition of the FindWindow API:



    I'm not sure if you can search other applications by caption.
    FindWindow will find a window using the classname either/and/or the title. Just pass a "vbNullString" in the parameter you're not using.

    The line "nodSelected = SendMessage(tvwHWND, TVM_GETNEXTITEM, TVGN_CARET, 0)" sets nodSelected to the handle of the selected node. Then setting .hItem to nodSelected Windows knows what node to get info from.
    Please rate my post.

  18. #18

    Thread Starter
    Member FaRd0wN's Avatar
    Join Date
    Mar 2002
    Posts
    32
    yes. i have run into this same problem. when i try to grab any info about a node in the treeview(not in my application), sendmessage returns junk. doesnt make much sense. i dont see why the api calls would work locally but not translate to work with another application. need help!!!

  19. #19
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    FaRd0wN,

    Zip up your code and post it please.
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  20. #20
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    This code will retrieve all the node handles for a "foreign" treeview....it uses the macros and definitions from Brad Martinez's site.... www.mvps.org/btmtz

    to make it work set up a seperate project with a Treeview (Treeview1) on a form (Form1) then run the project

    Then in a seperate project use the code below, and step thru it.


    Code:
    Dim cNodes As New Collection
    Dim thWnd&, thWnd1&, hNode&
    thWnd = FindWindowEx(0&, 0&, "ThunderFormDC", "Form1")
    thWnd1 = FindWindowEx(thWnd, 0&, "TreeView20WndClass", vbNullString)
    
    hNode = TreeView_GetRoot(thWnd1)
    If hNode Then cNodes.Add hNode
    Do While hNode
      hNode = TreeView_GetNextVisible(thWnd1, hNode)
      If hNode Then cNodes.Add hNode
    Loop
    MsgBox "Done" & " " & cNodes.Count


    and as for the italics.....i'm working on it.
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  21. #21

    Thread Starter
    Member FaRd0wN's Avatar
    Join Date
    Mar 2002
    Posts
    32
    if you want to retrieve the contents of a treeview you can always just run listbox api on it and it will retreive the text in order. but, with that code can you test the state of each item? ie, bolded. :P
    vBchode enabled

  22. #22
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    Listbox API - on a treeview....that'll be a first.
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width