diff --git a/Mainspring/CMakeLists.txt b/Mainspring/CMakeLists.txt index 179a8a3..b099d42 100644 --- a/Mainspring/CMakeLists.txt +++ b/Mainspring/CMakeLists.txt @@ -1,5 +1,5 @@ # Mainspring app CMakeLists.txt -add_executable(Mainspring WIN32 "src/main.cpp" "src/pch.h") +add_executable(Mainspring WIN32 "src/main.cpp" "src/pch.h" "src/Application.h" "src/Application.cpp" "resource.rc" "src/resources.h") set_property(TARGET Mainspring PROPERTY CXX_STANDARD 20) @@ -12,6 +12,6 @@ endif() target_precompile_headers(Mainspring PUBLIC "src/pch.h") find_package(Git) -execute_process(COMMAND ${GIT_EXECUTABLE} describe OUTPUT_VARIABLE MAINSPRING_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) +execute_process(COMMAND ${GIT_EXECUTABLE} describe OUTPUT_VARIABLE APPVERSION OUTPUT_STRIP_TRAILING_WHITESPACE) configure_file(src/version.h.in version.h) target_include_directories(Mainspring PUBLIC "${PROJECT_BINARY_DIR}/Mainspring") \ No newline at end of file diff --git a/Mainspring/resource.rc b/Mainspring/resource.rc new file mode 100644 index 0000000..66e41e6 --- /dev/null +++ b/Mainspring/resource.rc @@ -0,0 +1,9 @@ +// Mainspring resource script +#include "windows.h" +#include "src/resources.h" + +IDD_DIALOGMAIN DIALOGEX 0, 0, 150, 75 +STYLE WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_POPUP +BEGIN + +END diff --git a/Mainspring/src/Application.cpp b/Mainspring/src/Application.cpp new file mode 100644 index 0000000..2c344ca --- /dev/null +++ b/Mainspring/src/Application.cpp @@ -0,0 +1,53 @@ +// Application class implementation +#include "pch.h" +#include "Application.h" +#include "resources.h" + +// Enable visual styles +#pragma comment(linker, "\"/manifestdependency:type='win32' \ +name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ +processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") + +namespace mainspring { + Application::Application(const char* appName, const char* appVersion) + : m_appName(appName) + , m_appVersion(appVersion) + { + std::cout << std::format("{} {}\n", m_appName, m_appVersion); + } + + void Application::run() { + DialogBoxParam(nullptr, MAKEINTRESOURCE(IDD_DIALOGMAIN), nullptr, reinterpret_cast(mainDlgProc), reinterpret_cast(this)); + } + + BOOL CALLBACK Application::mainDlgProc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam) { + static Application* app = nullptr; + + switch (msg) { + case WM_INITDIALOG: { + app = reinterpret_cast(lParam); + + SetWindowText(dlg, app->m_appName); + + POINT cursor = {}; + GetCursorPos(&cursor); + MONITORINFO mi = {}; + mi.cbSize = sizeof(mi); + GetMonitorInfo(MonitorFromPoint(cursor, MONITOR_DEFAULTTONEAREST), &mi); + SetWindowPos(dlg, nullptr, mi.rcMonitor.left + 100, mi.rcMonitor.top + 100, 0, 0, SWP_NOZORDER | SWP_NOSIZE); + + return TRUE; + } + + case WM_CLOSE: + EndDialog(dlg, 0); + return TRUE; + } + + return FALSE; + } + + Application::~Application() { + + } +} \ No newline at end of file diff --git a/Mainspring/src/Application.h b/Mainspring/src/Application.h new file mode 100644 index 0000000..6da9a98 --- /dev/null +++ b/Mainspring/src/Application.h @@ -0,0 +1,17 @@ +// Application class header + +namespace mainspring { + class Application { + public: + Application(const char* appName, const char* appVersion); + + void run(); + + ~Application(); + private: + static BOOL CALLBACK mainDlgProc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam); + + const char* m_appName; + const char* m_appVersion; + }; +} \ No newline at end of file diff --git a/Mainspring/src/main.cpp b/Mainspring/src/main.cpp index 2d8fd62..49a5882 100644 --- a/Mainspring/src/main.cpp +++ b/Mainspring/src/main.cpp @@ -2,15 +2,16 @@ #include "pch.h" #include "version.h" +#include "Application.h" -// Enable visual styles -#pragma comment(linker, "\"/manifestdependency:type='win32' \ -name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ -processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") +#define APPNAME "Mainspring" int main(int argc, char* argv[]) { - std::cout << std::format("Mainspring {}\n", MAINSPRING_VERSION); - std::cin.get(); + { + mainspring::Application app(APPNAME, APPVERSION); + app.run(); + } + return EXIT_SUCCESS; } \ No newline at end of file diff --git a/Mainspring/src/resources.h b/Mainspring/src/resources.h new file mode 100644 index 0000000..07ffcd0 --- /dev/null +++ b/Mainspring/src/resources.h @@ -0,0 +1,2 @@ +// Win32 resources +#define IDD_DIALOGMAIN 101 diff --git a/Mainspring/src/version.h.in b/Mainspring/src/version.h.in index e95c487..cea0631 100644 --- a/Mainspring/src/version.h.in +++ b/Mainspring/src/version.h.in @@ -1,2 +1,2 @@ // Version configured header file -#define MAINSPRING_VERSION "@MAINSPRING_VERSION@" \ No newline at end of file +#define APPVERSION "@APPVERSION@" \ No newline at end of file