#include "windows.h"
#include <WINUSER.H>
#pragma comment(lib, "user32.lib")
#include <INITGUID.H>
#include <MSHTMHST.H>
#include <exdisp.h>
#pragma comment(lib, "ole32.lib")
#include "COMMDLG.H"
#pragma comment(lib, "comdlg32.lib")
#include <commctrl.h>
#pragma comment(lib, "comctl32.lib")
struct IOleClientSiteVtbl hIOCS;
struct IOleInPlaceSiteVtbl hIOPS;
struct IOleInPlaceFrameVtbl hIOPF;
struct IOleCommandTargetVtbl hIOCT;
struct IDocHostUIHandlerVtbl hIDHU;
struct IOleClientSiteVtbl* pIOleClientSite;
struct IOleInPlaceSiteVtbl* pIOleInPlaceSite;
struct IOleInPlaceFrameVtbl* pIOleInPlaceFrame;
struct IOleCommandTargetVtbl* pIOleCommandTarget;
struct IDocHostUIHandlerVtbl* pIDocHostUIHandler;
struct IOleObject* ppvWebBrowser;
struct IOleWebBrowser
{
HWND hwndParent;
RECT lprcPosRect;
};
struct IOleWebBrowser hMem;
IWebBrowser2* ppvWebObject;
HWND hHtmlWin;
#define DLG_WEBBROWER 100
#define IDW_BROW 2000
#define IDI_ICON 100
HRESULT STDMETHODCALLTYPE IOleClientSite_AddRef(IOleClientSite* This)
{
return 1;
}
HRESULT STDMETHODCALLTYPE IOleClientSite_QueryInterface(IOleClientSite* This, REFIID riid, void** ppvObject)
{
if (!memcmp(riid, &IID_IOleInPlaceSite, sizeof(GUID)))
{
*ppvObject = &pIOleInPlaceSite;
}
else if (!memcmp(riid, &IID_IOleClientSite, sizeof(GUID)))
{
*ppvObject = &pIOleClientSite;
}
else if (!memcmp(riid, &IID_IDocHostUIHandler, sizeof(GUID)))
{
*ppvObject = &pIDocHostUIHandler;
return S_OK;
}
else
{
*ppvObject = 0;
return(E_NOINTERFACE);
}
return S_OK;
}
HRESULT STDMETHODCALLTYPE IOleClientSite_Release(IOleClientSite* This)
{
return 1;
}
HRESULT STDMETHODCALLTYPE IOleClientSite_SaveObject(IOleClientSite* This)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE IOleClientSite_GetMoniker(IOleClientSite* This, DWORD dwAssign, DWORD dwWhichMoniker,IMoniker ** ppmk)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE IOleClientSite_GetContainer(IOleClientSite* This, LPOLECONTAINER* ppContainer)
{
return E_NOINTERFACE;
}
HRESULT STDMETHODCALLTYPE IOleClientSite_ShowObject(IOleClientSite* This)
{
return 0;
}
HRESULT STDMETHODCALLTYPE IOleClientSite_OnShowWindow(IOleClientSite* This, BOOL fShow)
{
return 0;
}
HRESULT STDMETHODCALLTYPE IOleClientSite_RequestNewObjectLayout(IOleClientSite* This)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceSite_AddRef(IOleInPlaceSite *This)
{
return 1;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceSite_Release(IOleInPlaceSite *This)
{
return 1;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceSite_QueryInterface(IOleInPlaceSite FAR* This, REFIID riid, LPVOID FAR* ppvObject)
{
if (ppvObject)
{
if (0==memcmp(riid, &IID_IOleCommandTarget, sizeof(GUID)))
{
*ppvObject = &pIOleCommandTarget;
return 0;
}
else if (!memcmp(riid, &IID_IOleClientSite, sizeof(GUID)))
{
*ppvObject = &pIOleClientSite;
}
else
{
*ppvObject = 0;
return E_NOINTERFACE;
}
}
return E_POINTER;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceSite_ContextSensitiveHelp(IOleInPlaceSite* This, BOOL fEnterMode)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceSite_CanInPlaceActivate(IOleInPlaceSite* This)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceSite_OnInPlaceActivate(IOleInPlaceSite* This)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceSite_GetWindow(IOleInPlaceSite* This, HWND* lphwnd)
{
*lphwnd = hMem.hwndParent;
return S_OK;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceSite_GetWindowContext(IOleInPlaceSite* This,
IOleInPlaceFrame** ppFrame,
IOleInPlaceUIWindow** ppDoc,
LPRECT lpRect,
LPRECT lprcClipRect,
LPOLEINPLACEFRAMEINFO lpFrameInfo)
{
*ppDoc = 0;
lpFrameInfo->fMDIApp = FALSE;
lpFrameInfo->hwndFrame = hMem.hwndParent;
lpFrameInfo->haccel = 0;
lpFrameInfo->cAccelEntries = 0;
return S_OK;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceSite_OnUIActivate(IOleInPlaceSite* This)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceSite_Scroll(IOleInPlaceSite* This, SIZE scrollExtent)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceSite_OnUIDeactivate(IOleInPlaceSite* This, BOOL fUndoable)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite* This)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceSite_DiscardUndoState(IOleInPlaceSite* This)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceSite_DeactivateAndUndo(IOleInPlaceSite* This)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceSite_OnPosRectChange(IOleInPlaceSite* This, LPCRECT lpRect)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceFrame_AddRef(IOleInPlaceFrame *This)
{
return 1;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceFrame_QueryInterface(IOleInPlaceFrame * This, REFIID riid, void **ppvObject)
{
struct IOleInPlaceFrameVtbl* pIOleInPlaceFrame=&hIOPF;
if ((!memcmp(riid, &IID_IUnknown, sizeof(GUID)) || (!memcmp(riid, &IID_IOleInPlaceFrame, sizeof(GUID)))))
{
*ppvObject = &pIOleInPlaceFrame;
IOleInPlaceFrame_AddRef(This);
}
else if (!memcmp(riid, &IID_IOleClientSite, sizeof(GUID)))
{
*ppvObject = &pIOleClientSite;
}
else
{
*ppvObject = 0;
return(E_NOINTERFACE);
}
return S_OK;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceFrame_Release(IOleInPlaceFrame *This)
{
return 1;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceFrame_GetWindow(IOleInPlaceFrame* This,HWND* phwnd)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame* This, BOOL fEnterMode)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceFrame_GetBorder(IOleInPlaceFrame* This, LPRECT lprectBorder)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceFrame_RequestBorderSpace(IOleInPlaceFrame* This, LPCBORDERWIDTHS pborderwidths)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceFrame_SetBorderSpace(IOleInPlaceFrame* This, LPCBORDERWIDTHS pborderwidths)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceFrame_SetActiveObject(IOleInPlaceFrame* This, IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceFrame_InsertMenus(IOleInPlaceFrame* This, HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceFrame_SetMenu(IOleInPlaceFrame* This, HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceFrame_RemoveMenus(IOleInPlaceFrame* This, HMENU hmenuShared)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceFrame_SetStatusText(IOleInPlaceFrame* This, LPCOLESTR pszStatusText)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceFrame_EnableModeless(IOleInPlaceFrame* This, BOOL fEnable)
{
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE IOleInPlaceFrame_TranslateAccelerator(IOleInPlaceFrame* This, LPMSG lpmsg, WORD wID)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE IOleCommandTarget_AddRef(IOleCommandTarget *This)
{
return 1;
}
HRESULT STDMETHODCALLTYPE IOleCommandTarget_QueryInterface(IOleCommandTarget * This, REFIID riid, void **ppvObject)
{
if (ppvObject)
{
if (0==memcmp(riid, &IID_IOleCommandTarget, sizeof(GUID)))
{
*ppvObject = &pIOleCommandTarget;
return 0;
}
else if (!memcmp(riid, &IID_IOleClientSite, sizeof(GUID)))
{
*ppvObject = &pIOleClientSite;
}
else
{
*ppvObject = 0;
return E_NOINTERFACE;
}
}
return E_POINTER;
}
HRESULT STDMETHODCALLTYPE IOleCommandTarget_Release(IOleCommandTarget *This)
{
return 1;
}
HRESULT STDMETHODCALLTYPE IOleCommandTarget_QueryStatus(IOleCommandTarget* This,const GUID* pguidCmdGroup,ULONG cCmds,OLECMD rgCmds[],OLECMDTEXT* pcmdtext)
{
return E_NOTIMPL;
}
#define OLECMDID_SHOWSCRIPTERROR 0x28
DEFINE_GUID(CGID_DocHostCommandHandler,0xF38BC242, 0xB950, 0x11D1, 0x89, 0x18, 0x00, 0xC0, 0x4F, 0xC2, 0xC8, 0x36);
HRESULT STDMETHODCALLTYPE IOleCommandTarget_Exec(IOleCommandTarget* This,const GUID* pguidCmdGroup,DWORD nCmdID,DWORD nCmdexecopt,VARIANTARG* pvarargIn,VARIANTARG* pvarargOut)
{
if (pguidCmdGroup)
{
if (0==memcmp(pguidCmdGroup, &CGID_DocHostCommandHandler, sizeof(GUID)))
{
if (nCmdID == OLECMDID_SHOWSCRIPTERROR)
{
return S_OK;
}
}
}
return E_NOTIMPL;
}
HRESULT STDMETHODCALLTYPE IDocHostUIHandler_AddRef(IDocHostUIHandler *This)
{
return 1;
}
HRESULT STDMETHODCALLTYPE IDocHostUIHandler_QueryInterface(IDocHostUIHandler * This, REFIID riid, void **ppvObject)
{
*ppvObject = 0;
if (!memcmp(riid, &IID_IUnknown, sizeof(GUID)) || !memcmp(riid, &IID_IDocHostUIHandler, sizeof(GUID)))
{
*ppvObject = (void *)This;
IDocHostUIHandler_AddRef(This);
return S_OK;
}
*ppvObject = 0;
return(E_NOINTERFACE);
}
HRESULT STDMETHODCALLTYPE IDocHostUIHandler_Release(IDocHostUIHandler *This)
{
return 1;
}
HRESULT STDMETHODCALLTYPE IDocHostUIHandler_ShowContextMenu(IDocHostUIHandler FAR* This, DWORD dwID, POINT __RPC_FAR *ppt, IUnknown __RPC_FAR *pcmdtReserved, IDispatch __RPC_FAR *pdispReserved)
{
return S_FALSE;
}
HRESULT STDMETHODCALLTYPE IDocHostUIHandler_GetHostInfo(IDocHostUIHandler* This, DOCHOSTUIINFO __RPC_FAR *pInfo)
{
pInfo->dwFlags |= DOCHOSTUIFLAG_SCROLL_NO | DOCHOSTUIFLAG_NO3DBORDER;
return S_OK;
}
HRESULT STDMETHODCALLTYPE IDocHostUIHandler_ShowUI(IDocHostUIHandler FAR* This, DWORD dwID, IOleInPlaceActiveObject __RPC_FAR *pActiveObject, IOleCommandTarget __RPC_FAR *pCommandTarget, IOleInPlaceFrame __RPC_FAR *pFrame, IOleInPlaceUIWindow __RPC_FAR *pDoc)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE IDocHostUIHandler_HideUI(IDocHostUIHandler FAR* This)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE IDocHostUIHandler_UpdateUI(IDocHostUIHandler FAR* This)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE IDocHostUIHandler_EnableModeless(IDocHostUIHandler FAR* This, BOOL fEnable)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE IDocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler FAR* This, BOOL fActivate)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE IDocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler FAR* This, BOOL fActivate)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE IDocHostUIHandler_ResizeBorder(IDocHostUIHandler FAR* This, LPCRECT prcBorder, IOleInPlaceUIWindow __RPC_FAR *pUIWindow, BOOL fRameWindow)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE IDocHostUIHandler_TranslateAccelerator(IDocHostUIHandler FAR* This, LPMSG lpMsg, const GUID __RPC_FAR *pguidCmdGroup, DWORD nCmdID)
{
return(S_FALSE);
}
HRESULT STDMETHODCALLTYPE IDocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler FAR* This, LPOLESTR __RPC_FAR *pchKey, DWORD dw)
{
return(S_FALSE);
}
HRESULT STDMETHODCALLTYPE IDocHostUIHandler_GetDropTarget(IDocHostUIHandler FAR* This, IDropTarget __RPC_FAR *pDropTarget, IDropTarget __RPC_FAR *__RPC_FAR *ppDropTarget)
{
return(S_FALSE);
}
HRESULT STDMETHODCALLTYPE IDocHostUIHandler_GetExternal(IDocHostUIHandler FAR* This, IDispatch __RPC_FAR *__RPC_FAR *ppDispatch)
{
*ppDispatch = 0;
return(S_FALSE);
}
HRESULT STDMETHODCALLTYPE IDocHostUIHandler_TranslateUrl(IDocHostUIHandler FAR* This, DWORD dwTranslate, OLECHAR __RPC_FAR *pchURLIn, OLECHAR __RPC_FAR *__RPC_FAR *ppchURLOut)
{
*ppchURLOut = 0;
return(S_FALSE);
}
HRESULT STDMETHODCALLTYPE IDocHostUIHandler_FilterDataObject(IDocHostUIHandler FAR* This, IDataObject __RPC_FAR *pDO, IDataObject __RPC_FAR *__RPC_FAR *ppDORet)
{
*ppDORet = 0;
return(S_FALSE);
}
void InitHtmlControl(HWND hWin,struct IOleWebBrowser* lpData)
{
struct IOleObject* ppvObject;
CLSID pclsid;
hIOCS.QueryInterface=&IOleClientSite_QueryInterface;
hIOCS.AddRef=&IOleClientSite_AddRef;
hIOCS.Release=&IOleClientSite_Release;
hIOCS.SaveObject=&IOleClientSite_SaveObject;
hIOCS.GetMoniker=&IOleClientSite_GetMoniker;
hIOCS.GetContainer=&IOleClientSite_GetContainer;
hIOCS.ShowObject=&IOleClientSite_ShowObject;
hIOCS.OnShowWindow=&IOleClientSite_OnShowWindow;
hIOCS.RequestNewObjectLayout=&IOleClientSite_RequestNewObjectLayout;
hIOPS.QueryInterface=&IOleInPlaceSite_QueryInterface;
hIOPS.AddRef=&IOleInPlaceSite_AddRef;
hIOPS.Release=&IOleInPlaceSite_Release;
hIOPS.ContextSensitiveHelp=&IOleInPlaceSite_ContextSensitiveHelp;
hIOPS.CanInPlaceActivate=&IOleInPlaceSite_CanInPlaceActivate;
hIOPS.OnInPlaceActivate=&IOleInPlaceSite_OnInPlaceActivate;
hIOPS.OnUIActivate=&IOleInPlaceSite_OnUIActivate;
hIOPS.Scroll=&IOleInPlaceSite_Scroll;
hIOPS.OnUIDeactivate=&IOleInPlaceSite_OnUIDeactivate;
hIOPS.OnInPlaceDeactivate=&IOleInPlaceSite_OnInPlaceDeactivate;
hIOPS.DiscardUndoState=&IOleInPlaceSite_DiscardUndoState;
hIOPS.DeactivateAndUndo=&IOleInPlaceSite_DeactivateAndUndo;
hIOPS.OnPosRectChange=&IOleInPlaceSite_OnPosRectChange;
hIOPS.GetWindowContext=&IOleInPlaceSite_GetWindowContext;
hIOPS.GetWindow=&IOleInPlaceSite_GetWindow;
hIOPF.QueryInterface=&IOleInPlaceFrame_QueryInterface;
hIOPF.AddRef=&IOleInPlaceFrame_AddRef;
hIOPF.Release=&IOleInPlaceFrame_Release;
hIOPF.GetWindow=&IOleInPlaceFrame_GetWindow;
hIOPF.ContextSensitiveHelp=&IOleInPlaceFrame_ContextSensitiveHelp;
hIOPF.GetBorder=&IOleInPlaceFrame_GetBorder;
hIOPF.RequestBorderSpace=&IOleInPlaceFrame_RequestBorderSpace;
hIOPF.SetBorderSpace=&IOleInPlaceFrame_SetBorderSpace;
hIOPF.SetActiveObject=&IOleInPlaceFrame_SetActiveObject;
hIOPF.InsertMenus=&IOleInPlaceFrame_InsertMenus;
hIOPF.SetMenu=&IOleInPlaceFrame_SetMenu;
hIOPF.RemoveMenus=&IOleInPlaceFrame_RemoveMenus;
hIOPF.SetStatusText=&IOleInPlaceFrame_SetStatusText;
hIOPF.EnableModeless=&IOleInPlaceFrame_EnableModeless;
hIOPF.TranslateAccelerator=&IOleInPlaceFrame_TranslateAccelerator;
hIOCT.QueryInterface=&IOleCommandTarget_QueryInterface;
hIOCT.AddRef=&IOleCommandTarget_AddRef;
hIOCT.Release=&IOleCommandTarget_Release;
hIOCT.QueryStatus=&IOleCommandTarget_QueryStatus;
hIOCT.Exec=&IOleCommandTarget_Exec;
hIDHU.AddRef=&IDocHostUIHandler_AddRef;
hIDHU.Release=&IDocHostUIHandler_Release;
hIDHU.ShowContextMenu=&IDocHostUIHandler_ShowContextMenu;
hIDHU.GetHostInfo=&IDocHostUIHandler_GetHostInfo;
hIDHU.ShowUI=&IDocHostUIHandler_ShowUI;
hIDHU.HideUI=&IDocHostUIHandler_HideUI;
hIDHU.UpdateUI=&IDocHostUIHandler_UpdateUI;
hIDHU.EnableModeless=&IDocHostUIHandler_EnableModeless;
hIDHU.OnDocWindowActivate=&IDocHostUIHandler_OnDocWindowActivate;
hIDHU.OnFrameWindowActivate=&IDocHostUIHandler_OnFrameWindowActivate;
hIDHU.ResizeBorder=&IDocHostUIHandler_ResizeBorder;
hIDHU.TranslateAccelerator=&IDocHostUIHandler_TranslateAccelerator;
hIDHU.GetOptionKeyPath=&IDocHostUIHandler_GetOptionKeyPath;
hIDHU.GetDropTarget=&IDocHostUIHandler_GetDropTarget;
hIDHU.GetExternal=&IDocHostUIHandler_GetExternal;
hIDHU.TranslateUrl=&IDocHostUIHandler_TranslateUrl;
hIDHU.FilterDataObject=&IDocHostUIHandler_FilterDataObject;
pIOleClientSite=&hIOCS;
pIOleInPlaceSite=&hIOPS;
pIOleInPlaceFrame=&hIOPF;
pIOleCommandTarget=&hIOCT;
pIDocHostUIHandler=&hIDHU;
hMem.hwndParent=hWin;
CLSIDFromString(L"Shell.Explorer\0",&pclsid);
CoCreateInstance(&pclsid,0,CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,&IID_IUnknown,(void **)&ppvWebBrowser);
ppvWebBrowser->lpVtbl->QueryInterface((struct IOleObject*)ppvWebBrowser,&IID_IOleObject,&ppvObject);
ppvObject->lpVtbl->SetClientSite((struct IOleObject*)ppvObject,(struct IOleClientSite*)&pIOleClientSite);
ppvObject->lpVtbl->Release((struct IOleObject*)ppvObject);
ppvWebBrowser->lpVtbl->QueryInterface((struct IOleObject*)ppvWebBrowser,&IID_IPersistStreamInit,(struct IPersistStreamInit**)&ppvObject);
((struct IPersistStreamInit*)ppvObject)->lpVtbl->InitNew((struct IPersistStreamInit*)ppvObject);
((struct IPersistStreamInit*)ppvObject)->lpVtbl->Release((struct IPersistStreamInit*)ppvObject);
ppvWebBrowser->lpVtbl->QueryInterface((struct IOleObject*)ppvWebBrowser,&IID_IOleObject,&ppvObject);
ppvObject->lpVtbl->DoVerb((struct IOleObject*)ppvObject,OLEIVERB_INPLACEACTIVATE,0,(struct IOleClientSite*)&pIOleClientSite,0,hMem.hwndParent,&hMem.lprcPosRect);
ppvObject->lpVtbl->DoVerb((struct IOleObject*)ppvObject,OLEIVERB_SHOW,0,(struct IOleClientSite*)&pIOleClientSite,0,hMem.hwndParent,&hMem.lprcPosRect);
ppvObject->lpVtbl->Release((struct IOleObject*)ppvObject);
ppvWebBrowser->lpVtbl->QueryInterface((struct IOleObject*)ppvWebBrowser,&IID_IOleObject,&ppvObject);
ppvObject->lpVtbl->DoVerb((struct IOleObject*)ppvObject,OLEIVERB_UIACTIVATE,0,(struct IOleClientSite*)&pIOleClientSite,0,hMem.hwndParent,&hMem.lprcPosRect);
ppvObject->lpVtbl->Release((struct IOleObject*)ppvObject);
ppvWebBrowser->lpVtbl->AddRef((struct IOleObject*)ppvWebBrowser);
ppvWebBrowser->lpVtbl->QueryInterface((struct IOleObject*)ppvWebBrowser,&IID_IWebBrowser2,&ppvWebObject);
ppvWebObject->lpVtbl->put_Offline((struct IWebBrowser2*)ppvWebObject,FALSE);
ppvWebObject->lpVtbl->Navigate((struct IWebBrowser2*)ppvWebObject,L"http://news.baidu.com/", 0, 0, 0, 0);
return;
}
void _stdcall DestroyHtmlControl(struct IOleWebBrowser* lpData)
{
struct IOleInPlaceObject* ppvObject;
ppvWebObject->lpVtbl->Release((struct IWebBrowser2*)ppvWebObject);
ppvWebBrowser->lpVtbl->QueryInterface((struct IOleObject*)ppvWebBrowser,&IID_IOleObject,&ppvObject);
((struct IOleObject*)ppvObject)->lpVtbl->Close((struct IOleObject*)ppvObject,OLECLOSE_NOSAVE);
((struct IOleObject*)ppvObject)->lpVtbl->SetClientSite((struct IOleObject*)ppvObject,0);
((struct IOleObject*)ppvObject)->lpVtbl->Release((struct IOleObject*)ppvObject);
ppvWebBrowser->lpVtbl->QueryInterface((struct IOleObject*)ppvWebBrowser,&IID_IOleInPlaceObject,(struct IOleInPlaceObject**)&ppvObject);
(struct IOleInPlaceObject*)ppvObject->lpVtbl->UIDeactivate((struct IOleInPlaceObject*)ppvObject);
(struct IOleInPlaceObject*)ppvObject->lpVtbl->InPlaceDeactivate((struct IOleInPlaceObject*)ppvObject);
(struct IOleInPlaceObject*)ppvObject->lpVtbl->Release((struct IOleInPlaceObject*)ppvObject);
ppvWebBrowser->lpVtbl->Release((struct IOleObject*)ppvWebBrowser);
((struct IOleClientSite*)&pIOleClientSite)->lpVtbl->Release((struct IOleClientSite*)&pIOleClientSite);
}
void _stdcall ResetHtmlSize(struct IOleWebBrowser* lpData,LPARAM lParam)
{
struct IOleInPlaceObject* ppvObject;
hMem.lprcPosRect.left=0;
hMem.lprcPosRect.top=0;
hMem.lprcPosRect.right= LOWORD(lParam);
hMem.lprcPosRect.bottom=HIWORD(lParam);
if (ppvWebBrowser)
{
ppvWebBrowser->lpVtbl->QueryInterface((struct IOleObject*)ppvWebBrowser,&IID_IOleInPlaceObject,&ppvObject);
ppvObject->lpVtbl->SetObjectRects((struct IOleInPlaceObject*)ppvObject,&hMem.lprcPosRect,&hMem.lprcPosRect);
ppvObject->lpVtbl->Release((struct IOleInPlaceObject*)ppvObject);
}
}
long _stdcall CallHtmlWinProc(HWND hWin,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE:
InitHtmlControl(hWin,(struct IOleWebBrowser*)GetWindowLong(hWin,GWL_USERDATA));
break;
case WM_DESTROY:
DestroyHtmlControl((struct IOleWebBrowser*)GetWindowLong(hWin,GWL_USERDATA));
break;
case WM_SIZE:
ResetHtmlSize((struct IOleWebBrowser*)GetWindowLong(hWin,GWL_USERDATA),lParam);
break;
case WM_NCCREATE:
if (lParam)
{
SetWindowLong(hWin,GWL_USERDATA,(long)(((struct tagCREATESTRUCTA*)(lParam))->lpCreateParams));
}
break;
}
return DefWindowProc(hWin,uMsg,wParam,lParam);
}
HWND _stdcall CreateWebBrowser(HWND hWin,int left,int top,int right,int bottom,HMENU hID)
{
WNDCLASSEX wc;
HWND hCtl;
RtlZeroMemory(&wc,sizeof wc);
wc.cbSize=sizeof wc;
wc.style=CS_SAVEBITS | CS_OWNDC | CS_DBLCLKS;
wc.lpfnWndProc=&CallHtmlWinProc;
wc.hCursor=LoadCursor(0,IDC_ARROW);
wc.hbrBackground=NULL;
wc.lpszClassName=TEXT("IEFrame");
RegisterClassEx(&wc);
hCtl=CreateWindowEx(0,TEXT("IEFrame"),0,WS_CHILD,left,top,right,bottom,hWin,hID,0,&hMem);
ShowWindow(hCtl,SW_SHOW);
UpdateWindow(hWin);
return hCtl;
}
void AutoRealizeMainWinSize(HWND hWin)
{
RECT rct;
HWND t;
t = FindWindow(TEXT("Shell_TrayWnd"),NULL);
if (t)
{
GetClientRect(t,&rct);
rct.right=GetSystemMetrics(SM_CXSCREEN);
rct.bottom = GetSystemMetrics(SM_CYSCREEN) - rct.bottom - 5;
SetWindowPos(hWin,0,0,0,rct.right,rct.bottom,SWP_NOZORDER | SWP_SHOWWINDOW);
}
return;
}
BOOL _stdcall WebBrowerDialogProc(HWND hWin,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
RECT rct;
switch (uMsg)
{
case WM_COMMAND:
if ((LOWORD(wParam))==IDCANCEL)
{
SendMessage(hWin,WM_CLOSE,0,0);
return TRUE;
}
break;
case WM_INITDIALOG:
InitCommonControls();
CoInitialize(NULL);
OleInitialize(NULL);
AutoRealizeMainWinSize(hWin);
GetClientRect(hWin,&rct);
hHtmlWin=CreateWebBrowser(hWin,rct.left,rct.top,rct.right,rct.bottom,(HMENU)IDW_BROW);
return TRUE;
case WM_SIZE:
GetClientRect(hWin,&rct);
SetWindowPos(GetDlgItem(hWin,IDW_BROW),0,0,0,rct.right,rct.bottom,SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOMOVE);
return TRUE;
case WM_CLOSE:
DestroyWindow(hHtmlWin);
OleUninitialize();
CoUninitialize();
EndDialog(hWin,lParam);
return TRUE;
}
return FALSE;
}
int _stdcall WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
DialogBoxParam(hInstance,MAKEINTRESOURCE(DLG_WEBBROWER),NULL,WebBrowerDialogProc,IDI_ICON);
ExitProcess(0);
return 0;
}
最后于 2020-3-30 01:13
被笑梅编辑
,原因: