첨부된 소스 참고하세요
신철우 님이 쓰신 글 :
: 류종택님 답변을 주셔서 감사합니다. 류종택 님이 쓰신 글대로 해보면
: MessageLoop에서 에러가 수북히 나는데[아래 참조]
: declaration 'MessageLoop' differs from previous declaration.
: Undeclared identifier : 'IOleInPlaceActiveObject'
: Undeclared identifier : 'FWebHandle' - private에 선언했는데도 ?
: Comparing signed and unsigned types - widened both operands
: object or class type required
: Undeclared identifier : 'FOleInPlaceActiveObject'
: .
: .
:
: 목적은 델파이의 webbrowser을 이용하여 웹서버에 접속해서
: textarea로 업데이트를 하려는데 이 textarea내에서 엔터키로 줄바꿈이 일어나지 않는 문제를 해결하려는 것입니다.
: 그런데 아래 방법으로 하는 것이 맞는 것인지, 맞다면 uses에 추가해야할 요소가 더 있는지,
: 에러가 안나게 자세히 부탁드립니다.(다른 사람들은 웹브라우저에서 단순히 조회만 하고 입력이나 수정은 안하는지
: 궁금하네요.)
:
: [소스 시작]
: 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 WebBrowser1NavigateComplete2(Sender: TObject;
: const pDisp: IDispatch; var URL: OleVariant);
: procedure MessageLoop(var Msg:TMsg; var Handled:Boolean);
:
: private
: { Private declarations }
: FWebHandle : Integer;
:
: 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;
:
: FWebHandle := 0;
: WebBrowser1.Navigate('
http://www.irumi.ac/intro_update.php');
: Application.OnMessage:= MessageLoop;
: end;
:
: // Form Close시에 하는 것들.
: procedure THTraining_F.FormClose(Sender: TObject; var Action: TCloseAction);
: begin
: Action := caFree;
: end;
:
: procedure THTraining_F.WebBrowser1NavigateComplete2(Sender: TObject;
: const pDisp: IDispatch; var URL: OleVariant);
: begin
: if FWebHandle = 0 then Begin
: FWebHandle:= FindWindowEx(WebBrowser1.Handle, 0, 'Shell DocObject View', Nil);
: FWebHandle:= FindWindowEx(FWebHandle, 0, 'Internet Explorer_Server', Nil);
: end;
: end;
:
: end.
: [소스 끝]
:
: 류종택 님이 쓰신 글 :
: : 웹브로우져의 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;