怎样获取当前应用程序的窗体的Caption 或者是 Appplication.Title 在线等待(100分)

  • 主题发起人 主题发起人 ftop1
  • 开始时间 开始时间
F

ftop1

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样获取当前应用程序的窗体的Caption 或者是 Appplication.Title
 
在窗体Form里的函数直接用CAPTION,用Appplication.Title 可以访问程序的窗体标题
 
不是这样 我想用一个程序获取其他当前应用程序的标题
 
用GetWindows来找,
 
var
h: HWND;
buf: array[0..254]of char;
begin
h := GetActiveWindow;
GetWindowText(h,buf,255);
Label1.caption := buf;
end;
 
var
h: HWND;
buf: array[0..254]of char;
begin
h := GetActiveWindow;
GetWindowText(h,buf,255);
Label1.caption := buf;
end;
 
怎么获得其它程序的标题?
 
上述的都不行 怎样获得其他获得焦点的程序的Application

 
你运行的当前程序就是获得焦点了吧?
 

怎样一个程序获取其他当前应用程序的标题
 Appplication.Title


procedure TForm1.Timer1Timer(Sender: TObject);
begin
str:=function();
end;

function=?
 
你其实应该问如何使你的程序在后台运行.
 
GetWindowText
 
Mainform.caption
application.title
 
再使用该函数
function WinText(hWnd: LongInt): string;
var
PC: PChar;
L: integer;
begin
L := SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0);
getmem(PC, L + 1);
SendMessage(hWnd, WM_GETTEXT, L + 1, LongInt(PC));
result := PC;
end;

如:
name := '程序名称: ' + WinText(PrhWnd) ;
 
to 山泉 怎样获得当前焦点程序的句柄 hWnd
谢谢
 
FindWindow 根据标题或或它的 className

The FindWindow function retrieves the handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows.

HWND FindWindow(

LPCTSTR lpClassName, // pointer to class name
LPCTSTR lpWindowName // pointer to window name
);


Parameters

lpClassName

Points to a null-terminated string that specifies the class name or is an atom that identifies the class-name string. If this parameter is an atom, it must be a global atom created by a previous call to the GlobalAddAtom function. The atom, a 16-bit value, must be placed in the low-order word of lpClassName; the high-order word must be zero.

lpWindowName

Points to a null-terminated string that specifies the window name (the window's title). If this parameter is NULL, all window names match.



Return Values

If the function succeeds, the return value is the handle to the window that has the specified class name and window name.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.

See Also

EnumWindows, FindWindowEx, GetClassName, GlobalAddAtom
 
var
handle:Thandle;
a:pchar;
begin
handle:= GetforegroundWindow();//获取当前窗体
Getmem(a,256);
GetWindowText(Handle,a,256);
Edit1.text:=(string(a));
end;
/////////////////
有时显示不出来 '' 比如QQ登陆的时候   看来还要显示可执行文件的名称
function TForm1.GetExeFileName(wh: Thandle): string;
var
p:Dword;
thh:Thandle;
lppe:tagProcessentry32;
begin
Result:='';
GetWindowThreadProcessId(wh,@p);
thh:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
lppe.dwSize:=sizeof(lppe);
Process32First(thh,lppe);
if lppe.th32ProcessID=p then
begin
result:=lppe.szExeFile;
exit;
end;
while Process32Next(thh,lppe) do
if lppe.th32ProcessID=p then
begin
result:=lppe.szExeFile;
break;
end;
end;//没路径
 
接受答案了.
 
后退
顶部