如何与findwindow使用案例

时间:2015-02-05 04:35:00

标签: delphi case delphi-xe7

如何在以下代码中使用CASE?

  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;

我尝试使用此

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;

但我需要检查窗口是否在特定浏览器中打开。

2 个答案:

答案 0 :(得分:2)

有点不清楚你究竟在问什么,但你的浏览器检查可以这样做:

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;

答案 1 :(得分:0)

效果很好,谢谢。

    case BrowserFound of
    Chrome:
      begin
          case Screen.Height of
             1080 : Brada.Left := 546;
             1050 : Brada.Left := 504;
             1024 : Brada.Left := 478;
             960 : Brada.Left := 414;
             900 : Brada.Left := 354;
             800 : Brada.Left := 236;
             864 : Brada.Left := 277;
             768 : Brada.Left := 222;
             720 : Brada.Left := 225;
          end;
      end;

    Firefox:
      begin
        case Screen.Height of
          1080 : Brada.Left := 546;
        end;
      end;
  end
end;