类库大魔王
类库大魔王 多年C++、Go项目经验,长期从事跨平台(Windows/macOS/iOS/Android)应用架构设计与开发。

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
void __fastcall TMainForm::GetTabControlContent()
{
        //TODO: Add your source code here
    int nItemCount;
    int i;
    char chBuffer[256];
    DWORD dwProcessID;
    HANDLE hProcess;
    void * Pointer;
    SIZE_T nNumberOfBytesRead;
    TTCItem Item;

    nItemCount = TabCtrl_GetItemCount(hWindow);
    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{
    for(i= 0 ; i < nItemCount ; ++i)
    {
       Item.mask = TCIF_TEXT;
       Item.cchTextMax = sizeof (chBuffer);
       Item.pszText = (LPSTR)((UINT *)Pointer + sizeof(TTCItem));

       WriteProcessMemory(hProcess,
                    Pointer,
                    &Item,
                    sizeof(TTCItem),
                    &nNumberOfBytesRead);
       SendMessage(hWindow, TCM_GETITEM , i, (LPARAM)Pointer);
       ReadProcessMemory(hProcess,
                    (void *)((UINT *)Pointer + sizeof(TTCItem)),
                    chBuffer,
                    sizeof(chBuffer),
                    &nNumberOfBytesRead);
       ContentMemo->Lines->Add(chBuffer);
    }//for(i...
    }//try
    __finally
    {
      VirtualFreeEx(hProcess,
                    Pointer,
                    0,
                    MEM_RELEASE);
      CloseHandle(hProcess);
    }
}

感觉本文不错,不妨小额鼓励我一下!
如果你有Visa、MasterCard之类的国际银行卡,也可以考虑以下选项:
如果你看不到评论框,说明Disqus被墙了。