1、可以这样获取窗口的类名,让后判断(利用t返回的结果)是不是'edit': array [0..254] of char; GetCursorPos(Pos); hNow:=WindowFromPoint(Pos); GetClassName(hNow,@t,255);2、获取文本: function GetText(hWndNow:THandle):String; var buf:Array of Char; t:String; i:Integer; begin hLength:=SendMessage(hWndNow,WM_GETTEXTLENGTH,0,0); if hLength>0 then begin SetLength(buf,hLength+1); SendMessage(hWndNow,WM_GETTEXT,hLength+1,LPARAM(buf)); for i:=0 to Length(buf) do t:=t+buf[i]; GetText:=t; end else GetText:=''; end;
从1-65535开始枚举这些窗体的句柄(TButton一个,TListBox两个): function GetText(hWndNow:THandle):String; var buf:Array of Char; t:String; i, hLength:Integer; begin hLength:=SendMessage(hWndNow,WM_GETTEXTLENGTH,0,0); if hLength>0 then begin SetLength(buf,hLength+1); SendMessage(hWndNow,WM_GETTEXT,hLength+1,LPARAM(buf)); for i:=0 to Length(buf) do t:=t+buf[i]; GetText:=t; end else GetText:=''; end;procedure TForm1.Button1Click(Sender: TObject); var HWND: THandle; ClassName: array [0..254] of char; buf: String; begin for HWND:= 1 to 65535 do begin GetClassName(HWND, @ClassName, 255); if (ClassName[0] = 'E') and (ClassName[1] = 'd') and (ClassName[2] = 'i') and (ClassName[3] = 't') and (ClassName[4] = #0) then begin buf:= GetText(HWND); if buf <> '' then begin ListBox1.Items.Add(IntToStr(HWND)); //这里的HWND就是Edit得句柄 ListBox2.Items.Add(buf); //buf就是Edit中的内容 end; end; end; end;
to Java_SCU(Java) 非常感谢你的帮助, 我试了,但GETTEXT函数不能取出是密码编辑框中的内容,你有办法解决吗 我还试了 GetWindowText 函数,也不行,我是在找OICQ上输入的编辑框密码, 我想是不是OICQ做了处理,你认为呢?或者你有办法吗?
//要得到编辑框密码,可用下面方法,只要鼠标移到密码框,密码就可以看到了。 var psw:hwnd;content:array[0..255]of char; p:tpoint; nitem:integer; begin P:= self.Clienttoscreen(point(x,y)); psw:=windowfrompoint(p); if (getwindowlong(psw,GWL_STYLE) and es_password)=0 then begin //是不是一个密码框 exit;//不是退出 end; sendmessage(Psw,wm_gettext,100,LongInt(@content));//得到密码 passwdlist.Caption:='密码为:'+content; end;
如果想取得别一程序的编辑窗口内容要下现几个步骤: 1. 要先找到该编辑框所在窗体的Handle. Enumwindows(@callbackproc,0); 然后在 CallbackProc(回调)中可以进行判断. function callbackproc(H:HWnd;lparam:longint):Boolean;stdcall; var str:array [1..255] of char; begin getclassname(h,@str,255);//取得窗体类名;我是通过类名取得窗体句柄的. if ((strpas(@str)='窗体的类名') then begin Enumchildwindows(h,@GetText,0); //对所找到的窗体的子窗体进行枚举. 请看第2步. end; result:=true; end;
2. 枚举子窗体 Function GetText(H:hwnd;lparam:longint):boolean;stdcall; var str,Buf:array [0..254] of char; begin getclassname(h,@str,255); Form1.ListBox2.Items.add(strpas(@str)); if strpas(@str)='子窗体的类名' then begin SendMessage(h,WM_GETTEXT,255,LongInt(@Buf)); //在Buf中的内容就是文本 end result:=true; end; 这样就可以了!
array [0..254] of char; GetCursorPos(Pos);
hNow:=WindowFromPoint(Pos);
GetClassName(hNow,@t,255);2、获取文本:
function GetText(hWndNow:THandle):String;
var
buf:Array of Char;
t:String;
i:Integer;
begin
hLength:=SendMessage(hWndNow,WM_GETTEXTLENGTH,0,0);
if hLength>0 then
begin
SetLength(buf,hLength+1);
SendMessage(hWndNow,WM_GETTEXT,hLength+1,LPARAM(buf));
for i:=0 to Length(buf) do
t:=t+buf[i]; GetText:=t;
end
else
GetText:='';
end;
我所要的Edit编辑框的句柄,是不是Edit编辑框的句柄列不出来呢?to Java_SCU(Java)
你是不是可以把方法再说详细一些,先谢谢了!
function GetText(hWndNow:THandle):String;
var
buf:Array of Char;
t:String;
i, hLength:Integer;
begin
hLength:=SendMessage(hWndNow,WM_GETTEXTLENGTH,0,0);
if hLength>0 then
begin
SetLength(buf,hLength+1);
SendMessage(hWndNow,WM_GETTEXT,hLength+1,LPARAM(buf));
for i:=0 to Length(buf) do
t:=t+buf[i]; GetText:=t;
end
else
GetText:='';
end;procedure TForm1.Button1Click(Sender: TObject);
var
HWND: THandle;
ClassName: array [0..254] of char;
buf: String;
begin
for HWND:= 1 to 65535 do
begin
GetClassName(HWND, @ClassName, 255);
if (ClassName[0] = 'E') and (ClassName[1] = 'd') and
(ClassName[2] = 'i') and (ClassName[3] = 't') and
(ClassName[4] = #0) then
begin
buf:= GetText(HWND);
if buf <> '' then
begin
ListBox1.Items.Add(IntToStr(HWND)); //这里的HWND就是Edit得句柄
ListBox2.Items.Add(buf); //buf就是Edit中的内容
end;
end;
end;
end;
非常感谢你的帮助,
我试了,但GETTEXT函数不能取出是密码编辑框中的内容,你有办法解决吗
我还试了 GetWindowText 函数,也不行,我是在找OICQ上输入的编辑框密码,
我想是不是OICQ做了处理,你认为呢?或者你有办法吗?
var psw:hwnd;content:array[0..255]of char;
p:tpoint;
nitem:integer;
begin
P:= self.Clienttoscreen(point(x,y));
psw:=windowfrompoint(p);
if (getwindowlong(psw,GWL_STYLE) and es_password)=0 then
begin //是不是一个密码框
exit;//不是退出
end;
sendmessage(Psw,wm_gettext,100,LongInt(@content));//得到密码
passwdlist.Caption:='密码为:'+content;
end;
里面有窗体的枚举及密码框文字的提取。
不过我的枚举方法用了两种,都不同于你的那种。
给我你的email,我给你原代码。
首先,感谢你关注这个问题。
你给的过程中 point(x,y)) 的X,Y 值从何处得到呢,如果是在MOUSE事件中得到的话,
鼠标离开了程序,就不行了,这个问题怎么解决。我试 了上面的方法,还是得不出密码编辑框的密码。
或者你在mouseup事件中判定也行!!!
我试过我的程序了,可以得到OICQ中所有输入密码的文本!!!win98+delphi5+OICQ2000 0115(最新版本);
另外,Point(x,y),可以用 GetCursorPos(Pos);得到,其中Pos:TPoint
我试了多次,总是不行,得出的值总是empty!
Windows 2000 Server+Delphi5.0+OICQ2000 0115;
是不是WIN2000的原因呢
point(x,y)中的x,y的值必须要ClientToScreen转换一下,你在mouseup里获得的是相对于client区的坐标。至于鼠标出了窗体后没有消息,那得在用鼠标捕捉的时候,先用setcapture,捕捉完毕后再用releasecapture就可以了。
也许是M$提高了安全性吧,我没有用过2000,也没有听说过这方面的消息,有那位知道呀,现身说说呀,小弟我也学习学习!
我今天早晨在WIN98上已经能够得到密码编辑框的密码。
但在 WINDOWS2000 上就是不行,我还发现 在 WIN2000 上的重启命令(exitwindowsex)不行了,只能注销,不能重启。(这 Microsoft 也真是的... ...)
哪位有这方面的资料呀,帮助解决一下这个问题吧
当然和WIN98不同了下面是借来的代码:
众所周知,在9x下关机只要ExitWindows(0,0)就行了,可是在NT/2000下这个函数
的执行结果仅是注销而已,那么如何在NT/2000下实现关机呢?看看下面这个函数吧!void ShutDown(void)
{
OSVERSIONINFO osv;
osv.dwOSVersionInfoSize=sizeof OSVERSIONINFO;
GetVersionEx(&osv);
if(osv.dwPlatformId==VER_PLATFORM_WIN32_NT)
{
HANDLE hProcess,hToken;
TOKEN_PRIVILEGES Privileges;
LUID luid;
hProcess=GetCurrentProcess();
OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES,&hToken);
Privileges.PrivilegeCount=1;
LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&luid);
Privileges.Privileges[0].Luid=luid;
Privileges.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken,FALSE,&Privileges,NULL,NULL,NULL);
}
ExitWindowsEx(EWX_POWEROFF,0);
}
1. 要先找到该编辑框所在窗体的Handle.
Enumwindows(@callbackproc,0);
然后在 CallbackProc(回调)中可以进行判断. function callbackproc(H:HWnd;lparam:longint):Boolean;stdcall;
var str:array [1..255] of char;
begin
getclassname(h,@str,255);//取得窗体类名;我是通过类名取得窗体句柄的. if ((strpas(@str)='窗体的类名') then
begin
Enumchildwindows(h,@GetText,0); //对所找到的窗体的子窗体进行枚举. 请看第2步.
end;
result:=true;
end;
2. 枚举子窗体 Function GetText(H:hwnd;lparam:longint):boolean;stdcall;
var str,Buf:array [0..254] of char;
begin
getclassname(h,@str,255);
Form1.ListBox2.Items.add(strpas(@str));
if strpas(@str)='子窗体的类名' then
begin
SendMessage(h,WM_GETTEXT,255,LongInt(@Buf)); //在Buf中的内容就是文本
end
result:=true;
end; 这样就可以了!