Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


ID: 15541, Getting an handle to a window in another application.

by Heinrich Behrmann Email: Anonymous


Fix to source in Article #17362 FAQ Question:
How do I get the handle of another application's window and make
that window the active window?
Download Details
FTP  download also available
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
To download this, you must have registered:
A free membership

For Delphi, Version 1.0  to 5.0 1789 downloads
Copyright: No significant restrictions


Size: 679 bytes
Updated on Sun, 28 Jan 2001 06:35:04 GMT
Originally uploaded on Sun, 28 Jan 2001 06:27:42 GMT
SHA1 Hash: BE35A7313F629B874FAA6F5297C35913C4A7111F
MD5 Hash: 4CA5E2D43F290F3B22895C8A1AD71325

    Explore the files in this upload

Description
there is a bug inside the answers source example, which will never give a true result
and which took me some time to spend on an issue, I had not been focused on:


...

function FindAWindow(Caption : string;
ClassName : string) : THandle;
var
WindowInfo : TFindWindowStruct;

begin
with WindowInfo do begin
Caption := Caption;
ClassName := ClassName;
WindowHandle := 0;
EnumWindows(@EnumWindowsProc, LongInt(@WindowInfo));
FindAWindow := WindowHandle;
end;
end;

...

Problem:
The 'with' statement does not allow to take over the function's parameters,
because they do have the same name as record members.

Fix:
Change names as below or similar.

...

function FindAWindow(LocalCaption : string;
LocalClassName : string) : THandle;
var
WindowInfo : TFindWindowStruct;

begin
with WindowInfo do begin
Caption := LocalCaption;
ClassName := LocalClassName;
WindowHandle := 0;
EnumWindows(@EnumWindowsProc, LongInt(@WindowInfo));
FindAWindow := WindowHandle;
end;
end;

...

   Latest Comments  View All Add New

Move mouse over comment to see the full text

Could not retrieve comments. Please try again later.

Server Response from: ETNACDC04