Вот абсолютно рабочая функция получающая текст активного таба в чужом процессе . Правда на С++, но механизм , я думаю понятен.
Код:
//---------------------------------------------------------------------------------
// GetActiveTabText
//---------------------------------------------------------------------------------
// This function return the text(caption) of active page
// in the tabcontrol window, that it get.
//---------------------------------------------------------------------------------
typedef LPVOID (__stdcall * PFNVIRTALLEX)(HANDLE, LPVOID, DWORD, DWORD,DWORD);
CString GetActiveTabText(HWND hWnd)
{
DWORD dwProcessId;
HANDLE hProcess;
PFNVIRTALLEX pfnVirtualAllocEx;
TC_ITEM *ptci;
TC_ITEM tci;
CString Text;
int TabSelected;
char Buffer[255] = "\n";
TabSelected = TabCtrl_GetCurSel(hWnd);
GetWindowThreadProcessId(hWnd, &dwProcessId);
hProcess = OpenProcess( PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, dwProcessId);
if (hProcess == NULL)
{
MessageBox(NULL,"Could not communicate with process","", MB_OK | MB_ICONWARNING);
return "";//0;
}
/// Allocate memory in the remote process's address space
//get procAddress this way so the code can be compiled on win 95/98
pfnVirtualAllocEx = (PFNVIRTALLEX) GetProcAddress(GetModuleHandle("KERNEL32.DLL"),"VirtualAllocEx");
ptci = (TC_ITEM*) pfnVirtualAllocEx(hProcess, NULL, sizeof(TC_ITEM)+25, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
tci.mask = TCIF_TEXT;
tci.pszText = (LPTSTR) (ptci + 1) ;
tci.cchTextMax = 25;
// Write the local TC_ITEM structure to the remote memory block
WriteProcessMemory(hProcess, ptci, &tci, sizeof(tci), NULL);
TabCtrl_GetItem(hWnd,TabSelected ,ptci);
// Read the remote text string into the end of our clipboard buffer
ReadProcessMemory(hProcess, ptci + 1,Buffer, 24, NULL);
// Free the memory in the remote process's address space
VirtualFreeEx(hProcess, ptci, 0, MEM_RELEASE);
CloseHandle(hProcess);
Text = Buffer;
return Text;
}
// -----------------------------------------------------