aburgoyne
asked on
Need to get window caption when I only have the instance from GetModuleHandle
I have a DLL that I'm writing in Delphi and I need to be able to get the main window caption of the calling application. I have no issue identifying the application using GetModuleFileName() and then using GetModuleHandle() to get the instance but I can't work out how to get any further. Any assistance greatly appreciated :-)
ASKER
Yes... lots probably! I used Delphi quite a bit a few years back (D5) but haven't touched it for ages.
ASKER
Haven't used EE for quite a while either ;-) ...forgot to ask if you could include a code snippet?
Here's a function to find the window belonging to a process id:
function GetHwnd(ProcessID: DWORD): hwnd;
var WindowProcesID: DWORD;
begin
result := GetWindow(GetDesktopWindow(), GW_CHILD);
while result <> 0 do
begin
if IsWindowVisible(result) then
begin
GetWindowThreadProcessId(result, WindowProcesID);
if ProcessID = WindowProcesID then
break;
end;
result := GetWindow(result, GW_HWNDNEXT);
end;
end;
oops forgot: You can get your own processid by calling GetCurrentProcessID().
will post the rest soon
will post the rest soon
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Awesome! - works like a charm!
Thanks for all your help :-)
Thanks for all your help :-)
after that you can get the caption with GetWindowText().
Need any help with that?