Q&A

  • OleObject생성후 다시 원래 프로그램으로 활성화 시키는 법 궁금해요
안녕하세요!

질문 하나 할께요!

ActiveX폼에서요
my_IE := CreateOLEObject('Internetexplorer.Application');
.
.
.
.
이렇게 해서 브라우저를 하나 띄웠거든요.
그 다음 브라우저를 띄운 ActiveX가 있는 브라우저로 다시 활성화 시키는 방법이 없을까요?

SetWindowPos, BringToFront등등 해봐도 안먹네요 ㅠ.ㅠ

아시는 분 답변 부탁드리겠습니다.
즐프하세요~~~

1  COMMENTS
  • Profile
    정병선 2006.10.16 22:38
    // 소스입니다.

    uses
      Comobj;

    var
      IEApp: OLEVariant;
      IEHandle: HWND;

    function CheckExplorer(ExpOle: OLEVariant; ExpHWND: HWND): Boolean;
    begin
      // 생성한 Explorer 검사
      Result:= Not VarIsNull(IEApp) and IsWindow(IEHandle);
    end;

    function RunInternetExploreOLE(const URL: String; const FullScreen: Boolean = True): OLEVariant;
    begin
      Result:= CreateOLEObject('InternetExplorer.Application');
      Result.Visible := True;
      if FullScreen then
      begin
        Result.Top     := 0;
        Result.Left    := 0;
        Result.Width   := Screen.Width;
        Result.Height  := Screen.Height;
      end;
      Result.Navigate(URL);
    end;

    function ForceSetForegroundWindow(AHandle: HWND): Boolean;
    var
      fromId, toId: DWORD;
    begin
      fromId:= GetCurrentThreadId();
      toId:= GetWindowThreadProcessId(GetForegroundWindow, nil);
      AttachThreadInput(fromId, toId, TRUE);
      Result:= SetForegroundWindow(AHandle);
      AttachThreadInput(fromId, toId, FALSE);
    end;

    // 최소화 되었을 경우에도 다시 복원 후 Focus 하기
    procedure ShowFindWindow(WND: HWND);
    var
      Placement: TWindowPlacement;
    begin
      if IsWindow(WND) then
      begin
        Placement.length := SizeOf(TWindowPlacement);
        GetWindowPlacement(WND, @Placement);
        case Placement.showCmd of
          SW_SHOWMINIMIZED:
            ShowWindow(WND, SW_RESTORE)
          else
            ShowWindow(WND, SW_SHOW);
        if GetActiveWindow <> WND then
          ForceSetForegroundWindow(WND);
      end;
    end;

    procedure TForm2.Button1Click(Sender: TObject);
    const
      cURL: String = 'http://www.swissdelphicenter.ch/torry/';
    begin
      // 기존에 생성한 Explorer 검사
      if CheckExplorer(IEApp, IEHandle) then
      begin
        IEApp.Navigate(cURL);
        ShowFindWindow(IEHandle);
      end else
      begin
        // 생성하기
        IEApp:= RunInternetExploreOLE(cURL);
        //InternetExplorer 속성은 SHDocVw.pas 의 IWebBrowserApp 인터페이스 참조
        IEHandle:= IEApp.HWND; //Handle 등록
      end;
    end;

    procedure TForm2.Button2Click(Sender: TObject);
    begin
      // ForeGround 하기
      if CheckExplorer(IEApp, IEHandle) then
        ShowFindWindow(IEHandle)
      else
        IEApp:= Unassigned;
    end;


    익스플로러의 브라우저를 컨트롤 하려면 SHDocVW, MSHTML_TLB, MSHTML 의 인터페이스를 참고하세요.
    그럼 즐코^^;