From fe65f8945c189467e0d6211762ebd9c7fcc0aaf3 Mon Sep 17 00:00:00 2001 From: MusicalProgrammer <38636805+MusicalProgrammer@users.noreply.github.com> Date: Sat, 7 Jul 2018 20:55:18 -0400 Subject: [PATCH] IEBrowser class added --- .gitignore | 1 + Demo.h | 1 + Globals.cpp | 4 +++ Globals.h | 3 ++- IEBrowser.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ IEBrowser.h | 15 +++++++++++ IEDispatcher.cpp | 31 +++++++++++++++++++++++ IEDispatcher.h | 10 ++++++-- main.cpp | 64 +++++++++++++++-------------------------------- 9 files changed, 147 insertions(+), 47 deletions(-) create mode 100644 IEBrowser.cpp create mode 100644 IEBrowser.h diff --git a/.gitignore b/.gitignore index 8de655f..6c0f1e3 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,4 @@ log.txt G3DTest.suo G3DTest.suo stderr.txt +desktop.ini diff --git a/Demo.h b/Demo.h index 7496586..2e76d84 100644 --- a/Demo.h +++ b/Demo.h @@ -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; diff --git a/Globals.cpp b/Globals.cpp index 914660c..dddef2f 100644 --- a/Globals.cpp +++ b/Globals.cpp @@ -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){} diff --git a/Globals.h b/Globals.h index f0052d2..07d4fd0 100644 --- a/Globals.h +++ b/Globals.h @@ -17,4 +17,5 @@ public: static const int patch; static G3D::TextureRef surface; static int surfaceId; -}; \ No newline at end of file + static const std::string PlaceholderName; +}; diff --git a/IEBrowser.cpp b/IEBrowser.cpp new file mode 100644 index 0000000..1a15626 --- /dev/null +++ b/IEBrowser.cpp @@ -0,0 +1,65 @@ +#ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN +#endif + +#include + +#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; +} \ No newline at end of file diff --git a/IEBrowser.h b/IEBrowser.h new file mode 100644 index 0000000..4762122 --- /dev/null +++ b/IEBrowser.h @@ -0,0 +1,15 @@ +//#include "WindowFunctions.h" +#include +#include +//#include + +class IEBrowser { + public: + IEBrowser(HWND attachHWnd); + ~IEBrowser(void); + bool navigateSyncURL(wchar_t* url); + private: + IWebBrowser2* webBrowser; + HWND hwnd; + IDispatch* spDocument; +}; diff --git a/IEDispatcher.cpp b/IEDispatcher.cpp index bb2069c..10330f6 100644 --- a/IEDispatcher.cpp +++ b/IEDispatcher.cpp @@ -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; +} + \ No newline at end of file diff --git a/IEDispatcher.h b/IEDispatcher.h index 72c7349..9cc1e41 100644 --- a/IEDispatcher.h +++ b/IEDispatcher.h @@ -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 *); + }; diff --git a/main.cpp b/main.cpp index 9d753fa..5a78cfa 100644 --- a/main.cpp +++ b/main.cpp @@ -35,11 +35,9 @@ #include #include #include -#include -#include #include "ax.h" -#include "IEDispatcher.h" - +#include +#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));