积极答复者
给TREEVIEW发送消息失败

问题
-
HWND hWnd = ::FindWindow(_T("#32770"), _T("下载数据"));
if(hWnd)
{
HWND hButton = ::FindWindowEx(hWnd, NULL, NULL, _T("Tree1"));
if(hButton)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)hButton;
HTREEITEM hItem = (HTREEITEM)::SendMessage(hButton,TVM_GETNEXTITEM,TVGN_ROOT,0x0);
::SendMessage(hButton, TVM_SELECTITEM, TVGN_CARET, (LPARAM)&hItem);
答案
-
// 模拟向其它进程窗口中的CTreeCtrl控件中的选中的节点项发送右键点击消息
HWND hWnd = ::FindWindow(NULL, _T("XX"));
if(hWnd)
{
HWND hTreeView = ::FindWindowEx(hWnd, NULL, _T("SysTreeView32"), NULL);
if(hTreeView)
{
DWORD pid = 0;
::GetWindowThreadProcessId(hTreeView, &pid);
HANDLE hProcess = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if(hProcess)
{
HTREEITEM hItem = TreeView_GetSelection(hTreeView); // 得到当前CTreeCtrl控件selected HTREEITEMRECT rc = {0};
RECT* pRect = NULL;
pRect = (RECT*)::VirtualAllocEx(hProcess, NULL, sizeof(RECT), MEM_COMMIT, PAGE_READWRITE);
ASSERT(pRect);
DWORD dwWrite = 0;
DWORD dwRead = 0;
*(HTREEITEM*)&rc = hItem;
::WriteProcessMemory(hProcess, pRect, &rc, sizeof(RECT), &dwRead);
LRESULT lResult = ::SendMessage(hTreeView, TVM_GETITEMRECT, FALSE, (LPARAM)pRect);
BOOL bRet = ::ReadProcessMemory(hProcess, pRect, &rc, sizeof(RECT), &dwRead);POINT pt = {0};
pt.x = rc.left + (rc.right - rc.left) / 2;
pt.y = rc.top + (rc.bottom - rc.top) / 2;::PostMessage(hTreeView, WM_RBUTTONDOWN, MK_RBUTTON, MAKELPARAM(pt.x, pt.y)); // 向CTreeCtrl发送WM_RBUTTONDOWN右键点击消息
::VirtualFreeEx(hProcess, pRect, sizeof(RECT), MEM_RELEASE);
::CloseHandle(hProcess);
}
}
}
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.- 已标记为答案 Honny_yeyh 2011年5月16日 4:44
全部回复
-
// 模拟向其它进程窗口中的CTreeCtrl控件中的选中的节点项发送右键点击消息
HWND hWnd = ::FindWindow(NULL, _T("XX"));
if(hWnd)
{
HWND hTreeView = ::FindWindowEx(hWnd, NULL, _T("SysTreeView32"), NULL);
if(hTreeView)
{
DWORD pid = 0;
::GetWindowThreadProcessId(hTreeView, &pid);
HANDLE hProcess = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if(hProcess)
{
HTREEITEM hItem = TreeView_GetSelection(hTreeView); // 得到当前CTreeCtrl控件selected HTREEITEMRECT rc = {0};
RECT* pRect = NULL;
pRect = (RECT*)::VirtualAllocEx(hProcess, NULL, sizeof(RECT), MEM_COMMIT, PAGE_READWRITE);
ASSERT(pRect);
DWORD dwWrite = 0;
DWORD dwRead = 0;
*(HTREEITEM*)&rc = hItem;
::WriteProcessMemory(hProcess, pRect, &rc, sizeof(RECT), &dwRead);
LRESULT lResult = ::SendMessage(hTreeView, TVM_GETITEMRECT, FALSE, (LPARAM)pRect);
BOOL bRet = ::ReadProcessMemory(hProcess, pRect, &rc, sizeof(RECT), &dwRead);POINT pt = {0};
pt.x = rc.left + (rc.right - rc.left) / 2;
pt.y = rc.top + (rc.bottom - rc.top) / 2;::PostMessage(hTreeView, WM_RBUTTONDOWN, MK_RBUTTON, MAKELPARAM(pt.x, pt.y)); // 向CTreeCtrl发送WM_RBUTTONDOWN右键点击消息
::VirtualFreeEx(hProcess, pRect, sizeof(RECT), MEM_RELEASE);
::CloseHandle(hProcess);
}
}
}
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.- 已标记为答案 Honny_yeyh 2011年5月16日 4:44