PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Using SendMessage to Manipulate a Tree Control-VBForums
Results 1 to 4 of 4

Thread: Using SendMessage to Manipulate a Tree Control

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 1999
    Location
    Liverpool, UK
    Posts
    64

    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

  2. #2
    Member
    Join Date
    Mar 2004
    Location
    Texas
    Posts
    53

    Talking

    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:
    1. 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:
    1. desktop_hwnd = FindWindow("#32769",VBNullString)
    2. 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:
    1. 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:
    1. 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:
    1. 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!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 1999
    Location
    Liverpool, UK
    Posts
    64
    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:
    1. Dim wintext As String
    2. Dim slength As Long
    3. Dim retval As Long
    4.  
    5. slength = SendMessage(hWnd, WM_GETTEXTLENGTH, CLng(0), CLng(0)) + 1
    6. wintext = Space(slength)
    7. retval = SendMessage(hWnd, WM_GETTEXT, slength, wintext)
    8. wintext = Left(wintext, retval)
    9. 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:
    1. const TV_FIRST           = &H1100&
    2. const TVM_GETITEM        = (TV_FIRST + 12)
    3. const TVM_SETITEM        = (TV_FIRST + 13)

  4. #4
    Member
    Join Date
    Mar 2004
    Location
    Texas
    Posts
    53
    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
  •  



Featured


Click Here to Expand Forum to Full Width