|
-
Mar 19th, 2004, 04:39 AM
#1
Thread Starter
Lively Member
Using SendMessage to Manipulate a Tree Control
Is it possible to use 'SendMessage' to do the following tasks in an application that is not under my control...
[1] Look for a treeview control in a given window.
[2] Look for an item in the treeview control identified in task 1.
[3] Select the item in the treeview as identified in task 2.
So, for example, I want my VB app to first locate the Outlook express window. Next, see if there is a treeview control present on the window. Then if its found, select the item 'Outlook Express\Local Folders\Inbox' in the tree.
Any takers...?
Thanks
-
Mar 20th, 2004, 12:37 AM
#2
Member
Hey I know exactly what you need to do.
1st - Find the desired handle of the window you want to use
- If there is only 1 instance with the same class name, you can use
VB Code:
program_hwnd = FindWindow(Class_Name_In_Quotes, VBNullString / Window_Caption_In_Quotes)
Where program_hwnd is decalred as a long
- If there are more than 1 instances with the same class name, but different captions, you must use FindWindowEx, but first you need to get the desktop handle:
VB Code:
desktop_hwnd = FindWindow("#32769",VBNullString)
program_hwnd = FindWindowEx(desktop_hwnd,0&,Class_Name_In_Quotes,Window_Caption_In_Quotes)
NOTE: in either case if all you know is the caption, and thats the only program with that caption, then you may use VBNullString instead of the class name, so
VB Code:
program_hwnd = FindWindow(VBNULLSTRING,WIndow_Caption_In_Quotes)
would work
2nd - Find the control handle you wish to retrieve from, apply the same concept as above to this process. So if the program has only 1 tree control, use
VB Code:
Control_Hwnd = FindWindowEx(program_hwnd,0&,"TreeView",VBNullString)
. Where the Contol_HWND represents a long. If there are more than one, ask me what to do, so I'm not just adding extra info thats not needed.
3rd - Call SendMessage to select the desired item from the control handle. Now im not too familar with the TreeView, but you could try this, I'm not sure if itll work, but call
VB Code:
SendMessage(Control_Hwnd,WM_GETTEXT,INDEX,0)
where INDEX is the item index you want to retrieve. WM_GETTEXT is a generic get text msg so it may not work, I know a list view has its own define way, so the tree view may too, but you should be able to find it out somewhere, the hard parts done!
Well I hope this works, tell me what you think or if you haveb any questions. The thing I love about window api is that its cross-language. I'm a C++ programmer, concentrating on MFC, yet I can do VB jsut as well, since of the similarities on API. Goodluck!
-
Mar 22nd, 2004, 03:40 AM
#3
Thread Starter
Lively Member
Thanks for the reply...
Didn't quite work though. I did a bit of digging around last week and came up with something similar to what you suggested...
VB Code:
Dim wintext As String
Dim slength As Long
Dim retval As Long
slength = SendMessage(hWnd, WM_GETTEXTLENGTH, CLng(0), CLng(0)) + 1
wintext = Space(slength)
retval = SendMessage(hWnd, WM_GETTEXT, slength, wintext)
wintext = Left(wintext, retval)
Print "result = "; wintext
By changing the value of hWnd to the handle of a tree, or window or whatever, this will return the 'caption' from that control/window, but it doesn't return the selected item. I'm sure this is almost there, its just a case of finding the message which returns the selected tree item - just need to find it...
This might be what I need though, if I can get it to work...
VB Code:
const TV_FIRST = &H1100&
const TVM_GETITEM = (TV_FIRST + 12)
const TVM_SETITEM = (TV_FIRST + 13)
-
Mar 22nd, 2004, 09:26 PM
#4
Member
Ahhh yea, silly me! I forgot how tree views and list views have their own commands to get text, etc. Gald you got it, ill make note of it.
Good programming site:
*http://www.planet-source-code.com
Our CS Clan Page:
*http://h2p.inter-gamer.com/index.html
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|