Partial FindWindowByWindowName ?

46 views
Skip to first unread message

David F.

unread,
Jul 25, 2023, 6:57:12 PM7/25/23
to innosetup
Hello,

I typically FindWindowByWindowName to find the application to close, but I've added an app that includes the open file name in the window title.

Is there a way to have partial matches (or wildcards) using FindWindowByWindowName ?

TIA!!

mtr...@fitall.com

unread,
Jul 27, 2023, 12:09:52 PM7/27/23
to innosetup
To identify a running application from within Inno Setup you should really use a Mutex. -- see Inno documentation.

However, here is a function in Pascal that will accomplish what you want.

function FindWindowExtd(ApartialTitle: string): HWND;
var
  hWndTemp: hWnd;
  iLenText: Integer;
  cTitletemp: array [0..254] of Char;
  sTitleTemp: string;
begin
Result := 0;
hWndTemp := FindWindow(nil, nil);
while hWndTemp <> 0 do
  begin
  iLenText := GetWindowText(hWndTemp, cTitletemp, 255);
  sTitleTemp := cTitletemp;
  sTitleTemp := UpperCase(copy( sTitleTemp, 1, iLenText));
  ApartialTitle := UpperCase(ApartialTitle);
  if pos( ApartialTitle, sTitleTemp ) <> 0 then
    begin
    result := hWndTemp;
    Exit;
    end;
  hWndTemp := GetWindow(hWndTemp, GW_HWNDNEXT);
  end;
end;

Regards,
John
Reply all
Reply to author
Forward
0 new messages