#include "comdef.h"
#include "mshtml.h"
#include "mshtmcid.h"
#include "mshtmhst.h"
#include "exdisp.h"
#include "objbase.h"


void CMercuryFormView::OnHomepage()
{
// TODO: Add your command handler code here
//ShellExecute(0, _T("open"), _T("C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE"), _T("http://CarrotBoy.Net"), 0, SW_SHOWNORMAL);



HRESULT hr;
IWebBrowser2 *pWebBrowser = NULL;
VARIANT vtHeader2={0};
VARIANT vtTarget2={0};
VARIANT vtEmpty2={0};

vtHeader2.vt = VT_BSTR;
vtHeader2.bstrVal = SysAllocString(L"Content-Type: application/x-www-form-urlencoded\r\n");

vtTarget2.vt = VT_BSTR;
vtTarget2.bstrVal = SysAllocString(L"_top");

VariantInit(&vtEmpty2);

CoInitialize(NULL);
CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER,IID_IWebBrowser2, (void**)&pWebBrowser);

pWebBrowser->put_Width(800); // 가로 폭
pWebBrowser->put_Height(600); // 세로 폭
pWebBrowser->put_Left(0); // 외쪽 포인트
pWebBrowser->put_Top(0); // 오른쪽 포인트
pWebBrowser->put_ToolBar(VARIANT_FALSE); // 익스플로어 툴바 없앰
pWebBrowser->put_MenuBar(VARIANT_FALSE); // 메뉴바 없앰
pWebBrowser->put_AddressBar(VARIANT_FALSE); // 주소창 없앰
pWebBrowser->put_StatusBar(VARIANT_FALSE); // 상태바 없앰
pWebBrowser->put_Visible(VARIANT_TRUE);
HWND exh;
pWebBrowser->get_HWND((long*)&exh);
SetForegroundWindow();

hr = pWebBrowser->Navigate(SysAllocString(L"http://CarrotBoy.Net"), &vtEmpty2, &vtTarget2, &vtEmpty2, &vtHeader2);
//hr = pWebBrowser->Navigate(SysAllocString(L"www.daum.net"), &vtEmpty2, &vtTarget2, &vtEmpty2, &vtHeader2);
if(SUCCEEDED(hr))
{
//SetVisited(); // 제대로 갔다면 링크를 방문한 색깔로 바꿈
}
else // 오류시 메시지
{
/*
CString msg="HyperLink Error";
if(E_INVALIDARG == hr) msg+=": Invalid Parameters.";
else if(E_OUTOFMEMORY == hr) msg+=": Out of memory.";
MessageBeep(MB_ICONEXCLAMATION); // Unable to follow link
AfxMessageBox(msg, MB_ICONEXCLAMATION | MB_OK);
*/
}

SysFreeString(vtHeader2.bstrVal);
SysFreeString(vtTarget2.bstrVal);
pWebBrowser->Release();

CoUninitialize();

}
Posted by 장안동베짱e :