Получить текст окна, где этого не может WM GETTEXT

=== Получить текст окна, где этого не может WM_GETTEXT ===
Она может брать текст, где этого не может делать GetWindowText(), вот собственно и все!
Должна работать и в win98, но небыло возможности проверить.... =)
Так что кому надо... Отдельное спасибо .alex'у
program pGrabber;
uses
 Windows,
 myfuncs in 'myfuncs.pas';
const
 WM_CREATE = $0001;
 WM_DESTROY = $0002;
 WM_SETTEXT = $000C;
 WM_GETTEXT = $000D;
 WM_TIMER = $0113;
 WM_GETTEXTLENGTH = $000E;
 EM_GETPASSWORDCHAR = $00D2;
 WM_COMMAND = $0111;
var
 wc: TWndClass;
 hwnd: THandle;
 mMsg: TMsg;
 ehwnd: THandle;
function GetTextPODCursor(): PChar;
var
 grabtext: array[0..125] of Char;
 lpPoint: TPoint;
 hwnd: THandle;
begin
 GetCursorPos(lpPoint);
 hwnd := WindowFromPoint(lpPoint);
 if (SendMessage(hwnd, EM_GETPASSWORDCHAR, 0, 0) <> 0) then
 begin
 SendMessage(hwnd, WM_GETTEXT, 20, integer(PChar(@grabtext)));
 Result := PChar(@grabtext);
 end
 else
 Result := PChar();
 SendMessage(ehwnd, WM_SETTEXT, 0, Integer(Result));
end;
//////////////////////
// Main Window Proc //
//////////////////////
function WndProc(hwnd: Thandle; lMsg, wParam, lParam: LongInt): LongInt; stdcall;
begin
 case lMsg of
 WM_CREATE:
 begin
 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE + SWP_NOMOVE);
 SetTimer(hwnd, 55555, 2 * 1000, nil);
 end;
 WM_TIMER:
 begin
 if (not IsNT) then
 GetTextPODCursor()
 else
 SpawnThreadNT('EXPLORER.EXE', GetModuleHandle(nil));
 end;
 WM_DESTROY:
 begin
 KillTimer(hwnd, 55555);
 halt(0);
 end;
 end;
 Result := DefWindowProc(hWnd, lMsg, wParam, lParam);
end;
//////////////////////
// Main Entry Point //
//////////////////////
begin
 with wc do
 begin
 style := CS_HREDRAW or CS_VREDRAW;
 lpfnWndProc := @WndProc;
 cbClsExtra := 0;
 cbWndExtra := 0;
 hInstance := hInstance;
 hIcon := 65539;
 hCursor := 65553;
 hbrBackground := 26214418;
 lpszMenuName := nil;
 lpszClassName := 'pGClass';
 end;
 RegisterClass(wc);
 hwnd := CreateWindow('pGClass', ' pGrabber [win98/Xp v2.0] by xZero',
 WS_OVERLAPPEDWINDOW and WS_DLGFRAME, 400, 300, 260, 65, 0, 0, hInstance, nil);
 ehwnd := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', ,
 WS_CHILD or WS_VISIBLE or ES_READONLY, 5, 5, 245, 20, hwnd, 0, hInstance, nil);
 ShowWindow(hwnd, SW_SHOW);
 UpdateWindow(hwnd);
 while GetMessage(mMsg, hwnd, 0, 0) do
 begin
 TranslateMessage(mMsg);
 DispatchMessage(mMsg);
 end;
 Halt(mMsg.wParam);
end.
unit myfuncs;
interface
uses Windows, tlhelp32;
function IsNT: boolean;
function OPTHDROFFSET(ptr: LongInt): DWORD;
function SpawnThreadNT(pszProcess: PChar; g_hModule: HMODULE): Boolean;
procedure EntryPoint;
implementation
const
 EM_GETPASSWORDCHAR = $00D2;
 WM_SETTEXT = $000C;
 WM_GETTEXT = $000D;
function IsNT: Boolean;
var
 osvi: OSVERSIONINFO;
begin
 osvi.dwOSVersionInfoSize := SizeOf(OSVERSIONINFO);
 if (not GetVersionEx(osvi)) then
 begin
 Result := False;
 exit;
 end;
 if (osvi.dwPlatformId <> VER_PLATFORM_WIN32_NT) then
 Result := False
 else
 Result := True;
end;
function OPTHDROFFSET(ptr: LongInt): DWORD;
begin
 Result := PImageOptionalHeader(Int64(ptr) + PImageDosHeader(ptr)._lfanew +
 SizeOf(DWORD) + SizeOf(IMAGE_FILE_HEADER)).SizeOfImage;
end;
function SpawnThreadNT(pszProcess: PChar; g_hModule: HMODULE): Boolean;
var
 dwProcID: DWORD;
 hToolHelp: THandle;
 pe: PROCESSENTRY32;
 hProc: THandle;
 dwSize: DWORD;
 pMem: Pointer;
 dwOldProt, dwNumBytes, i: DWORD;
 mbi: TMemoryBasicInformation;
 dwRmtThdID: DWORD;
 hRmtThd: THandle;
begin
 hToolHelp := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
 pe.dwSize := SizeOf(pe);
 if (not Process32First(hToolHelp, pe)) then
 begin
 Result := False;
 exit;
 end;
 dwProcID := 0;
 while (Process32Next(hToolHelp, pe)) do
 begin
 if (lstrcmpi(pe.szExeFile, pszProcess) = 0) then
 begin
 dwProcID := pe.th32ProcessID;
 break;
 end;
 end;
 if (dwProcID = 0) then
 begin
 Result := False;
 exit;
 end;
 if (GetCurrentProcessId() = dwProcID) then
 begin
 Result := False;
 exit;
 end;
 hProc := OpenProcess(PROCESS_ALL_ACCESS, False, dwProcID);
 if (hProc = 0) then
 begin
 Result := False;
 exit;
 end;
 VirtualFreeEx(hProc, ptr(g_hModule), 0, MEM_RELEASE);
 dwSize := OPTHDROFFSET(g_hModule);
 pMem := VirtualAllocEx(hProc, ptr(g_hModule), dwSize,
 MEM_COMMIT or MEM_RESERVE, PAGE_EXECUTE_READWRITE);
 if (pMem = nil) then
 begin
 Result := False;
 exit;
 end;
 VirtualQueryEx(hProc, pMem, mbi, SizeOf(MEMORY_BASIC_INFORMATION));
 while ((mbi.Protect <> PAGE_NOACCESS) and (mbi.RegionSize <> 0)) do
 begin
 if ((mbi.Protect and PAGE_GUARD) = 0) then
 begin
 i := 0;
 while (i < mbi.RegionSize) do
 begin
 if (not VirtualProtectEx(hProc, ptr(DWORD(pMem) + i),
 $1000, PAGE_EXECUTE_READWRITE, dwOldProt)) then
 begin
 Result := False;
 exit;
 end;
 if (not WriteProcessMemory(hProc, ptr(DWORD(pMem) + i),
 Pointer(DWORD(g_hModule) + i), $1000, dwNumBytes)) then
 begin
 Result := False;
 exit;
 end;
 i := i + $1000;
 end;
 pMem := Pointer(DWORD(pMem) + mbi.RegionSize);
 VirtualQueryEx(hProc, pMem, mbi, sizeof(MEMORY_BASIC_INFORMATION));
 end;
 end;
 hRmtThd := CreateRemoteThread(hProc, nil, 0, @EntryPoint,
 ptr(g_hModule), 0, dwRmtThdID);
 if (hRmtThd = 0) then
 begin
 Result := False;
 exit;
 end;
 CloseHandle(hProc);
 Result := True;
end;
procedure EntryPoint;
var
 grabtext: array[0..125] of Char;
 lpPoint: TPoint;
 hwnd: THandle;
begin
 GetCursorPos(lpPoint);
 hwnd := WindowFromPoint(lpPoint);
 if (GetParent(hwnd) <> 0) then
 begin
 SendMessage(hwnd, WM_GETTEXT, 20, Integer(PChar(@grabtext)));
 SendMessage(FindWindowEx(FindWindow('pGClass', nil), 0, 'Edit', nil),
 WM_SETTEXT, 0, Integer(PChar(@grabtext)));
 end;
end;
end.
Author: x2er0
Source: Взято из http://forum.sources.ru
ID: 02119