挖井

类库大魔王的挖井日记

挖一口属于自己的井


编程读取其它进程中TreeView的内容

void __fastcall TMainForm::GetTreeViewContent()
{
        //TODO: Add your source code here
    int nItemCount;
    int i;
    char chBuffer[256];
    DWORD dwProcessID;
    HANDLE hProcess;
    void * Pointer;
    SIZE_T nNumberOfBytesRead;
    TTVItem Item;
    HTREEITEM hTreeItem;

    GetWindowThreadProcessId(hWindow, &dwProcessID);
    hProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE,
                    false,
                    dwProcessID);
    Pointer = VirtualAllocEx(hProcess,
                            NULL,
                            4096,
                            MEM_RESERVE | MEM_COMMIT,
                            PAGE_READWRITE);
    try{
    nItemCount = TreeView_GetCount(hWindow);
    hTreeItem = TreeView_GetRoot(hWindow);
    for(i= 0 ; i < nItemCount ; ++i)
    {
       TreeView_Expand(hWindow, hTreeItem,  TVM_EXPAND);

       Item.mask = TVIF_TEXT;
       Item.cchTextMax = sizeof (chBuffer);
       Item.pszText = (LPSTR)((UINT *)Pointer + sizeof(TTVItem));
       Item.hItem = hTreeItem;

       WriteProcessMemory(hProcess,
                    Pointer,
                    &Item,
                    sizeof(TTVItem),
                    &nNumberOfBytesRead);
       SendMessage(hWindow, TVM_GETITEM, 0, (LPARAM)Pointer);
       ReadProcessMemory(hProcess,
                    (void *)((UINT *)Pointer + sizeof(TTVItem)),
                    chBuffer,
                    sizeof(chBuffer),
                    &nNumberOfBytesRead);
       ContentMemo->Lines->Add("┣"+GetLineString(TreeNodeGetLevel(hTreeItem))
                               +"  "+AnsiString(chBuffer));
       hTreeItem = TreeNodeGetNext(hTreeItem);
    }//for(i...
    }//try
    __finally
    {
      VirtualFreeEx(hProcess,
                    Pointer,
                    0,
                    MEM_RELEASE);
      CloseHandle(hProcess);
    }
}
//---------------------------------------------------------------------------
HTREEITEM __fastcall TMainForm::TreeNodeGetNext(HTREEITEM hTreeItem)
{
        //TODO: Add your source code here
    HTREEITEM hParentID;
    HTREEITEM hResult;

    hResult = NULL;
    if(hWindow != NULL && hTreeItem != NULL)
    {
      hResult = TreeView_GetChild(hWindow, hTreeItem);
      if(hResult == NULL)
      {
        hResult = TreeView_GetNextSibling(hWindow, hTreeItem);
      }
      hParentID = hTreeItem;
      while(hResult == NULL && hParentID != NULL)
      {
        hParentID = TreeView_GetParent(hWindow, hParentID);
        hResult = TreeView_GetNextSibling(hWindow, hParentID);
      }
    }
    return hResult;
}
//---------------------------------------------------------------------------
int __fastcall TMainForm::TreeNodeGetLevel(HTREEITEM hTreeItem)
{
        //TODO: Add your source code here
    HTREEITEM hParentID;
    int iRet;

    iRet = -1;
    if(hWindow != NULL && hTreeItem != NULL)
    {
      hParentID = hTreeItem;
      do
      {
        iRet ++;
        hParentID = TreeView_GetParent(hWindow, hParentID);
      }while(hParentID != NULL);
    }
    return iRet;
}
//---------------------------------------------------------------------------

AnsiString __fastcall TMainForm::GetLineString(int iLength)
{
        //TODO: Add your source code here
  AnsiString sRet;
  for(int i = 0; i < iLength; ++i)
  {
    sRet += "━";
  }
  return sRet;
}

本文地址:

https://minidump.info/blog/2005/02/E7-BC-96-E7-A8-8B-E8-AF-BB-E5-8F-96-E5-85-B6-E5-AE-83-E8-BF-9B-E7-A8-8B-E4-B8-ADTreeView-E7-9A-84-E5-86-85-E5-AE-B9/

上一篇

编程读取其它进程中ToolBar的内容

void __fastcall TMainForm::GetToolBarContent(){ //TODO: Add your source code here int nItemCount; int i; char chBuffer[256]; DWO...…

imported from CSDN 全文阅读
下一篇

TSharedMem类

/// SharedMem.hclass TSharedMem{private: bool FCreated; BYTE *FFileView; HANDLE FHandle;public: TSharedMem(const TCHAR* Name, int Size); ...…

imported from CSDN 全文阅读