1,183
社区成员
发帖
与我相关
我的任务
分享
uses commctrl;
procedure CrnGetStatusBarItem(hStatusBar: THandle; pList: TStrings);
var
dwProcessID: DWORD;
hProcess: THandle;
lpCommon: Pointer;
nAllocSize: integer;// = 255;
szBuf: array [0..255] of char;
dwBytesRead: DWORD;
nPnlCount: integer;
i: integer;
begin
nAllocSize := 255;
nPnlCount := SendMessage(hStatusBar, SB_GETPARTS, 0, 0);
pList.Add('StatusBar的项目数: ' + IntToStr(nPnlCount));
GetWindowThreadProcessId(hStatusBar, @dwProcessID);
hProcess := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ, false, dwProcessID);
lpCommon := VirtualAllocEx(hProcess, nil, nAllocSize,
MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE);
for i := 0 to nPnlCount - 1 do
begin
SendMessage(hStatusBar, SB_GETTEXT, i, LPARAM(lpCommon));
ReadProcessMemory(hProcess, lpCommon, @szBuf, 255, dwBytesRead);
pList.Add(szBuf);
end;
VirtualFreeEx(hProcess, lpCommon, 0, MEM_RELEASE);
CloseHandle(hProcess);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
hTopWnd, hWnd: THandle;
begin
hTopWnd := FindWindow('MSPaintApp', nil);
if IsWindow(hTopWnd) then
begin
hWnd := FindWindowEx(hTopWnd, 0, 'msctls_statusbar32', nil);
if IsWindow(hWnd) then
CrnGetStatusBarItem(hWnd, Memo1.Lines);
end;
end;
void __stdcall CrnGetStatusBarItem(HANDLE hStatusBar, TStrings *pList)
{
DWORD dwProcessID;
HANDLE hProcess;
LPVOID lpCommon;
int nAllocSize = 255;
int nPnlLen;
char szBuf[255];
DWORD dwBytesRead;
int nPnlCount = SendMessage(hStatusBar, SB_GETPARTS, 0, 0);
pList->Add("StatusBar的项目数: " + String(nPnlCount));
GetWindowThreadProcessId(hStatusBar, &dwProcessID);
hProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ |
PROCESS_VM_WRITE, false, dwProcessID);
lpCommon = VirtualAllocEx(hProcess, NULL, nAllocSize,
MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
for(int i=0; i<nPnlCount; i++)
{
SendMessage(hStatusBar, SB_GETTEXT, i, LPARAM(lpCommon));
ReadProcessMemory(hProcess, lpCommon, szBuf, 255, &dwBytesRead);
pList->Add(szBuf);
}
VirtualFreeEx(hProcess, lpCommon, 0, MEM_RELEASE);
CloseHandle(hProcess);
}
function HandleTEXT(Handlea:THandle):string;
var
s:array[0..255] of Char;
dw:DWORD;
begin
SendMessage(Handlea, SB_GETTEXT,Length(S), Integer(@S));
Result:=S;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
HWindow,hedit: THandle; //句本柄变量
szText: string; //得到的字符串
begin
HWindow:=0;
HWindow:=FindWindow(nil,'学习句柄');
HWindow:=FindWindowEx(HWindow,0,'TStatusBar',nil);//找Sta句柄
szText:=HandleTEXT(HWindow); //将sta的pan值取出来
ShowMessage(IntToStr(HWindow));
ShowMessage(szText);
end;