웹브로우져의 html 문서가 Dislay되는 오브잭트의 핸들을 알아내야 합니다.
그래야 그 핸들에 들어오는 메시지를 처리해서 엔터키를 먹도록 하게 되는 거지요.
1. THTraining 에 추가
private
{ Private declarations }
FWebHandle : Integer;
2. OnCreate에서 추가
FWebHandle := 0;
3. 웹브로우져 오브젝트의 이벤트 핸들러 추가
procedure TForm1.WebBrowserNavigateComplete2(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
If FWebHandle = 0 then Begin
FWebHandle:= FindWindowEx(WebBrowser.Handle, 0, 'Shell DocObject View', Nil);
FWebHandle:= FindWindowEx(FWebHandle, 0, 'Internet Explorer_Server', Nil);
End;
end;
* 간단한 소스라 별일 없겠지만
PC 방에서 노트패트로 작성한 소스라 ㅡ.ㅡ 혹여 에러 및 오타가 있을 수도 쿨럭 ㅡ.ㅡ;
신철우 님이 쓰신 글 :
: 아래 [소스에서] undeclared indentifier: 'FWebHandle'라고 나와서
: 이 Line을 막았더니
: object or class type required
: 라고 나오면서 실행도 되지 않네요.
:
: 답변 좀 부탁드립니다.
:
: [소스]
: unit HTraining_U;
:
: interface
:
: uses
: Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
: Dialogs, SpeedBar, StdCtrls, ExtCtrls, ComCtrls, DB, MemDS, DBAccess,
: MSAccess, Grids, DBGrids, ToolEdit, DBCtrls, Mask, Buttons, Label3dB,
: BaseGrid, AdvGrid, CurrEdit, DBTables, RXCtrls, Printers, RxGIF, Psock,
: OleCtrls, SHDocVw;
:
: type
: THTraining_F = class(TForm)
: WebBrowser1: TWebBrowser;
:
: procedure FormCreate(Sender: TObject);
: procedure FormClose(Sender: TObject; var Action: TCloseAction);
:
: procedure MessageLoop(var Msg:TMsg; var Handled:Boolean);
:
: private
: { Private declarations }
:
: public
: { Public declarations }
:
: end;
:
: var
: HTraining_F: THTraining_F;
:
: implementation
:
: uses Common_U, Main_U;
:
: {$R *.dfm}
:
: procedure THTraining_F.MessageLoop(var Msg: TMsg; var Handled: Boolean);
: Const
: DialogKeys : Set of Byte = [VK_RETURN];
: MSJVMClassName = 'MSAWT_Comp_Class'; // for Java Applets
: Var
: iOIPAO : IOleInPlaceActiveObject;
: Dispatch : IDispatch;
: Str : String;
: begin
: // WebBrowser의 도큐멘트 표시 부분의 핸들이 아닌 경우에는 무시
: if Msg.hwnd <> FWebHandle then Exit;
:
: if ((Msg.Message = WM_KEYDOWN) or (Msg.Message = WM_KEYUP)) and
: (Msg.wParam in DialogKeys) then Begin
: Handled:= IsDialogMessage(WebBrowser.Handle, msg) = True;
: SetLength(Str, MAX_PATH);
: GetClassName(Msg.hwnd, PChar(Str), MAX_PATH);
: SetLength (Str, StrLen (PChar(Str)));
: if (Msg.wParam = VK_DELETE) and (Str = MSJVMClassName) then
: else
: if Handled then
: if FOleInPlaceActiveObject <> Nil then
: FOleInPlaceActiveObject.TranslateAccelerator(Msg)
: else
: begin
: Dispatch := IDispatch(WebBrowser.Application);
: if Dispatch <> Nil then
: begin
: Dispatch.QueryInterface(IID_IOleInPlaceActiveObject, iOIPAO);
: if iOIPAO <> Nil then
: FOleInPlaceActiveObject := iOIPAO;
: end;
: end;
: end else Handled:= False;
: end;
:
: // FORM CREATE시 하는 작업들..
: procedure THTraining_F.FormCreate(Sender: TObject);
: begin
: self.Left := 125; self.top := 150;
:
: Application.OnMessage:= MessageLoop;
:
: WebBrowser1.Navigate('
http://www.amisnet.co.kr');
: end;
:
: // Form Close시에 하는 것들.
: procedure THTraining_F.FormClose(Sender: TObject; var Action: TCloseAction);
: begin
: Action := caFree;
: end;
:
: end.