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.
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.)
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.
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
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.
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.
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?
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.
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...
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.
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.
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.
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!!!
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
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