| View previous topic :: View next topic |
| Author |
Message |
Anden100 Grandmaster Cheater
Reputation: 0
Joined: 20 Apr 2007 Posts: 668
|
Posted: Mon May 05, 2008 4:26 am Post subject: Get the title of a window |
|
|
I was wondering, if it is possible to get the title of a window, using the hwnd, or in any other way, get a list of all the open applictions, by the window name or class name
Prefer in delphi, but C++ would be ok aswell
|
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Mon May 05, 2008 4:58 am Post subject: |
|
|
Look in ce's source at the proces list or window list thing...
Anyway, you can use the following api's:
EnumWindows
GetWindow
FindWindow
GetActiveWindow
GetWindowText
GetWindowTextLength
SetWindowText
and probably some more..
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Mon May 05, 2008 5:01 am Post subject: |
|
|
Yea, you can do a lot with a window-handle.
I got this of one of my old sources, not sure if I wrote it or not, but I couldn't find it on google so I think I wrote that.
| Code: | procedure TForm1.Button1Click(Sender: TObject);
var
h: hwnd;
cap: string;
int: integer;
begin
h := FindWindow('TApplication', NIL);
if h <> 0 then
begin
int := GetWindowTextLength(h)+1;
SetLength(cap, int);
GetWindowText(h, PChar(cap), int);
ShowMessage(cap);
end;
end; |
Replace the TApplication to the class of the window.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Mon May 05, 2008 5:30 am Post subject: |
|
|
| rEakW0n wrote: | Yea, you can do a lot with a window-handle.
I got this of one of my old sources, not sure if I wrote it or not, but I couldn't find it on google so I think I wrote that.
| Code: | procedure TForm1.Button1Click(Sender: TObject);
var
h: hwnd;
cap: string;
int: integer;
begin
h := FindWindow('TApplication', NIL);
if h <> 0 then
begin
int := GetWindowTextLength(h)+1;
SetLength(cap, int);
GetWindowText(h, PChar(cap), int);
ShowMessage(cap);
end;
end; |
Replace the TApplication to the class of the window. |
nvm i figured it out XD
_________________
Stylo
Last edited by Stylo on Mon May 05, 2008 5:37 am; edited 1 time in total |
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Mon May 05, 2008 5:36 am Post subject: |
|
|
| 1qaz wrote: | i couldn't find information about the setLength function on msdn
can you explain that function please? where can i find it? |
You see, I declard something to int, the Length of the Window-Text(+1).
And now, before I declare the Window-Text to cab I set its length.
So, SetLength() sets the length of the string
In this case I set the length of cap to int.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Mon May 05, 2008 6:06 am Post subject: |
|
|
| rEakW0n wrote: | Yea, you can do a lot with a window-handle.
I got this of one of my old sources, not sure if I wrote it or not, but I couldn't find it on google so I think I wrote that.
| Code: | procedure TForm1.Button1Click(Sender: TObject);
var
h: hwnd;
cap: string;
int: integer;
begin
h := FindWindow('TApplication', NIL);
if h <> 0 then
begin
int := GetWindowTextLength(h)+1;
SetLength(cap, int);
GetWindowText(h, PChar(cap), int);
ShowMessage(cap);
end;
end; |
Replace the TApplication to the class of the window. |
The reason you didn't find it on the net because you renamed the variables, uppercased some stuff and removed some lines that you probably didn't understand - http://www.swissdelphicenter.ch/torry/showcode.php?id=2143
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Mon May 05, 2008 6:22 am Post subject: |
|
|
| Rot1 wrote: | | rEakW0n wrote: | Yea, you can do a lot with a window-handle.
I got this of one of my old sources, not sure if I wrote it or not, but I couldn't find it on google so I think I wrote that.
| Code: | procedure TForm1.Button1Click(Sender: TObject);
var
h: hwnd;
cap: string;
int: integer;
begin
h := FindWindow('TApplication', NIL);
if h <> 0 then
begin
int := GetWindowTextLength(h)+1;
SetLength(cap, int);
GetWindowText(h, PChar(cap), int);
ShowMessage(cap);
end;
end; |
Replace the TApplication to the class of the window. |
The reason you didn't find it on the net because you renamed the variables, uppercased some stuff and removed some lines that you probably didn't understand - http://www.swissdelphicenter.ch/torry/showcode.php?id=2143 |
I at least say that I'm not sure if i wrote it by myself.
Also, I'm not even sure if it's from there, it seems smiliar but not same.
I copied this out of an old project.
And these 2 lines aren't neccesarry afaik.
| Rot1 wrote: | | removed some lines that you probably didn't understand - |
Stop being a hypocrite.
Last edited by Reak on Mon May 05, 2008 6:31 am; edited 1 time in total |
|
| Back to top |
|
 |
Anden100 Grandmaster Cheater
Reputation: 0
Joined: 20 Apr 2007 Posts: 668
|
Posted: Mon May 05, 2008 6:29 am Post subject: |
|
|
| rEakW0n wrote: | Yea, you can do a lot with a window-handle.
I got this of one of my old sources, not sure if I wrote it or not, but I couldn't find it on google so I think I wrote that.
| Code: | procedure TForm1.Button1Click(Sender: TObject);
var
h: hwnd;
cap: string;
int: integer;
begin
h := FindWindow('TApplication', NIL);
if h <> 0 then
begin
int := GetWindowTextLength(h)+1;
SetLength(cap, int);
GetWindowText(h, PChar(cap), int);
ShowMessage(cap);
end;
end; |
Replace the TApplication to the class of the window. |
woot! ty soo much!, modifyed it a bit, now it shows all the visible windows :
procedure TForm1.Button2Click(Sender: TObject);
var
h: hwnd;
cap: string;
int: integer;
begin
h := handle;
while h > 0 do
begin
if IsWindowVisible(h) then
begin
int := GetWindowTextLength(h)+1;
SetLength(cap, int);
GetWindowText(h, PChar(cap), int);
listbox1.Items.Add(cap);
h := GetNextWindow(h, GW_HWNDNEXT);
end;
h := GetNextWindow(h, GW_HWNDNEXT);
end;
end;
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Mon May 05, 2008 11:17 am Post subject: |
|
|
why when i use the GetWindowText function my application shutdown?
i have HWND to the window, empty string, and integer variable and i get no error when i compile the code
_________________
Stylo |
|
| Back to top |
|
 |
Anden100 Grandmaster Cheater
Reputation: 0
Joined: 20 Apr 2007 Posts: 668
|
Posted: Mon May 05, 2008 11:22 am Post subject: |
|
|
| 1qaz wrote: | why when i use the GetWindowText function my application shutdown?
i have HWND to the window, empty string, and integer variable and i get no error when i compile the code |
It did that to me aswell, but i fixed it, can i please see your source?
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Mon May 05, 2008 11:40 am Post subject: |
|
|
it's inside a timer and the language is C#
| Code: |
IntPtr hwnd = FindWindow("IMWindowClass",null);
if (hwnd != IntPtr.Zero)
{
GetHWND.Stop(); // stops timer
string WindowText;
int x = 260;
GetWindowText(hwnd,out WindowText,x);
}
|
_________________
Stylo |
|
| Back to top |
|
 |
|