Add Application and basic dialog

This commit is contained in:
Grayson Riffe 2025-01-20 20:44:10 -06:00
parent 6d1d7ed8d7
commit c0f04232b4
7 changed files with 91 additions and 9 deletions

View File

@ -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")

9
Mainspring/resource.rc Normal file
View File

@ -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

View File

@ -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<DLGPROC>(mainDlgProc), reinterpret_cast<LPARAM>(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<Application*>(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() {
}
}

View File

@ -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;
};
}

View File

@ -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;
}

View File

@ -0,0 +1,2 @@
// Win32 resources
#define IDD_DIALOGMAIN 101

View File

@ -1,2 +1,2 @@
// Version configured header file
#define MAINSPRING_VERSION "@MAINSPRING_VERSION@"
#define APPVERSION "@APPVERSION@"