Add Application and basic dialog
This commit is contained in:
parent
6d1d7ed8d7
commit
c0f04232b4
@ -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
9
Mainspring/resource.rc
Normal 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
|
53
Mainspring/src/Application.cpp
Normal file
53
Mainspring/src/Application.cpp
Normal 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() {
|
||||
|
||||
}
|
||||
}
|
17
Mainspring/src/Application.h
Normal file
17
Mainspring/src/Application.h
Normal 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;
|
||||
};
|
||||
}
|
@ -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;
|
||||
}
|
2
Mainspring/src/resources.h
Normal file
2
Mainspring/src/resources.h
Normal file
@ -0,0 +1,2 @@
|
||||
// Win32 resources
|
||||
#define IDD_DIALOGMAIN 101
|
@ -1,2 +1,2 @@
|
||||
// Version configured header file
|
||||
#define MAINSPRING_VERSION "@MAINSPRING_VERSION@"
|
||||
#define APPVERSION "@APPVERSION@"
|
Loading…
x
Reference in New Issue
Block a user