Programming - cpueblo.com

Post 방식으로 전달하는 Internet Explorer 열기


Post 방식으로 인터넷 익스플러를 오픈하는 방법 & C++ Builder 에서 Delphi 소스를 활용하는 방법입니다

글쓴이 : 유광희 날짜 : 2007-05-29 (화) 14:43 조회 : 21754
Post 방식으로 인터넷 익스플러를 오픈하는 방법 & C++ Builder 에서 Delphi 소스를 활용하는 방법입니다

보고 배울점!

1. Post 방식으로 인터넷 익스플러를 오픈하는 방법을 소개합니다.
2. C++ Builder 에서 .PAS 파일을 컴파일 하여 유닛으로 활용하는 방법을 소개합니다.
3. Delphi 에서 IE OLE 객체를 생성하는 방법을 소개합니다.

1. PostInternetExplorer.pas 를 프로젝트에 추가

------------------------PostInternetExplorer.pas---------------------------------------------------

Unit PostInternetExplorer;

Interface

uses
    Windows, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Dialogs, ComObj, StdCtrls, ExtCtrls;

type TPostInternetExplorer = class(TObject)
    private
    public
        procedure PostRequest(const Url, Params: string);
end;


Implementation


procedure TPostInternetExplorer.PostRequest(const Url, Params: string);
var
  I: Integer;
  vUrl: OleVariant;
  vFlag: OleVariant;
  PostData: OleVariant;
  Headers: OleVariant;
  IE: Variant;
begin
  PostData := VarArrayCreate([0, Length(Params) - 1], varByte);
  for I := 1 to Length(Params) do  PostData[I-1] := Ord(Params[I]);
  Headers := 'Content-Type: application/x-www-form-urlencoded' + #10#13;
  try
  IE := CreateOleObject('InternetExplorer.Application');
  except
  // 익스플로러 실행 실패
  Exit;
  end;
  IE.Visible := true;
  SetWindowPos(IE.HWND, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE);
  SetWindowPos(IE.HWND, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE);
  {
  IE.ToolBar := false;   IE.Resizable := false;   IE.TheaterMode := true;
  IE.Left := 300; IE.Top := 300; IE.Width := 350; IE.Height := 385;
  }
  vUrl := Url;
  vFlag := EmptyParam;  //1 or 4 or 8;
  IE.Navigate2(vUrl, vFlag, EmptyParam, PostData, Headers);
  IE := Unassigned;
end;

end.


---------------------------------------------------------------------------------------------------

2. PostInternetExplorer.hpp 파일이 컴파일 후 생성

PostInternetExplorer.hpp 는 위 pas 파일을 프로젝트에
넣고 컴파일을 하게 되면 자동으로 생성되는 파일 입니다.
이외 DCU 파일도 함께 생성됩니다.

------------------------PostInternetExplorer.hpp---------------------------------------------------
// Borland C++ Builder
// Copyright (c) 1995, 2002 by Borland Software Corporation
// All rights reserved

// (DO NOT EDIT: machine generated header) 'PostInternetExplorer.pas' rev: 6.00

#ifndef PostInternetExplorerHPP
#define PostInternetExplorerHPP

#pragma delphiheader begin
#pragma option push -w-
#pragma option push -Vx
#include     // Pascal unit
#include     // Pascal unit
#include     // Pascal unit
#include     // Pascal unit
#include <Forms.hpp>    // Pascal unit
#include     // Pascal unit
#include     // Pascal unit
#include     // Pascal unit
#include     // Pascal unit
#include     // Pascal unit
#include     // Pascal unit
#include     // Pascal unit
#include     // Pascal unit

//-- user supplied -----------------------------------------------------------

namespace Postinternetexplorer
{
//-- type declarations -------------------------------------------------------
class DELPHICLASS TPostInternetExplorer;
class PASCALIMPLEMENTATION TPostInternetExplorer : public System::TObject
{
    typedef System::TObject inherited;

public:
    void __fastcall PostRequest(const AnsiString Url, const AnsiString Params);
public:
    #pragma option push -w-inl
     inline __fastcall TPostInternetExplorer(void) : System::TObject() { }
    #pragma option pop
    #pragma option push -w-inl
     inline __fastcall virtual ~TPostInternetExplorer(void) { }
    #pragma option pop

};


//-- var, const, procedure ---------------------------------------------------

}    
using namespace Postinternetexplorer;
#pragma option pop    // -w-
#pragma option pop    // -Vx

#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif    // PostInternetExplorer
---------------------------------------------------------------------------------------------------

3. PostInternetExplorer.hpp 를 이용하여 호출하기

------------------------frmExample.cpp-------------------------------------------------------------
#include "PostInternetExplorer.hpp"

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TPostInternetExplorer *pExplorer = new TPostInternetExplorer;
    pExplorer->PostRequest("http://cpueblo.com/phpinfo.php", "post_arg1=merong&post_arg2=haha&post_arg3=haha");
    delete pExplorer;

}
//---------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------

예제와 소스 다운로드

다운로드

작성자

http://cpueblo.com

유광희

Downloads

  • PostInternetExplorer.zip

  •