From 1cc7f8fcb6b962c6431e7b4249fda68f6600dedc Mon Sep 17 00:00:00 2001 From: Vulpovile Date: Thu, 4 Mar 2021 22:59:28 -0800 Subject: [PATCH] Refactor main, Fixed main getting taken out of gitignore for some reason --- .gitignore | 2 - src/source/main.cpp | 222 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 222 insertions(+), 2 deletions(-) create mode 100644 src/source/main.cpp diff --git a/.gitignore b/.gitignore index a20e3db..cde6729 100644 --- a/.gitignore +++ b/.gitignore @@ -52,6 +52,4 @@ G3DTest.suo G3DTest.suo stderr.txt desktop.ini -main.cpp *.db -G3DTest.sln diff --git a/src/source/main.cpp b/src/source/main.cpp new file mode 100644 index 0000000..799cc1b --- /dev/null +++ b/src/source/main.cpp @@ -0,0 +1,222 @@ +// TODO: Move toolbar buttons with resized window. +The hell is going on +#define _WIN32_WINNT 0x0400 +#define _WIN32_WINDOWS 0x0400 +#define WINVER 0x0400 + +#include "resource.h" +#include "Application.h" +#include "WindowFunctions.h" +#include "ax.h" +#include +#include "ErrorFunctions.h" + +#if G3D_VER < 61000 + #error Requires G3D 6.10 +#endif +HWND hwnd; + +HRESULT hresult; +OLECHAR dat = ((OLECHAR)"SayHello"); +OLECHAR * szMember = &dat; +DISPID dispid; +DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0}; +EXCEPINFO excepinfo; +UINT nArgErr; + +LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + Application *app = (Application *)GetWindowLongPtr(hwnd, GWL_USERDATA); + if (app==NULL) + { + return DefWindowProc(hwnd, msg, wParam, lParam); + } + switch(msg) + { + case WM_KEYDOWN: + if ((HIWORD(lParam)&0x4000)==0) // single key press + { + app->onKeyPressed(wParam); + } + break; + case WM_KEYUP: + { + app->onKeyUp(wParam); + } + break; + case WM_MOUSEWHEEL: + app->onMouseWheel(LOWORD(lParam),HIWORD(lParam),HIWORD(wParam)); + break; + case WM_SIZE: + app->resizeWithParent(hwnd); + break; + case WM_ACTIVATE: + if(wParam > WA_INACTIVE) app->setFocus(false); + else app->setFocus(true); + default: + { + return DefWindowProc(hwnd, msg, wParam, lParam); + } + } + return 0; +} + +LRESULT CALLBACK ToolboxProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + //Application *app = (Application *)GetWindowLongPtr(hwnd, GWL_USERDATA); + MessageBox(NULL, (LPCSTR)wParam, (LPCSTR)lParam, 1); + //if (app==NULL) + //{ + //return DefWindowProc(hwnd, msg, wParam, lParam); + //} + switch(msg) + { + case WM_SIZE: + break; + default: + { + return DefWindowProc(hwnd, msg, wParam, lParam); + } + } + return 0; +} + +LRESULT CALLBACK G3DProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + Application *app = (Application *)GetWindowLongPtr(hwnd, GWL_USERDATA); + if (app==NULL) + { + return DefWindowProc(hwnd, msg, wParam, lParam); + } + switch(msg) + { + case WM_QUIT: + app->QuitApp(); + break; + case WM_DESTROY: + app->QuitApp(); + break; + case WM_LBUTTONDOWN: + app->onMouseLeftPressed(hwnd,LOWORD(lParam),HIWORD(lParam)); + break; + case WM_LBUTTONUP: + app->onMouseLeftUp(app->getRenderDevice(),LOWORD(lParam),HIWORD(lParam)); + break; + case WM_RBUTTONDOWN: + app->onMouseRightPressed(LOWORD(lParam),HIWORD(lParam)); + break; + case WM_RBUTTONUP: + app->onMouseRightUp(LOWORD(lParam),HIWORD(lParam)); + break; + case WM_MOUSEMOVE: + app->onMouseMoved(LOWORD(lParam),HIWORD(lParam)); + break; + case WM_KEYDOWN: + if ((HIWORD(lParam)&0x4000)==0) // single key press + { + app->onKeyPressed(wParam); + } + break; + case WM_KEYUP: + { + app->onKeyUp(wParam); + } + break; + case WM_SYSKEYDOWN: + if ((HIWORD(lParam)&0x4000)==0) // single key press + { + app->onKeyPressed(wParam); + } + break; + case WM_SYSKEYUP: + { + app->onKeyUp(wParam); + } + case WM_SIZE: + { + app->onGraphics(app->getRenderDevice()); + } + break; + default: + { + return DefWindowProc(hwnd, msg, wParam, lParam); + } + } + + return 0; +} + +int main(int argc, char** argv) { + try{ + hresult = OleInitialize(NULL); + +/* IInternetSecurityManager *pSecurityMgr; + IInternetZoneManager *pZoneMgr; + LPCWSTR site1 = SysAllocString(L"http://www.androdome.com"); + + hr = CoCreateInstance(CLSID_InternetSecurityManager, NULL, CLSCTX_INPROC_SERVER, IID_IInternetSecurityManager, (void**)&pSecurityMgr); + + pSecurityMgr->SetZoneMapping((DWORD)2, site1, (DWORD)0); // 2 = Trusted Site, site1 is the URL to add, and 0 is to create the entry. +*/ + + + + if (!AXRegister()) + return 0; + + + INITCOMMONCONTROLSEX icc; +// WNDCLASSEX wcx; + + /* Initialize common controls. Also needed for MANIFEST's */ + + icc.dwSize = sizeof(icc); + icc.dwICC = ICC_WIN95_CLASSES/*|ICC_COOL_CLASSES|ICC_DATE_CLASSES| + ICC_PAGESCROLLER_CLASS|ICC_USEREX_CLASSES*/; + InitCommonControlsEx(&icc); + + AudioPlayer::init(); + /* GAppSettings settings; + settings.window.resizable = true; + settings.writeLicenseFile = false; + settings.window.center = true; */ + HMODULE hThisInstance = GetModuleHandle(NULL); + + if (!createWindowClass("mainHWND",WndProc,hThisInstance)) + return false; + if (!createWindowClass("toolboxHWND",ToolboxProc,hThisInstance)) + return false; + if (!createWindowClass("G3DWindow",G3DProc,hThisInstance)) + return false; + + HWND hwndMain = CreateWindowEx( + WS_EX_ACCEPTFILES, + "mainHWND", + "Main test", + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, + CW_USEDEFAULT, + 800, + 660, + NULL, // parent + NULL, // menu + hThisInstance, + NULL + ); + if(hwndMain == NULL) + { + MessageBox(NULL, "Critical error loading: Failed to create HWND, must exit", (g_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)); + + + Application app = Application(hwndMain); + app.run(); + } + catch(...) + { + OnError(-1); + } + return 0; +}