How to obtain the contents of the Treeview control of other processes

Source: Internet
Author: User

Extern "C" Long export _ stdcall getrootitem (long thwnd, char * filestr ){
Tvitem TVI, * _ TVI;
Char * _ item;
Char item [256];
Unsigned long PID;
Handle process;
Long ret = (long) (ctreectrl *) cwnd: fromhandle (hwnd) thwnd)-> getrootitem ();
If (RET ){
/*
Getwindowthreadprocessid
Description
Gets a process and thread identifier associated with a specified window.
Return Value
Long, the identifier of the thread that owns the window
Parameter table
Parameter type and description
Lpdwprocessid long: Specifies a variable to load the identifier of a process that owns the window.
Hwnd long, specify the window handle
*/
Getwindowthreadprocessid (hwnd) thwnd, & pid );
// Open the process with all Permissions
Process = OpenProcess (process_vm_operation | process_vm_read | process_vm_write | process_query_information, false, pid );
// Allocate process-level virtual memory space to _ LVI and _ item
_ TVI = (tvitem *) virtualallocex (process, null, sizeof (tvitem), mem_commit, page_readwrite );
_ Item = (char *) virtualallocex (process, null, 256, mem_commit, page_readwrite );
TVI. cchtexmax = 256;
TVI. hitem = (htreeitem) ret;
TVI. Mask = tvif_text;
TVI. psztext = _ item;
// Write _ LVI TO THE PROCESS
Writeprocessmemory (process, _ TVI, & TVI, sizeof (tvitem), null );
// Send the message to get the data
: Sendmessage (hwnd) thwnd, tvm_getitem, 0, (lparam) _ TVI );
// Read data from the process
Readprocessmemory (process, _ item, item, 256, null );
// Copy data
Memcpy (filestr, item, 256 );
// Free memory
Virtualfreeex (process, _ TVI, 0, mem_release );
Virtualfreeex (process, _ item, 0, mem_release );
}
Return ret;
}

Extern "C" Long export _ stdcall getnextitem (hwnd thwnd, long next, char * filestr ){
Tvitem TVI, * _ TVI;
Char item [256];
Char * _ item;
Unsigned long PID;
Handle process;
Long ret = (long) (ctreectrl *) cwnd: fromhandle (thwnd)-> getnextsiblingitem (htreeitem) Next );
If (RET ){
Getwindowthreadprocessid (thwnd, & pid );
Process = OpenProcess (process_vm_operation | process_vm_read | process_vm_write | process_query_information, false, pid );
_ TVI = (tvitem *) virtualallocex (process, null, sizeof (tvitem), mem_commit, page_readwrite );
_ Item = (char *) virtualallocex (process, null, 256, mem_commit, page_readwrite );
TVI. cchtexmax = 256;
TVI. hitem = (htreeitem) ret;
TVI. Mask = tvif_text;
TVI. psztext = _ item;
Writeprocessmemory (process, _ TVI, & TVI, sizeof (tvitem), null );
: Sendmessage (thwnd, tvm_getitem, 0, (lparam) _ TVI );
Readprocessmemory (process, _ item, item, 256, null );
Memcpy (filestr, item, 256 );
Virtualfreeex (process, _ TVI, 0, mem_release );
Virtualfreeex (process, _ item, 0, mem_release );

}
Return ret;
}
The above functions can be called in VB and Vc in the DLL. However, if the machine does not have VC installed, mfc42d. dll and msvcrtd. dll are required to be called in VB.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.