Solved

Get the title of a window by its handle

Posted on 2001-07-11
3
173 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now