Solved

Get the title of a window by its handle

Posted on 2001-07-11
3
176 Views
Last Modified: 2010-07-27
Hi,
How can I get the title of a window if I know the handle of that window?  Maybe GetWindowText can help, but I don't know the way to use it...Can anyone show me how to use it?

Thx.
0
Comment
Question by:nyt
  • 2
3 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6272450
Hello

yes you are right, you can use GetWindowText, it's easy to use


procedure TForm1.Button1Click(Sender: TObject);
var
  s : pchar;
begin
  GetWindowText(handle,s,255);
  showmessage(s);
end;

Best regards
Mohammed
0
 
LVL 9

Accepted Solution

by:
ITugay earned 25 total points
ID: 6272603
Hi nyt,
mnasman, wrong way. You should allocate memory for returning result.

procedure TForm1.SpeedButton1Click(Sender: TObject);
var
  //s : pchar; // will produce an exception!
  S: array[0..255] of char; // the way to allocate 256 byte for string buffer
begin
  GetWindowText(handle,s,255);
  showmessage(s);
end;

-----
Igor.
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6272653
oops

you are right Igor, i made that in fly
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to disable mouse scroll in a combo box field within a Delphi cxGrid 4 158
Magic Software info 18 139
Reconfigure Delphi Install? 2 61
How to debug For loops? 3 57
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question