IEBrowser class added

This commit is contained in:
MusicalProgrammer
2018-07-07 20:55:18 -04:00
parent ee1258b177
commit fe65f8945c
9 changed files with 147 additions and 47 deletions

1
.gitignore vendored
View File

@@ -51,3 +51,4 @@ log.txt
G3DTest.suo
G3DTest.suo
stderr.txt
desktop.ini

1
Demo.h
View File

@@ -29,6 +29,7 @@ class Demo { // : public GApp {
void onMouseRightUp(int x, int y);
void onMouseMoved(int x, int y);
void onMouseWheel(int x, int y, short delta);
CameraController cameraController;
RenderDevice* renderDevice;
UserInput* userInput;

View File

@@ -8,6 +8,10 @@ int const Globals::patch = 2;
int Globals::surfaceId = 2;
bool Globals::showMouse = true;
bool Globals::useMousePoint = false;
const std::string Globals::PlaceholderName = "Dynamica";
G3D::TextureRef Globals::surface;
POINT Globals::mousepoint;
Globals::Globals(void){}

View File

@@ -17,4 +17,5 @@ public:
static const int patch;
static G3D::TextureRef surface;
static int surfaceId;
};
static const std::string PlaceholderName;
};

65
IEBrowser.cpp Normal file
View File

@@ -0,0 +1,65 @@
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include "IEBrowser.h"
#include "Globals.h"
#include "ax.h"
IEBrowser::IEBrowser(HWND attachHWnd) {
MSG messages;
while (PeekMessage (&messages, NULL, 0, 0,PM_REMOVE))
{
if (IsDialogMessage(hwnd, &messages) == 0)
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
}
hwnd = attachHWnd;
spDocument = 0;
webBrowser = 0;
SendMessage(hwnd,AX_INPLACE,1,0);
SendMessage(hwnd,AX_QUERYINTERFACE,(WPARAM)&IID_IWebBrowser2,(LPARAM)&webBrowser);
}
IEBrowser::~IEBrowser(void) {
if (webBrowser)
{
webBrowser->Release();
}
}
bool IEBrowser::navigateSyncURL(wchar_t* url)
{
MSG messages;
if (webBrowser)
{
webBrowser->Navigate(url,0,0,0,0);
for (int i=1;i<1000;i++)
{
while (PeekMessage (&messages, NULL, 0, 0,PM_REMOVE))
{
if (IsDialogMessage(hwnd, &messages) == 0)
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
}
Sleep(30);
HRESULT hresult = webBrowser->get_Document(&spDocument);
if (&spDocument!=0)
{
return true;
}
}
}
else
{
MessageBox(NULL,"Cannot read IWebBrowser2...",Globals::PlaceholderName.c_str(),MB_OK);
}
return false;
}

15
IEBrowser.h Normal file
View File

@@ -0,0 +1,15 @@
//#include "WindowFunctions.h"
#include <mshtml.h>
#include <exdisp.h>
//#include <Mshtmhst.h>
class IEBrowser {
public:
IEBrowser(HWND attachHWnd);
~IEBrowser(void);
bool navigateSyncURL(wchar_t* url);
private:
IWebBrowser2* webBrowser;
HWND hwnd;
IDispatch* spDocument;
};

View File

@@ -7,3 +7,34 @@ IEDispatcher::IEDispatcher(void)
IEDispatcher::~IEDispatcher(void)
{
}
HRESULT STDMETHODCALLTYPE IEDispatcher::QueryInterface(const IID &riid, void **ppvObject)
{
return NULL;
}
ULONG STDMETHODCALLTYPE IEDispatcher::AddRef()
{
return NULL;
}
ULONG STDMETHODCALLTYPE IEDispatcher::Release()
{
return NULL;
}
HRESULT STDMETHODCALLTYPE IEDispatcher::GetTypeInfoCount(UINT *pctinfo)
{
return NULL;
}
HRESULT STDMETHODCALLTYPE IEDispatcher::GetTypeInfo(UINT, LCID, ITypeInfo **)
{
return NULL;
}
HRESULT STDMETHODCALLTYPE IEDispatcher::GetIDsOfNames(const IID &, LPOLESTR *, UINT, LCID, DISPID *)
{
return NULL;
}
HRESULT STDMETHODCALLTYPE IEDispatcher::Invoke(DISPID, const IID &, LCID, WORD, DISPPARAMS *, VARIANT *, EXCEPINFO *, UINT *)
{
return NULL;
}

View File

@@ -6,6 +6,12 @@ class IEDispatcher : public IDispatch
public:
IEDispatcher(void);
~IEDispatcher(void);
HRESULT IEDispatcher::QueryInterface();
HRESULT IEDispatcher::QueryInterface(const IID &riid, void **ppvObject);
HRESULT STDMETHODCALLTYPE IEDispatcher::QueryInterface(const IID &riid, void **ppvObject);
ULONG STDMETHODCALLTYPE IEDispatcher::AddRef();
ULONG STDMETHODCALLTYPE IEDispatcher::Release();
HRESULT STDMETHODCALLTYPE IEDispatcher::GetTypeInfoCount(UINT *pctinfo);
HRESULT STDMETHODCALLTYPE IEDispatcher::GetTypeInfo(UINT, LCID, ITypeInfo **);
HRESULT STDMETHODCALLTYPE IEDispatcher::GetIDsOfNames(const IID &, LPOLESTR *, UINT, LCID, DISPID *);
HRESULT STDMETHODCALLTYPE IEDispatcher::Invoke(DISPID, const IID &, LCID, WORD, DISPPARAMS *, VARIANT *, EXCEPINFO *, UINT *);
};

View File

@@ -35,11 +35,9 @@
#include <exdisp.h>
#include <vector>
#include <string>
#include <comdef.h>
#include <comdefsp.h>
#include "ax.h"
#include "IEDispatcher.h"
#include <cguid.h>
#include "IEBrowser.h"
#if G3D_VER < 61000
#error Requires G3D 6.10
@@ -48,8 +46,6 @@ HWND hwnd;
DEFINE_GUID(CLSID_G3d, 0xB323F8E0L, 0x2E68, 0x11D0, 0x90, 0xEA, 0x00, 0xAA, 0x00, 0x60, 0xF8, 0x6F);
HRESULT hresult;
IUnknown * punk;
IDispatch * pdisp = new IEDispatcher();
OLECHAR dat = ((OLECHAR)"SayHello");
OLECHAR * szMember = &dat;
DISPID dispid;
@@ -57,8 +53,6 @@ DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
EXCEPINFO excepinfo;
UINT nArgErr;
IWebBrowser2* test;
static std::string title = "";
static DataModelInstance* dataModel;
GFontRef fntdominant = NULL;
@@ -91,7 +85,7 @@ Demo::Demo(const GAppSettings& settings,HWND parentWindow) { //: GApp(settings,w
_hWndMain = parentWindow;
HMODULE hThisInstance = GetModuleHandle(NULL);
IWebBrowser2* wb = 0;
_hwndToolbox = CreateWindowEx(
WS_EX_ACCEPTFILES,
"AX",
@@ -106,31 +100,7 @@ Demo::Demo(const GAppSettings& settings,HWND parentWindow) { //: GApp(settings,w
hThisInstance,
NULL
);
SendMessage(_hwndToolbox,AX_INPLACE,1,0);
SendMessage(_hwndToolbox,AX_QUERYINTERFACE,(WPARAM)&IID_IWebBrowser2,(LPARAM)&wb);
if (wb)
{
wb->Navigate(L"https://scottbeebiwan.tk/g3d/toolbox/",0,0,0,0);
wb->Release();
}
_buttonTest = CreateWindow(
"COMBOBOX",
"",
CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE ,
20,
10,
80,
120,
_hwndToolbox, // parent
NULL, // menu
hThisInstance,
NULL
);
SendMessage(_buttonTest,(UINT) CB_ADDSTRING,(WPARAM) 0,(LPARAM) "TEST");
SendMessage(_buttonTest,(UINT) CB_ADDSTRING,(WPARAM) 0,(LPARAM) "TEST2");
SendMessage(_buttonTest, CB_SETCURSEL, (WPARAM)1, (LPARAM)0);
_hwndRenderer = CreateWindowEx(
WS_EX_ACCEPTFILES,
"G3DWindow",
@@ -146,10 +116,10 @@ Demo::Demo(const GAppSettings& settings,HWND parentWindow) { //: GApp(settings,w
NULL
);
Win32Window* window = Win32Window::create(settings.window,_hwndRenderer);
ShowWindow(_hwndRenderer, SW_SHOW);
ShowWindow(_hWndMain, SW_SHOW);
quit=false;
rightButtonHolding=false;
mouseOnScreen=false;
@@ -163,12 +133,15 @@ Demo::Demo(const GAppSettings& settings,HWND parentWindow) { //: GApp(settings,w
MessageBox(NULL,"Window not found!","Error",MB_OK);
return;
}
_window = renderDevice->window();
_window->makeCurrent();
SetWindowLongPtr(_hWndMain,GWL_USERDATA,(LONG)this);
SetWindowLongPtr(_hwndRenderer,GWL_USERDATA,(LONG)this);
SetWindowLongPtr(_hwndToolbox,GWL_USERDATA,(LONG)this);
IEBrowser* webBrowser = new IEBrowser(_hwndToolbox);
webBrowser->navigateSyncURL(L"https://scottbeebiwan.tk/g3d/toolbox/");
}
void clearInstances()
@@ -1398,13 +1371,13 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
LRESULT CALLBACK ToolboxProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
Demo *app = (Demo *)GetWindowLongPtr(hwnd, GWL_USERDATA);
//Demo *app = (Demo *)GetWindowLongPtr(hwnd, GWL_USERDATA);
MessageBox(NULL, (LPCSTR)wParam, (LPCSTR)lParam, 1);
if (app==NULL)
{
return DefWindowProc(hwnd, msg, wParam, lParam);
}
switch(msg)
//if (app==NULL)
//{
//return DefWindowProc(hwnd, msg, wParam, lParam);
//}
switch(msg)
{
case WM_SIZE:
break;
@@ -1593,8 +1566,11 @@ void Demo::onCreate(HWND parentWindow)
int main(int argc, char** argv) {
try{
hresult = OleInitialize(NULL);
<<<<<<< HEAD
=======
hresult = CoCreateInstance(CLSID_G3d, NULL, CLSCTX_SERVER, IID_IUnknown, (void **)&punk);
hresult = punk->QueryInterface(IID_IDispatch, &pdisp);
hresult = punk->QueryInterface(IID_IDispatch, (void **)&pdisp);
>>>>>>> db4c46cf20d280b99ab13d892c809de8108d4862
if (!AXRegister())
return 0;
@@ -1634,7 +1610,7 @@ int main(int argc, char** argv) {
if(hwndMain == NULL)
{
MessageBox(NULL, "Failed to create HWND",placeholderName+" Crash", MB_OK);
MessageBox(NULL, "Failed to create HWND", (PlaceholderName + " Crash").c_str() , MB_OK);
return 0;
}
SendMessage(hwndMain, WM_SETICON, ICON_BIG,(LPARAM)LoadImage(GetModuleHandle(NULL), (LPCSTR)MAKEINTRESOURCEW(IDI_ICON1), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE));