CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2006
    Posts
    143

    Getting the handle of a control from EnumChildWindows()

    I have enumerated the child windows of an application. My idea is to get a pointer to the first child control of the window which is a tree control.( I have made sure it is a tree control by the Ctrl ID and the handle obtained is correct.)

    Now having obtained a handle to the tree control( hWndTreeCtrl) by EnumChildWindows, I want to get a pointer to the tree control like as follows:
    CTreeCtrl* pTreeCtrl = static_cast< CTreeCtrl* > ( CWnd::FromHandle( hWndTreeCtrl ));

    Though I can now access the methods of CTreeCtrl using pTreeCtrl , it is not working as expected. Say , for example, pTreeCtrl->GetCount() returns different values though the item count in tree is the same always.

    I also want to get the root item of the tree as follows and traverse the tree.
    HTREEITEM hRoot= pTreeCtrl->GetRootItem();

    hRoot = (HTREEITEM)::SendMessage(hWndTreeCtrl, TVM_GETNEXTITEM, TVGN_ROOT, 0);
    But the handle returned is null.

    But HTREEITEM hRoot= pTreeCtrl->GetRootItem() sems to work but when I get the text of a tree item null is returned. what could be wrong? Please help.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Getting the handle of a control from EnumChildWindows()

    Are you sure this control is a real standard tree control?
    Try to check its class name (GetClassName API): for the standard tree control the class name is SysTreeView32
    Victor Nijegorodov

  3. #3
    Join Date
    Jun 2006
    Posts
    143

    Re: Getting the handle of a control from EnumChildWindows()

    Yes..I checked using Spy++. The name returned is SysTreeView32.

    I have observed that when we are working with a tree view control created in a vc++ app, the FromHandle() function returns correct handle.

    When called from another app, it returns a temporary handle...

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Getting the handle of a control from EnumChildWindows()

    You can't access tree items like this when the tree control is from another process.

    If you need to manipulate tree items (from another process), look into using Active Accessibility.

  5. #5
    Join Date
    Jan 2008
    Posts
    178

    Re: Getting the handle of a control from EnumChildWindows()

    Quote Originally Posted by Arjay
    You can't access tree items like this when the tree control is from another process.
    If you need to manipulate tree items (from another process), look into using Active Accessibility.
    No, just use RPM

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Getting the handle of a control from EnumChildWindows()

    Fred, can you be any more cryptic?

  7. #7
    Join Date
    Jun 2006
    Posts
    143

    Re: Getting the handle of a control from EnumChildWindows()

    Thank you...Yes..I think I should look into Accessibility...

  8. #8
    Join Date
    Aug 2008
    Posts
    68

    Re: Getting the handle of a control from EnumChildWindows()

    RPM = ReadProcessMemory() API

    WPM = WriteProcessMemory() API.

    used to modify dynamic memory that which every program is made up with.. when loaded in RAM memory

  9. #9
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Getting the handle of a control from EnumChildWindows()

    Thanks. Those are definitly not the api's to use to solve this issue.

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

Featured