如何实现双击外部程序中的Treeview 节点??我已经成功实现遍历和查找到目标节点,并选中该节点,但无法双击它。
发送sendmessage(treeviewHWD,WM_LBUTTONDBLCLK,MK_LBUTTON,0); 是无效的。请大侠们给帮帮忙!

解决方案 »

  1.   

    1、先取得坐标 SendMessage(tv.Handle, TVM_GETITEMRECT, True, rc) ,再将rc.top,rc.Left坐标经由 ClientToScreen转为屏幕坐标;2、根据取得坐标
    mouse_event (MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, rc.left, rc.top, 0, 0 ) 
    mouse_event (MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, rc.left, rc.top, 0, 0 ) 
      

  2.   


    发送的时候要带坐标吧。
    lParam 
    The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area. 
    The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area. 
      

  3.   

    现在主要就是不懂怎么取外部程序内treeview 节点的区域坐标。我在网上找到一个VC的。但是我对VC不太熟悉。有人能帮忙翻译成DELPHI的吗?
    代码如下:HTREEITEM Child61 = TreeView_GetChild(htree, Child6); //(火拼麻将)
    BOOL bSel=(BOOL)::SendMessage(htree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)Child61);
        TreeView_EnsureVisible(htree, Child61);
        
        DWORD  pid = 0;  
        GetWindowThreadProcessId(htree,&pid);      
        
        HANDLE  hProcess=OpenProcess(PROCESS_ALL_ACCESS,true,pid);  
        
        RECT *prect=(RECT*)VirtualAllocEx(hProcess, NULL, sizeof(RECT), MEM_COMMIT, PAGE_READWRITE);
        RECT rect={0};
        unsigned long n=0;
        
        *(HTREEITEM*)&rect = Child61;
        WriteProcessMemory(hProcess, prect, &rect, sizeof(RECT), NULL);
        ::SendMessage(htree, TVM_GETITEMRECT, (WPARAM)FALSE, (LPARAM)prect);
        ReadProcessMemory(hProcess,prect,&rect,sizeof(RECT),&n);  
        
        POINT pt={0};
        pt.x = rect.left + (rect.right-rect.left)/2;
        pt.y = rect.top + (rect.bottom-rect.top)/2;
        
        ::ClientToScreen(htree,&pt);    //鼠标事件
        SetCursorPos(pt.x, pt.y);
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0,0);
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0,0);
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0,0);
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0,0);    //释放内存
        CloseHandle(hProcess);
        VirtualFreeEx(hProcess, prect, 0, MEM_RELEASE);