Add launcher
This commit is contained in:
parent
7c37830cab
commit
a8a609907d
@ -51,7 +51,7 @@ workspace "open-mw3"
|
||||
configuration {}
|
||||
|
||||
project "open-mw3"
|
||||
kind "SharedLib"
|
||||
kind "WindowedApp"
|
||||
language "C++"
|
||||
|
||||
pchheader "std_include.hpp"
|
||||
|
12
src/launcher/launcher.cpp
Normal file
12
src/launcher/launcher.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include <std_include.hpp>
|
||||
#include "launcher.hpp"
|
||||
|
||||
launcher::launcher() : window_("Open-IW5", 300, 400)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void launcher::run() const
|
||||
{
|
||||
this->window_.run();
|
||||
}
|
13
src/launcher/launcher.hpp
Normal file
13
src/launcher/launcher.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "window.hpp"
|
||||
|
||||
class launcher
|
||||
{
|
||||
public:
|
||||
launcher();
|
||||
|
||||
void run() const;
|
||||
|
||||
private:
|
||||
window window_;
|
||||
};
|
84
src/launcher/window.cpp
Normal file
84
src/launcher/window.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
#include <std_include.hpp>
|
||||
#include "window.hpp"
|
||||
|
||||
window::window(const std::string& title, int width, int height)
|
||||
{
|
||||
const auto handle = GetModuleHandle(nullptr);
|
||||
|
||||
ZeroMemory(&this->wc_, sizeof(this->wc_));
|
||||
|
||||
this->wc_.cbSize = sizeof(this->wc_);
|
||||
this->wc_.style = CS_HREDRAW | CS_VREDRAW;
|
||||
this->wc_.lpfnWndProc = window::static_processor;
|
||||
this->wc_.hInstance = handle;
|
||||
this->wc_.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
||||
this->wc_.hIcon = LoadIcon(handle, MAKEINTRESOURCE(102));
|
||||
this->wc_.hIconSm = this->wc_.hIcon;
|
||||
this->wc_.hbrBackground = CreateSolidBrush(RGB(35, 35, 35));//HBRUSH(COLOR_WINDOW);
|
||||
this->wc_.lpszClassName = L"omw3_window";
|
||||
RegisterClassEx(&this->wc_);
|
||||
|
||||
const auto x = (GetSystemMetrics(SM_CXSCREEN) - width) / 2;
|
||||
const auto y = (GetSystemMetrics(SM_CYSCREEN) - height) / 2;
|
||||
|
||||
this->handle_ = CreateWindowExA(NULL, "omw3_window", title.data(), (WS_OVERLAPPEDWINDOW | WS_VISIBLE) & ~(WS_THICKFRAME | WS_MAXIMIZEBOX), x, y, width,
|
||||
height, nullptr, nullptr, handle, nullptr);
|
||||
|
||||
SetWindowLongPtrA(*this, GWLP_USERDATA, LONG_PTR(this));
|
||||
}
|
||||
|
||||
window::~window()
|
||||
{
|
||||
this->close();
|
||||
UnregisterClass(this->wc_.lpszClassName, this->wc_.hInstance);
|
||||
DeleteObject(this->wc_.hbrBackground);
|
||||
}
|
||||
|
||||
void window::close()
|
||||
{
|
||||
if (!this->handle_) return;
|
||||
|
||||
SendMessageA(this->handle_, WM_KILL_WINDOW, NULL, NULL);
|
||||
this->handle_ = nullptr;
|
||||
}
|
||||
|
||||
void window::run() const
|
||||
{
|
||||
MSG msg;
|
||||
while (this->handle_ && IsWindow(*this))
|
||||
{
|
||||
if (PeekMessageA(&msg, nullptr, NULL, NULL, PM_REMOVE))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessageA(&msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::this_thread::sleep_for(1ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT CALLBACK window::processor(UINT message, WPARAM w_param, LPARAM l_param) const
|
||||
{
|
||||
if (message == WM_KILL_WINDOW)
|
||||
{
|
||||
DestroyWindow(*this);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return DefWindowProc(*this, message, w_param, l_param);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK window::static_processor(HWND hwnd, UINT message, WPARAM w_param, LPARAM l_param)
|
||||
{
|
||||
window* self = reinterpret_cast<window*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
|
||||
if (self) return self->processor(message, w_param, l_param);
|
||||
return DefWindowProc(hwnd, message, w_param, l_param);
|
||||
}
|
||||
|
||||
|
||||
window::operator HWND() const
|
||||
{
|
||||
return this->handle_;
|
||||
}
|
22
src/launcher/window.hpp
Normal file
22
src/launcher/window.hpp
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#define WM_KILL_WINDOW (WM_USER+0)
|
||||
|
||||
class window final
|
||||
{
|
||||
public:
|
||||
window(const std::string& title, int width, int height);
|
||||
~window();
|
||||
|
||||
void close();
|
||||
void run() const;
|
||||
|
||||
operator HWND() const;
|
||||
|
||||
private:
|
||||
WNDCLASSEX wc_{};
|
||||
HWND handle_ = nullptr;
|
||||
|
||||
LRESULT CALLBACK processor(UINT message, WPARAM w_param, LPARAM l_param) const;
|
||||
static LRESULT CALLBACK static_processor(HWND hwnd, UINT message, WPARAM w_param, LPARAM l_param);
|
||||
};
|
28
src/main.cpp
28
src/main.cpp
@ -1,28 +1,8 @@
|
||||
#include <std_include.hpp>
|
||||
#include "launcher/launcher.hpp"
|
||||
|
||||
namespace main
|
||||
int CALLBACK WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nCmdShow*/)
|
||||
{
|
||||
void initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void uninitialize()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
BOOL APIENTRY DllMain(HMODULE, DWORD call_reason, LPVOID)
|
||||
{
|
||||
if (call_reason == DLL_PROCESS_ATTACH)
|
||||
{
|
||||
main::initialize();
|
||||
}
|
||||
else if (call_reason == DLL_PROCESS_DETACH)
|
||||
{
|
||||
main::uninitialize();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
launcher launcher;
|
||||
launcher.run();
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ BEGIN
|
||||
VALUE "FileVersion", "1.0.0.0"
|
||||
VALUE "InternalName", "Open-IW5"
|
||||
VALUE "LegalCopyright", "All rights reserved."
|
||||
VALUE "OriginalFilename", "oiw5.dll"
|
||||
VALUE "OriginalFilename", "oiw5.exe"
|
||||
VALUE "ProductName", "oiw5"
|
||||
VALUE "ProductVersion", "1.0.0.0"
|
||||
END
|
||||
|
@ -7,7 +7,10 @@
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
#pragma warning(disable: 4100)
|
||||
|
||||
#include "steam\steam.hpp"
|
||||
#include "steam/steam.hpp"
|
||||
|
Loading…
Reference in New Issue
Block a user