如何获取别的进程的TreeView控件的内容

 我来答
低调的神回复
2016-08-10 · TA获得超过1.8万个赞
知道大有可为答主
回答量:9065
采纳率:90%
帮助的人:1745万
展开全部
概述:

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

说明
获取与指定窗口关联在一起的一个进程和线程标识符

返回值
Long,拥有窗口的线程的标识符
参数表
参数 类型及说明
lpdwProcessId Long,指定一个变量,用于装载拥有那个窗口的一个进程的标识符
hwnd Long,指定窗口句柄
*/
GetWindowThreadProcessId((HWND)Thwnd, &pid);
//用全部权限打开进程
process=OpenProcess(PROCESS_VM_OPERATION |PROCESS_VM_READ | PROCESS_VM_WRITE |PROCESS_QUERY_INFORMATION, FALSE, pid);
//给_lvi,_item分配进程级的虚拟内存空间
_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;
//把_lvi写入进程
WriteProcessMemory(process, _tvi, &tvi, sizeof(TVITEM), NULL);
//发消息得到数据
::SendMessage((HWND)Thwnd, TVM_GETITEM, 0 , (LPARAM)_tvi);
//从进程中读出数据
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.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;
}
以上的函数可以放到dll中在vb,vc里调用,但如果机器没装vc,在vb里调用需要MFC42D.DLL,MSVCRTD.DLL。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式