How use case with findwindow

Fake

how using CASE in the following code?

  if (Pos('1080', IntToStr(Screen.Height)) > 0) and (FindWindow(nil, 'Stack Overflow - Google Chrome') > 0) then
  begin
    Form1.Top := 66;
    Form1.Left := 546;
  end;
  if (Pos('1080', IntToStr(Screen.Height)) > 0) and (FindWindow(nil, 'Stack Overflow - Mozilla Firefox') > 0) then
  begin
    Form1.Top := 76;
    Form1.Left := 546;
  end;

i try use this

var
  resolu : string;
begin
  resolu := IntToStr(Screen.Height);
  case AnsiIndexStr(resolu, ['1080', '768','864', '720', '1050', '1024', '960', '900', '800'])  of
  0 :
  begin
    Form1.Top := 80;
    Form1.Left := 900;
  end;

But I need to check if the window is open in a particular browser.

Jens Borrisholt

Its a bit unclear exactly what you are asking about but your browser check can be done like this:

procedure TForm1.SetFormPosition;
type
  TBorwser = (Chrome, Firefox);
const
  WindowText: array [TBorwser] of pChar = ('Stack Overflow - Google Chrome', 'Stack Overflow - Mozilla Firefox');
var
  Borwser, BrowserFound: TBorwser;
  WindowFound: Boolean;
begin
  WindowFound := False;
  for Borwser := low(TBorwser) to high(TBorwser) do
    if FindWindow(nil, WindowText[Borwser]) > 0 then
    begin
      WindowFound := True;
      BrowserFound := Borwser;
    end;

  if not WindowFound then
    exit;

  case BrowserFound of
    Chrome:
      begin
        Form1.Top := 66;
        Form1.Left := 546;
      end;

    Firefox:
      begin
        Form1.Top := 76;
        Form1.Left := 546;
      end;

  end;

end;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related