1. 2011. 4. 18. 22:57 Tutorials/IDE]Delphi 7.2
대략 아래 화면처럼 디자인 할것 입니다.
Win32.WebBrowser( ieframe.dll ) ActiveX 가 없다면, 추가하여 사용 할것 입니다.


컴포넌트 메뉴의 "Import ActiveX control..." 을 눌러 ActiveX 를 설치 합니다.
"Install" 을 선택하면 VCL 목록에 첨가되며, "Create Unit" 을 선택하면 수동으로 동적 생성 하여 사용 해야 합니다.
웹브라우저 컨트롤 : "Microsoft InternetControls ( Version 1.1 )" 선택후 "Install" 클릭


아래 지정한 ActiveX 목록에 VCL 이 잘 추가되었습니다.
추가되지 않는경우 이미 해당 이름이 있는 경우 입니다.


패널을 Align 값 alTop 으로 지정후,
웹브라우저는 Align 값을 alClient 로 주어 창 나머지 전체에 맞추었습니다.
아래 웹브라우저 속성

RegisterAsBrowser : 브라우저로 등록 합니다.
RegisterAsDragDrop : 파일을 끌어다 로드할수 있도록 등록 합니다.



메인폼, 컨트롤 속성 및 트리 구조


대략적인 창 형태가 완성되었다면, 이벤트 생성후 코드를 작성 합니다.


속성텝 바로 옆에 이벤트 텝이 있으며, 빈곳 더블클릭 으로 생성, 이동할 수 있습니다.

소스코드 상단에 있는 uses 에 Registry 를 첨가 합니다.
uses Windows,SysUnits, ~~~, Registry;


procedure TMainForm.Memo_URLKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var flag:OleVariant;
begin
  if( ssCtrl in Shift )and( Key = VK_RETURN )then begin//조합키 누름 Ctrl + Enter
    flag := 1;//새창 띄우기
    iExplorer.Navigate( TMemo(Sender).Text , flag);
  end else if Key = VK_RETURN then begin//키누름 Enter
    iExplorer.Navigate( TMemo(Sender).Text );
  end;
end;



procedure TMainForm.SpeedButton_urlClick(Sender: TObject);begin
  iExplorer.Navigate( Memo_URL.Text );//탐색 시작
end;



procedure TMainForm.SpeedButton_modeClick(Sender: TObject);
var reg: TRegistry;
begin
  reg := TRegistry.Create;
  if Assigned( reg ) then begin//유효성 검사
    reg.RootKey := HKEY_CURRENT_USER;
    if reg.OpenKey('\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION',True) then begin
    //레지스트리 열기
      if SpeedButton_mode.Caption = ie8 then begin//레지스트리 DWORD 등록
        reg.WriteInteger( ExtractFileName(Application.ExeName), 7000 );
        SpeedButton_mode.Caption := ie7;
      end else begin
        reg.WriteInteger( ExtractFileName(Application.ExeName), 8000 );
        SpeedButton_mode.Caption := ie8;
      end;
      SpeedButton_url.Click;
    end;
  end;
end;



procedure TMainForm.iExplorerTitleChange(ASender: TObject; const Text: WideString);begin
  Self.Caption := Text;
end;


폼이벤트에도 등록 했습니다.
FormCreate & FormClose 사용이 끝나면 레지스트리를 지워주는 것이 깔끔하고, 소프트웨어 경영에도 좋죠.
procedure TMainForm.FormCreate(Sender: TObject);begin
  SpeedButton_mode.Click;
end;

procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
var reg: TRegistry;
begin
  reg := TRegistry.Create;
  if Assigned( reg ) then begin//유효성 검사
    reg.RootKey := HKEY_CURRENT_USER;
    if reg.OpenKey('',True) then begin//레지스트리 열기
      reg.DeleteValue( ExtractFileName(Application.ExeName) );//레지스트리 값 제거
    end;
  end;
end;

tip : 단축키가 안듣는 문제 해결법 ( http://xtales.tistory.com/entry/Delphi-WebBrowser-ActiveX-Control-in-IE-Doesnt-Detect-Keystrokes )
Posted by Nightly Luna
,
® © Tanny Tales
/ rss