From c63fd0ec88e13d30d5881a4fec1428929a0ec667 Mon Sep 17 00:00:00 2001 From: "Grayson Riffe (Laptop)" Date: Wed, 18 Aug 2021 12:22:57 -0500 Subject: [PATCH] Added single instance lock and release error system --- NothinFancy/src/Application.cpp | 21 +++++++++++++-------- NothinFancy/src/include/Utility.h | 3 ++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/NothinFancy/src/Application.cpp b/NothinFancy/src/Application.cpp index db14924..cad4030 100644 --- a/NothinFancy/src/Application.cpp +++ b/NothinFancy/src/Application.cpp @@ -103,14 +103,19 @@ namespace nf { } void Application::registerWindowClass() { - m_wclassName = L"NFClass"; - WNDCLASS wclass = { }; - wclass.lpszClassName = m_wclassName; - wclass.hCursor = LoadCursor(NULL, IDC_ARROW); - wclass.hIcon = NULL; - wclass.hInstance = m_hInst; - wclass.lpfnWndProc = Application::WindowProc; - RegisterClass(&wclass); + if (!FindWindow(L"NFClass", NULL)) { + m_wclassName = L"NFClass"; + WNDCLASS wclass = { }; + wclass.lpszClassName = m_wclassName; + wclass.hCursor = LoadCursor(NULL, IDC_ARROW); + wclass.hIcon = NULL; + wclass.hInstance = m_hInst; + wclass.lpfnWndProc = Application::WindowProc; + RegisterClass(&wclass); + } + else { + Error("Cannot run two NF applications at once."); + } } void Application::toggleFullscreen() { diff --git a/NothinFancy/src/include/Utility.h b/NothinFancy/src/include/Utility.h index 2a610c8..cffb2c9 100644 --- a/NothinFancy/src/include/Utility.h +++ b/NothinFancy/src/include/Utility.h @@ -28,7 +28,8 @@ DebugBreak(); #else #define DEBUGINIT #define Log(x) -#define Error(x) +#define Error(x) MessageBox(FindWindow(L"NFClass", NULL), toWide(x), L"NF Engine Error", MB_OK | MB_ICONERROR);\ +std::exit(-1) #endif const wchar_t* toWide(const char* in);