How to get the contents of TreeView controls for other processes

xiaoxiao2021-03-06  19

Extern "C" long exportitem (long thwnd, char * filestr) {tvitem TVi, * _tvi; char * _item; char item [256]; unsigned long pid; handle process; long rett = ((ctreectrl *) CWnd :: fromHandle ((hwnd) ") -> getrootItem (); if (re)) {/ * getWindowThreadProcessID Description Gets a process and thread identifier that is associated with the specified window returns a value of LONG, the thread with the window Identifier Parameter Table Parameter Type and Description LPDWProcessID Long, specify a variable, used to load an identifier hWnd long, specify window handle * / getWindowThreadProcessID ((hwnd), & PID); // with all permissions open the process process = OpenProcess (PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_QUERY_INFORMATION, FALSE, pid); // to _lvi, _item allocation process level virtual memory space _tvi = (TVITEM *) VirtualAllocEx (process, NULL, sizeof (TVITEM), MEM_COMMIT, PAGE_READWRITE); _item = (char *) VirtualAllocEx (process, NULL, 256, MEM_COMMIT, PAGE_READWRITE); tvi.cchTextMax = 256; tvi.hItem = (HTREEITEM) ret; tvi.mask = TVIF_TEXT; tvi.pszText = _item ; // Write the _LVI write process WriteProcessMemory (Process, _TVI, & TVI, SIZEOF (TVItem), NULL); // Send a message Get data :: SendMessage ((hwnd) Thwnd, TVM_GetItem, 0, (lParam) _tvi); // read data readprocessMemory from the process (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 = ((ctreeCtrl *) CWnd :: fromHandle (THWND)) -> GetNextSiblingItem (htreeItem) Next); if (re) {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.cchTextMax = 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 placed in the DLL in VB, VC, but if the machine is not installed, the VB is called to require MFC42D.DLL, MSVCRTD.DLL.

转载请注明原文地址:https://www.9cbs.com/read-64056.html

New Post(0)