HWND hWnd=::FindWindow("#32770", "WINNAME1"); //另一进程的窗口标题是WINNAME1
hWnd=::FindWindowEx(hWnd, NULL, "SysListView32", NULL);
if (hWnd==NULL) return; CListCtrl *pListCtrl=(CListCtrl*)CWnd::FromHandle(hWnd);
pListCtrl->InsertColumn(0, "aa", LVCFMT_LEFT, 200);
pListCtrl->InsertColumn(1, "bb", LVCFMT_LEFT, 200);
pListCtrl->InsertColumn(2, "cc", LVCFMT_LEFT, 200); pListCtrl->InsertItem(0, "11");
pListCtrl->SetItemText(0, 1, "22");
pListCtrl->SetItemText(0, 1, "33"); 我是想向另一进程窗口的CListCtrl中插入列及行,结果列标题内容全部为空,而且行没有插入成功。为什么?我该如何解决?谢谢,分不够可以再加:)
hWnd=::FindWindowEx(hWnd, NULL, "SysListView32", NULL);
if (hWnd==NULL) return; CListCtrl *pListCtrl=(CListCtrl*)CWnd::FromHandle(hWnd);
pListCtrl->InsertColumn(0, "aa", LVCFMT_LEFT, 200);
pListCtrl->InsertColumn(1, "bb", LVCFMT_LEFT, 200);
pListCtrl->InsertColumn(2, "cc", LVCFMT_LEFT, 200); pListCtrl->InsertItem(0, "11");
pListCtrl->SetItemText(0, 1, "22");
pListCtrl->SetItemText(0, 1, "33"); 我是想向另一进程窗口的CListCtrl中插入列及行,结果列标题内容全部为空,而且行没有插入成功。为什么?我该如何解决?谢谢,分不够可以再加:)
你送消息过去的字符串都是位于你的进程内的.所以于其它的进程来说,你传过去的指针是无效的,这将会导致插入失败.如果一定要操作这个进程外的控件,建议:1) 使用全局钩子挂到相应的进程内.
2) 使用 CreateRemoteThread 来创建一个远程线程将代码插入到该进程. 在些线程内执行操作
GetWindowThreadProcessId(hWnd, &dwTrayProcessID);
HANDLE hTrayProc = OpenProcess(PROCESS_ALL_ACCESS, 0, dwTrayProcessID);
LPVOID lpData = VirtualAllocEx(hTrayProc, NULL, 5, MEM_COMMIT, PAGE_READWRITE);
WriteProcessMemory(hTrayProc, lpData, "文件", 5, &nByte); pListCtrl->InsertColumn(0, (char*)lpData, LVCFMT_LEFT, 200); VirtualFreeEx(hTrayProc, lpData, NULL, MEM_RELEASE);
CloseHandle(hTrayProc);另一方面,有没有简单些的方法?
你要把你操作list的代码写到远进程里去。
http://www.vckbase.com/document/viewdoc/?id=1223
http://zdnet.com.cn/common/printfriendly/printfriendly.htm?AT=39142983-2000081534t-20000560c这个例子中,一旦我对远程进程的窗口进程操作,就会非法操作:比如在回调函数中执行:AfxGetMainWnd()->SetWindowText("aaa");有些晕,哪位大侠能进一步帮我看一下呢?