웹브라우저 컨트롤을 사용할 때, 프로그램에서 로드된 도큐먼트의 소스를 가져오고 싶을 때가 있다. 인터넷 익스플로러에서 `보기` / `소스` 를 했을 때처럼 말이다. 쉬울듯하나 그리 간단하지는 않다.

 

제일 쉬운방법은 IHTMLDocument3에 있는 documentElement 개체를 얻어다 이것의 OuterHTML 프로퍼티를 읽어오는 것이다. 제법 그럴듯한 게 나오므로 대부분의 경우 이 방법을 사용하면 문제가 없다. 단 하나의 문제는 여기에 나오는 것이 웹서버가 준 도큐먼트 소스가 아니라 인터넷 익스플로러의 HTML 파서가 한 번 파싱해 놓은 도큐먼트라는 것이다. 그래서 서버가 준 것과 똑 같은 도큐먼트를 얻고자 할 때는 사용할 수가 없다.

 

그래서 일반적으로 할 수 있는 방법은 IHTMLDocument2로부터 IPersistStreamInit을 얻어와서 이것의 Save() 메쏘드를 이용하는 것이다. 이걸 할려면 IStream 개체가 있어야 하는데 ::CreateStreamOnHGlobal()이라는 아주 훌륭한 넘으로 쉽게 맹글 수 있다. 처음엔 HGlobal을 만들고 위에 함수를 불렀는데, 읽어올 도큐먼트의 크기를 미리 알아야 한다는 문제가 있었다. 하지만 그냥 NULL을 ::CreateStreamOnHGlobal()에 넘겨주면 알아서 메모리를 할당하므로 크기를 알아올 필요가 없어져서 좋다. 내부 버퍼를 알아올라면 ::GetHGlobalFromStream()을 쓰면 된다.

 

MSDN 어딘가를 뒤져보며 있는데 위치를 까먹었다. ㅠㅠ

 

// 웹브라우저 컨트롤에서 가져화서 설정한다.

// 설정하는 방법은 다른데서 설명하기로 하자.

IHTMLDocument pDoc;

 

IStream * pStream = NULL;
IPersistStreamInit * pPSI = NULL;

HGLOBAL hHTMLContent;
HRESULT hr;
bool bResult = false;
BYTE* buff = NULL; // 여기다 소스를 담는다

 

hr = ::CreateStreamOnHGlobal(NULL, TRUE, &pStream);
if (SUCCEEDED(hr))
{
    // request the IPersistStreamInit interface
    hr = pDoc->QueryInterface(IID_IPersistStreamInit, (void **) &pPSI);
    if (SUCCEEDED(hr))
    {
        hr = pPSI->Save(pStream, FALSE);
        if (SUCCEEDED(hr))
        {
            hr = ::GetHGlobalFromStream(pStream, &hHTMLContent);
            if (SUCCEEDED(hr))
            {
                bResult = true;
                LPVOID data = ::GlobalLock(hHTMLContent);
                DWORD size = ::GlobalSize(hHTMLContent);
                buff = new BYTE[size + 1];
                ::memcpy(buff, data, size);
                buff[size] = '\0';
                ::GlobalUnlock(hHTMLContent);
            }
        }
        pPSI->Release();
    }
    // implicitly calls ::GlobalFree to free the global memory
    pStream->Release();
}

 =======================================================================================================
[다른방법]

홈페이지 소스 가져오기

//웹페이지 소스 가져오기
 IWebBrowser2* pBrowser2;

 HRESULT hr;

 hr=OleInitialize(NULL);

    if(!SUCCEEDED(hr))
        return FALSE;

 CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, IID_IWebBrowser2, (LPVOID *)&pBrowser2);

  
      BSTR bstrURL = SysAllocString(L"http://news.naver.com/sports/new/main/index.nhn");

    if(pBrowser2)
    {  
 
    VARIANT vEmpty;
       VariantInit(&vEmpty);

       hr = pBrowser2->Navigate(bstrURL, &vEmpty, &vEmpty, &vEmpty, &vEmpty);
    }


 IHTMLDocument2*  pHTMLDocument2;
 LPDISPATCH lpDispatch;
 pBrowser2->get_Document(&lpDispatch);


 

 CString szSource = "";

    if (lpDispatch)
 {
  HRESULT hr;
  hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&pHTMLDocument2);
  lpDispatch->Release();

  IHTMLElement*  pBody;
  hr = pHTMLDocument2->get_body(&pBody);

  BSTR bstr;              
  pBody->get_innerHTML(&bstr);

  int nLen;
  char* szTarget;
  nLen = (int)wcslen(bstr) * 2 + 1;
  szTarget = new char[nLen];
     ::WideCharToMultiByte(CP_ACP, 0, bstr, -1, szTarget, nLen, NULL, NULL );

  szSource.Format("%s", szTarget);

   
  SysFreeString(bstr);
  pBody->Release();

  delete szTarget;


 }

 pBrowser2->Quit();

 SysFreeString(bstrURL);
    pBrowser2->Release();

 OleUninitialize();


 

Posted by 모과이IT
,

// 주소 에디트 박스 핸들값으로 오는건 break를 걸어서 Dialog로 메시지를 보내고 아닌것은...
// SendAcceleratorToWeb함수를 이용해서 웹페이지로 보냄
// 힘들었음 이거 알아낸다고 ㅠ
// CEdit *hWndUrlAdress;

BOOL CNBrowserSetupCtrl::PreTranslateMessage(MSG* pMsg)
{
 // TODO: 여기에 특수화된 코드를 추가 및/또는 기본 클래스를 호출합니다.

 switch (pMsg->message)
 {
 case WM_KEYDOWN:
  if(GetKeyState(VK_CONTROL))
  {
   // 67 = 'c' , 86 = 'v'
   if(pMsg->wParam == 67)
   { 
    hWndUrlAdress = (CEdit*)NitsViewDlg.GetDlgItem(IDC_ADC);
    MyOutputDebugString("Ctrl Message [%d],[%d],[%d],[%d],[%d]",hWndUrlAdress->m_hWnd,pMsg->hwnd,pMsg->lParam,pMsg->message,pMsg->wParam);
    
    if(!(hWndUrlAdress->m_hWnd == pMsg->hwnd))
     return SendAcceleratorToWeb(pMsg);

    break;
   }
   if(pMsg->wParam == 86)
   {
    hWndUrlAdress = (CEdit*)NitsViewDlg.GetDlgItem(IDC_ADC);
    MyOutputDebugString("Ctrl Message [%d],[%d],[%d],[%d],[%d]",hWndUrlAdress->m_hWnd,pMsg->hwnd,pMsg->lParam,pMsg->message,pMsg->wParam);
    
    if(!(hWndUrlAdress->m_hWnd == pMsg->hwnd))
     return SendAcceleratorToWeb(pMsg);

    break;
   }
  }

 case WM_KEYUP:
  switch (pMsg->wParam)
  {
  case VK_TAB:
  case VK_RETURN:
   MyOutputDebugString("VK_TABffffffffffff");
   hWndUrlAdress = (CEdit*)NitsViewDlg.GetDlgItem(IDC_ADC);
   MyOutputDebugString("Ctrl Message [%d],[%d],[%d],[%d],[%d]",hWndUrlAdress->m_hWnd,pMsg->hwnd,pMsg->lParam,pMsg->message,pMsg->wParam);

   // urlAdress의 핸들값이 아니면 웹으로 키보스 마우스를 보내고
   // 아니면 urlAdress핸들로 키보스 메시지를 보낸다
   if(!(hWndUrlAdress->m_hWnd == pMsg->hwnd))
    return SendAcceleratorToWeb(pMsg);
   break;

  }
  break;
 }
 return COleControl::PreTranslateMessage(pMsg);
}

Posted by 모과이IT
,
다이얼로그 베이스의 프로그램에서 CComVariant 등의 ATL을 사용하는 방법입니다.

우선 Project -> Settings -> Link -> Object/library modules 로 가서
  Wininet.lib 를 추가합니다.

다음으로 stdafx.h 파일에 다음 헤더파일들을 인클루드해주면 됩니다.
#include <Mshtml.h>
#include <atlbase.h>

Posted by 모과이IT
,


BOOL CCarDealersBrowserCtrl::SendAcceleratorToWeb( MSG* pMsg )
{
 CComQIPtr<IOleInPlaceActiveObject, &IID_IOleInPlaceActiveObject> pIOIPAO(GetIWebBrowser2FromCWebBrowser2(WebDlgFormWnd->DlgWebBrowser.m_MyBrowser));

 HRESULT hr = S_FALSE ;
 //MyOutputDebugString("pIOIPAO 있음 ");
 if( pIOIPAO )
 {
  MyOutputDebugString("pIOIPAO 있음 ");
  hr = pIOIPAO->TranslateAccelerator(pMsg) ;
 }

 return ( hr == S_OK ?  TRUE : FALSE );
}

BOOL CCarDealersBrowserCtrl::PreTranslateMessage(MSG* pMsg)
{
 // TODO: 여기에 특수화된 코드를 추가 및/또는 기본 클래스를 호출합니다.
 switch (pMsg->message)
 {
 case WM_KEYDOWN:
 case WM_KEYUP:
  switch (pMsg->wParam)
  {
  case VK_TAB:
  case VK_RETURN:
   // TAB,ENTER 웹브라우저에서 안되는것을 처리
   MyOutputDebugString("VK_TAB");
   return SendAcceleratorToWeb(pMsg) ;

  }
  break;
 }
 return COleControl::PreTranslateMessage(pMsg);
}

Posted by 모과이IT
,

IDispatch* FindElement( REFIID riid, IDispatch* pDispBrowser )
{
 HRESULT hr;
 IHTMLDocument2* pHTMLDocument2;

 hr= pDispBrowser->QueryInterface( IID_IHTMLDocument2, (void**)&pHTMLDocument2 );
 if (hr != S_OK) return 0;

 IHTMLElementCollection* pColl;
 hr= pHTMLDocument2->get_all( &pColl );
 if (hr != S_OK) return 0;

 LONG celem;
 hr = pColl->get_length( &celem );
 if (hr != S_OK) return 0;

 for ( int i=0; i< celem; i++ ) {
  COleVariant varIndex( (long)i );
  COleVariant var2;
  IDispatch* pDisp;

  hr = pColl->item( varIndex, var2, &pDisp );
  if ( hr != S_OK ) {
   return 0;
  }
  IHTMLElement* pElem;
  //---------- see if this one is of the requested type...
  hr = pDisp->QueryInterface( riid, (void **)&pElem );
  if ( hr == S_OK ) {   // YES!
   pDisp->Release();
   return( pElem );
  }
  pDisp->Release();
 }
 return(0);
}


==========================================
실제로쓰기

CWebBrowser2* pBrowser= (CWebBrowser2*)GetDlgItem( IDC_PREVIEW_IKEA );


  IHTMLFrameBase* pFrameSetElem= (IHTMLFrameBase*)FindElement(
   IID_IHTMLFrameBase, pBrowser->GetDocument()
   );

Posted by 모과이IT
,

이 소스로 모든 ie의 인터페이스를 컨트롤 할수있다. (조금만 응용하면)

Posted by 모과이IT
,

ActiveX 자동 업데이트 하는 방법

1. 프로젝트 리소스의 VERSIONINFO 리소스의 버전 정보를 수정한다.
 
  이때 FILEVERSION 과 PRODUCTVERSION 은 일치하는 것이 좋으며 버전정보는 , 로 구분되는 숫자 4개로 이루어져야함.
  예). 1,2,3,4
 
2. CAB 파일을 만들기 위한 INF를 작성한다.
 
  이때도 INF 에 버전정보를 적는데 VERSIONINFO 에 적은 버전정보와 같은 형식으로 , 로 구분하여 적는다.

  예).
 
  [TEST.ocx]
  file-win32-x86=thiscab
  ; *** add your controls CLSID here ***
  clsid={4132944C-862D-463F-BB47-ABF99043AB1C}
  ; Add your ocx's file version here.
  FileVersion=1,0,1,3
  RegisterServer=yes
 
3. CAB 파일을 생성 후 서버에 업로드 후 ActiveX 를 참조 하는 OBJECT 태그의 버전정보를 수정한다.

  이때 역시 버전정보는 , 로 구분되는 숫자 4개여야 함.

  예)
  <OBJECT id=Service classid="CLSID:3201944C-862D-463F-BB47-ABF99043AB1C" codebase="/Include/AutoUPOCX.CAB#version=1,0,1,3" width="0" height="0" type="application/x-oleobject">
  </OBJECT>
 
  따라서, 편한 버전 업데이트를 위해서는 ActiveX 를 참조하는 OBJECT 태그를 별도의 스크립트 파일로 분리하여 Include 하는 것이 관리하는데 도움을 줄 수 있음
 
 
4. IE는 서버에 새번이 있더라도 페이지에서 구버전을 요청하면 업데이트를 시행하지 않으므로 OBJECT 태그의 버전정보를 반드시 새버전으로 변경해야한다.

  또한, 구버전이 이미 로딩된 상태로 다음 페이지에서 새버전을 요구하면 업데이트 할 때 재부팅을 요구할 수 있으므로 반드시 ActiveX 가 처음 사용되는 페이지의 버전정보를 변경한다.

Posted by 모과이IT
,

클라이언트 어플리케이션을 작성하다 보면 웹 페이지를 어플리케이션 내에서 호스팅 해야 할 경우가 생긴다. 이럴 경우 키보드의 단축키를 어플리케이션 내에서 먼저 잡아서 처리하므로 웹 페이지에서는 단축키가 안 먹는다. 대표적으로 Tab, Delete, Return, Ctrl+A, Ctrl+C, Ctrl+X, Ctrl+V 등이 있다.
웹 페이지만 따로 띄워서 보면 위의 키들이 다 잘 작동하나 어플리케이션 내에서 웹 페이지를 호스팅 하는 경우는 많이 사용하는 키임에도 불구하고 작동을 하지 않는다. 이럴 경우에는 어플리케이션의 PreTranslateMessage에서 웹 페이지로 단축키를 넘겨주면 된다.

virtual BOOL PreTranslateMessage(MSG* pMsg)
 {
  if( pMsg->message == WM_KEYDOWN )
  {
   TRACEMSG(1, _T("KeyDown: 0x%x"), pMsg->wParam) ;
   if ( pMsg->wParam == VK_DELETE || pMsg->wParam == VK_TAB || pMsg->wParam == VK_RETURN)
   {
    return SendAcceleratorToWeb(pMsg) ;
   }

   if( pMsg->wParam == 'A' || pMsg->wParam == 'C' || pMsg->wParam == 'X' || pMsg->wParam == 'V' )
   {
    // Ctrl 키가 눌러져 있다면... 다른 키의 조합은 & 으로 하면 된다.
    // GetKeyState( VK_CONTROL & VK_SHIFT )

    if( GetKeyState( VK_CONTROL ) < 0 )
     return SendAcceleratorToWeb(pMsg);
   }
  }

  return CWindow::IsDialogMessage(pMsg) ;
 }

 BOOL SendAcceleratorToWeb( MSG* pMsg )
 {
  CComQIPtr<IOleInPlaceActiveObject, &IID_IOleInPlaceActiveObject> pIOIPAO(m_spWebBrowser) ;

  HRESULT hr = S_FALSE ;

  if( pIOIPAO )
  {
   hr = pIOIPAO->TranslateAccelerator(pMsg) ;
  }

  return ( hr == S_OK ?  TRUE : FALSE );
 }


Posted by 모과이IT
,
// ===========================================================================
// File: W I N S I N K . H
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright 1995-1999 Microsoft Corporation.  All Rights Reserved.
#ifndef _WinSink_h_
#define _WinSink_h_
#include <comdef.h>
#include <afxpriv.h>
#include <mshtml.h>
#include <mshtmdid.h>
class CWinSink : public IDispatch
{
public:
    CWinSink() : m_pWin(NULL), m_dwRef(1),
            m_hrConnected(CONNECT_E_CANNOTCONNECT),
            m_dwCookie(0), m_pCP(NULL)
    {
    }
    ~CWinSink()
    {
    }
    HRESULT Init(IHTMLElementPtr pWin);
    HRESULT Passivate()
    {
        HRESULT hr = NOERROR;
        if (m_pCP)
        {
            if (m_dwCookie)
            {
                hr = m_pCP->Unadvise(m_dwCookie);
                m_dwCookie = 0;
            }
             m_pCP->Release();
             m_pCP = NULL;
        }
        if (m_pWin)
        {
            m_pWin->Release();
            m_pWin = NULL;
        }
        return NOERROR;
    }
    // IUnknown methods
    STDMETHOD(QueryInterface)(REFIID riid, LPVOID* ppv);
    STDMETHOD_(ULONG, AddRef)();
    STDMETHOD_(ULONG, Release)();
    // IDispatch method
    STDMETHOD(GetTypeInfoCount)(UINT* pctinfo)
            { ODS("GetTypeInfoCount\n" ); return E_NOTIMPL; }
    STDMETHOD(GetTypeInfo)(UINT iTInfo,
            LCID lcid,
            ITypeInfo** ppTInfo)
            { ODS("GetTypeInfo\n" ); return E_NOTIMPL; }
    STDMETHOD(GetIDsOfNames)(REFIID riid,
            LPOLESTR* rgszNames,
            UINT cNames,
            LCID lcid,
            DISPID* rgDispId)
            { ODS("GetIDsOfNames\n" ); return E_NOTIMPL; }
        
    STDMETHOD(Invoke)(DISPID dispIdMember,
            REFIID riid,
            LCID lcid,
            WORD wFlags,
            DISPPARAMS __RPC_FAR *pDispParams,
            VARIANT __RPC_FAR *pVarResult,
            EXCEPINFO __RPC_FAR *pExcepInfo,
            UINT __RPC_FAR *puArgErr);
protected:
    IHTMLElementPtr m_pWin;
    DWORD m_dwRef;
    LPCONNECTIONPOINT m_pCP;
    HRESULT m_hrConnected;
    DWORD m_dwCookie;
};
#endif

//===================
// ===========================================================================
// File: W I N S I N K . C P P
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
//
//    - CWinSink implements a simple object that traps MSHTML window events such as window::onload.
//    DHTML authors simply do the following in an HTML page:
//        function window_load()
//        {
//           alert("window::onload fired" );
//        }
//
//        window.onload = window_load;
//
//    C++ developers do the following: 
//        Instantiate a host object that implements IDispatch
//        QI an interface exposed by MSHTML for IConnectionPointContainer (ICPC)
//        Request a specific connection point via ICPC
//        Call Advise on the connect point, passing a reference to the host object
//
//        MSHTML will call the host's IDispatch::Invoke implementation when an event occurs.
//  
//  - For a complete list of window events see dispinterface HTMLWindowEvents2 in mshtml.idl.
//
// Copyright 1995-1999 Microsoft Corporation.  All Rights Reserved.
#include "StdAfx.h"
//#include <windows.h>
#include <mshtml.h>
#include <mshtmdid.h>
#include "winsink.h"
#include <iostream.h>
HRESULT CWinSink::Init(IHTMLElementPtr pWin)
{
    HRESULT hr = NOERROR;
    LPCONNECTIONPOINTCONTAINER pCPC = NULL;
    if (m_pWin)
    {
        m_pWin->Release();
    }
    m_pWin = pWin;
    if (FAILED(hr = pWin->QueryInterface(IID_IConnectionPointContainer, (LPVOID*)&pCPC)))
    { 
        goto Error;
    }
    //if (FAILED(hr = pCPC->FindConnectionPoint(DIID_HTMLElementEvents2, &m_pCP)))
    //if (FAILED(hr = pCPC->FindConnectionPoint(DIID_HTMLButtonElementEvents, &m_pCP)))
    if (FAILED(hr = pCPC->FindConnectionPoint(DIID_HTMLAnchorEvents, &m_pCP)))
    {
        goto Error;
    }
    m_hrConnected = m_pCP->Advise((LPUNKNOWN)this, &m_dwCookie);
Error:
    if (pCPC) pCPC->Release();
    return hr;
}
STDMETHODIMP CWinSink::QueryInterface(REFIID riid, LPVOID* ppv)
{
    *ppv = NULL;
    if (IID_IUnknown == riid)
    {
        *ppv = (LPUNKNOWN)this;
        AddRef();
        return NOERROR;
    }
    else if (IID_IDispatch == riid)
    {
        *ppv = (IDispatch*)this;
        AddRef();
        return NOERROR;
    }
    else
    {
        OLECHAR wszBuff[39];
        int i = StringFromGUID2(riid, wszBuff, 39);
        TCHAR szBuff[39];
        i = WideCharToMultiByte(CP_ACP, 0, wszBuff, -1, szBuff, 39, NULL, NULL);
        ODS("CWinSink QI: " ); ODS(szBuff); ODS("\n" );
        return E_NOTIMPL;
    }
}
STDMETHODIMP_(ULONG) CWinSink::AddRef()
{
    TCHAR szBuff[255];
    wsprintf(szBuff, "CWinSink refcount increased to %d\n" , m_dwRef+1);
    ODS(szBuff);
    return ++m_dwRef;
}
STDMETHODIMP_(ULONG) CWinSink::Release()
{
    TCHAR szBuff[255];
    if (--m_dwRef == 0) 
    { 
        ODS("Deleting CWinSink\n" );
        delete this; 
        return 0; 
    }
    wsprintf(szBuff, "CWinSink refcount reduced to %d\n" , m_dwRef);
    ODS(szBuff);
    return m_dwRef;
}
// OA events are fired through the IDispatch::Invoke of the sink object
STDMETHODIMP CWinSink::Invoke(DISPID dispIdMember,
            REFIID riid,
            LCID lcid,
            WORD wFlags,
            DISPPARAMS __RPC_FAR *pDispParams,
            VARIANT __RPC_FAR *pVarResult,
            EXCEPINFO __RPC_FAR *pExcepInfo,
            UINT __RPC_FAR *puArgErr)
{
    if (!pVarResult)
    {
        return E_POINTER;
    }
    if( pDispParams->cArgs != 0 )
        IHTMLEventObjPtr pEvtObj = pDispParams->rgvarg[0].pdispVal;
    switch(dispIdMember)
    {
    case DISPID_HTMLELEMENTEVENTS_ONCLICK:
        {
        /*
            IHTMLEventObjPtr pEvtObj = pDispParams->rgvarg[0].pdispVal;
        IHTMLElementPtr pElem;
        pEvtObj->get_srcElement(&pElem);
        pElem->toString( &bstStr );
        */
        BSTR bstStr;
        m_pWin->toString(&bstStr);
        
        _bstr_t bsStr(bstStr);
        MessageBox(NULL,"OnClick" ,(LPCTSTR)bsStr,MB_OK);
        }
        break;
    default:
        return DISP_E_MEMBERNOTFOUND;
    }
    return NOERROR;
}
//===================

#include <mshtml.h>
#include <mshtmdid.h>
#include "winsink.h"
void CTestEventIEDlg::OnSink() 
{
    // TODO: Add your control notification handler code here
    //CWebBrowser2* pBrowser = (CWebBrowser2*)GetDlgItem( IDC_EXPLORER1 );
    
    IDispatchPtr pDisp = m_web.GetDocument();
    if (pDisp != NULL )
    {
        IHTMLDocument2Ptr pHTMLDocument2;
        HRESULT hr;
        hr = pDisp->QueryInterface( IID_IHTMLDocument2, (void**)&pHTMLDocument2 );
        if (hr == S_OK)
        {
            IHTMLElementCollectionPtr pColl;
            hr = pHTMLDocument2->get_all( &pColl );
            if (hr == S_OK)
            {
                VARIANT varIndex;
                varIndex.vt = VT_BSTR;
                varIndex.bstrVal = _bstr_t("item1" );
                VARIANT var2;
                VariantInit( &var2 );
                IDispatch* pDisp;
                hr = pColl->item( varIndex, var2, &pDisp );
                if ( hr == S_OK )
                {
                    IHTMLElementPtr pElem;
                    hr = pDisp->QueryInterface( IID_IHTMLElement, (void **)&pElem );
                    if ( hr == S_OK )
                    {
                        m_sink.Init(pElem);
                    }
                }
            }
        }
    }
    
}
Posted by 모과이IT
,
CWebBrowser2 (웹브라우저) 컨트롤에서 스크롤바 없애기  윤덕근 / yunskorea  

#include <mshtml.h>

CWebBrowser2 m_ctlWebBrowser; 라고 되어 있을때....

Class Wizard에서...
웹브라우저 컨트롤의 Message중 DocumentComplete에 대한 멤버함수 추가 후, 아래와 같이 작성하면 됩니다.


void CWebDlg::OnDocumentCompleteBrowser(LPDISPATCH pDisp, VARIANT FAR* URL) 
{
IDispatch *pDisp2 = m_ctlWebBrowser.GetDocument();

CString strOption = _T("no" );   // yes no auto

if (pDisp2 != NULL)
{
IHTMLDocument2* pHTMLDocument2;
HRESULT hr;
hr = pDisp2->QueryInterface(IID_IHTMLDocument2, (void**)&pHTMLDocument2);

if (hr == S_OK)
{
IHTMLElement *pIElement;
hr = pHTMLDocument2->get_body(&pIElement);

IHTMLBodyElement *pIBodyElement;
hr = pIElement->QueryInterface(IID_IHTMLBodyElement, (void**)&pIBodyElement);

BSTR bstr;
bstr = strOption.AllocSysString();
pIBodyElement->put_scroll(bstr);
}
pDisp2->Release ();
}   
}

Posted by 모과이IT
,