소스파일입니다.


우선..
"stdafx.h" 파일을 만들고
==================================================================
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once


#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

#ifndef DWORD
#define DWORD unsigned long
#endif
// TODO: reference additional headers your program requires here
==================================================================
를 써줍니다.

다음.. 소스가 들어갈 파일..
파일명은 "LaunchBrowser.cpp" 로 해줍니다.
==================================================================

#include "stdafx.h"
#include <comutil.h>
#include <exdisp.h>
#include <process.h>    /* _beginthread, _endthread */
#include <stddef.h>

#pragma comment(lib, "comsupp.lib")

// Get a string from the registry
BOOL GetRegistryString(HKEY rootKey, const char *pzPath, const char *pzKey, char *zBuf, int nBufSize)
{
  HKEY hKey = NULL;
  LONG lReturnValue = RegOpenKeyEx (rootKey, pzPath, 0L, KEY_QUERY_VALUE, &hKey);
  if(lReturnValue != ERROR_SUCCESS)
    return FALSE;
  DWORD dwType = 0;
  DWORD dwSize = nBufSize;
  lReturnValue = RegQueryValueEx (hKey, pzKey, NULL, &dwType, (BYTE *) zBuf, &dwSize);
  RegCloseKey (hKey);
  if (lReturnValue != ERROR_SUCCESS)
    return FALSE;
  return TRUE;
}

// Determine if the version of MSIE is version 7
BOOL IsIE7()
{
  char szVersion[128];
  BOOL bRet = GetRegistryString(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Internet Explorer", "Version", szVersion, sizeof(szVersion));
  if (bRet == TRUE && szVersion[0] == '7')
    return TRUE;
  return FALSE;
}

// simple data structure for our browser settings
typedef struct
{
  char zUrl[1024];
  int nWidth;
  int nHeight;
 HICON hIcon;
}BROWSER_INFO;

BROWSER_INFO g_BrowserInfo;

// This thread demonstrates how to initialize OLE such that we have an exclusive COM apartment for this
// thread separate from the main thread.
//
// It also shows how to manipulate the IWebBrowser interface to do some interesting things such as:
//   1.  Make the IE window resizable or static (non-resizable) based on IE version number.
//  2.  Turn off the address bar, menu bar, status bar, and tool bar buttons.
//  3.  Set the width and height of the resulting window.
//  4.  Change the icon of the MSIE window to one of your own.
//
void BrowserThread( void* pParams )
{
  OleInitialize(NULL);
  BROWSER_INFO *pBrowserInfo = (BROWSER_INFO *)pParams;
   IWebBrowser2* m_pInetExplorer;

    HRESULT hr;
  HICON hIcon;
    CLSID clsid;
    LPUNKNOWN punk=NULL;
    CLSIDFromProgID (OLESTR("InternetExplorer.Application"), &clsid);
    hr = CoCreateInstance (clsid, NULL, CLSCTX_SERVER, IID_IUnknown, (LPVOID *) &punk);
    if (SUCCEEDED(hr))
   {
    punk->QueryInterface (IID_IWebBrowser2, (LPVOID *) &m_pInetExplorer);
    punk->Release();
    VARIANT vars[4];
        memset(vars,0,sizeof(vars));
        BSTR BStrURL = _com_util::ConvertStringToBSTR((const char *)(pBrowserInfo->zUrl));
    if (IsIE7())
      m_pInetExplorer->put_Resizable(VARIANT_TRUE);
    else
      m_pInetExplorer->put_Resizable(VARIANT_FALSE);
        m_pInetExplorer->put_ToolBar(FALSE);
        m_pInetExplorer->put_AddressBar(VARIANT_FALSE);
        m_pInetExplorer->put_MenuBar(VARIANT_FALSE);
        m_pInetExplorer->put_StatusBar(VARIANT_FALSE);
        m_pInetExplorer->put_Width(pBrowserInfo->nWidth);
        m_pInetExplorer->put_Height(pBrowserInfo->nHeight);

        m_pInetExplorer->put_Visible(VARIANT_TRUE);
        HRESULT hrie = m_pInetExplorer->Navigate(BStrURL,vars,vars+1,vars+2,vars+3);
        SysFreeString(BStrURL);
    if (SUCCEEDED(hrie))
    {
      VARIANT_BOOL bBusy = VARIANT_TRUE;
      while(bBusy == VARIANT_TRUE)
      {
        Sleep(500);
        m_pInetExplorer->get_Busy(&bBusy);
      }
       HWND hWnd = NULL;
      m_pInetExplorer->get_HWND ((long*)(&hWnd));
      if (IsWindow(hWnd) && pBrowserInfo->hIcon != NULL)
      {
        hIcon = pBrowserInfo->hIcon;
        SendMessage(hWnd, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hIcon);
      }
  // Do other interesting IE stuff here while the window is valid.
  //   while(IsWindow(hWnd))
  //   {
  //     Sleep(500);
  //     m_pInetExplorer->get_HWND ((long*)(&hWnd));
  //   }
    }
    m_pInetExplorer->Release();
   }
    OleUninitialize();
  // thread exiting.
}

/*
 * Spawn the M browser
 */
void spawn_browser(
  const char *uri, // URL
  int nWidth,    // Window Width
  int nHeight,   // Window Height
 HICON hIcon)   // Handle to the icon
{
  g_BrowserInfo.nWidth = nWidth;
  g_BrowserInfo.nHeight = nHeight;
  memset(g_BrowserInfo.zUrl,0,(sizeof(g_BrowserInfo.zUrl)*sizeof(char)));
  strncpy(g_BrowserInfo.zUrl,uri,min(strlen(uri),(sizeof(g_BrowserInfo.zUrl)*sizeof(char))));
  g_BrowserInfo.hIcon = hIcon;
  HANDLE hThread = (HANDLE) _beginthread( BrowserThread, 0, &g_BrowserInfo );

  // Wait until IE is done loading before we return.
    WaitForSingleObject( hThread, INFINITE );
}

==================================================================

해줍니다..

구조상...
spawn_browser으로 구동시키며,
이거 쓰레드를 사용합니다... 허...
어쨋든..

spawn_browser("http://www.codeproject.com", 800, 600, hIcon);
식으로 쓰면, codeproject.com 웹을  800,600 크기, hIcon 이미지를 가진 대화상자를 만들어
거기에 띄워줍니다.

음...
이거.. 소스찾는데 애먹었습니다..허.. 조금만 수정하면 다용도로 사용가능할꺼 같네요

블로그 이미지

프로그래머 지향자 RosaGigantea

바쁜 일상 생활중의 기억 장소