From 83f092d8df5d8694f8c9b61b61e3901a86c9ac8a Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Tue, 13 May 2025 10:21:31 +0200 Subject: [PATCH] minwin: Add implementations for some minor function (#74) --- CMakeLists.txt | 2 +- miniwin/miniwin.cpp | 6 ++++ miniwin/miniwin.h | 13 ++------ miniwin/stdafx.cpp | 78 +++++++++++++++++++++++++++++++++++++++++++++ util/stdafx.cpp | 28 ---------------- 5 files changed, 88 insertions(+), 39 deletions(-) create mode 100644 miniwin/stdafx.cpp delete mode 100644 util/stdafx.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6caa0243..309596df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -525,7 +525,7 @@ if (ISLE_BUILD_CONFIG) CONFIG/res/config.rc ) if(NOT WIN32) - list(APPEND config_SRC util/stdafx.cpp) + list(APPEND config_SRC miniwin/stdafx.cpp) endif() add_executable(config ${config_SRC}) if(NOT WIN32) diff --git a/miniwin/miniwin.cpp b/miniwin/miniwin.cpp index e207df49..45a08629 100644 --- a/miniwin/miniwin.cpp +++ b/miniwin/miniwin.cpp @@ -4,6 +4,7 @@ #include "miniwin_d3drm.h" #include "miniwin_ddraw.h" +#include #include bool IsEqualGUID(const GUID& a, const GUID& b) @@ -60,3 +61,8 @@ void OutputDebugString(const char* lpOutputString) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", lpOutputString); } + +VOID WINAPI Sleep(DWORD dwMilliseconds) +{ + SDL_Delay(dwMilliseconds); +} diff --git a/miniwin/miniwin.h b/miniwin/miniwin.h index 34288ddc..b3b5ef7f 100644 --- a/miniwin/miniwin.h +++ b/miniwin/miniwin.h @@ -310,10 +310,7 @@ inline BOOL SetWindowPos(HWND hWndInsertAfter, int X, int Y, int cx, int cy, UIN return TRUE; } -inline BOOL GetWindowRect(HWND hDlg, struct tagRECT* Rect) -{ - return TRUE; -} +BOOL GetWindowRect(HWND hDlg, struct tagRECT *Rect); inline BOOL GetClientRect(LPRECT lpRect) { @@ -540,9 +537,7 @@ inline AFX_MODULE_STATE* AfxGetModuleState() return &g_CustomModuleState; } -inline void AfxMessageBox(const char* message) -{ -} +void AfxMessageBox(const char* message); inline void* GetProcAddress(HMODULE module, const char* name) { @@ -633,9 +628,7 @@ inline HMENU GetSystemMenu(HWND hWnd, bool bRevert) return reinterpret_cast(0x1234); } -inline VOID WINAPI Sleep(DWORD dwMilliseconds) -{ -} +VOID WINAPI Sleep(DWORD dwMilliseconds); inline HWND WINAPI FindWindow(LPCSTR lpClassName, LPCSTR lpWindowName) { diff --git a/miniwin/stdafx.cpp b/miniwin/stdafx.cpp new file mode 100644 index 00000000..e1b23771 --- /dev/null +++ b/miniwin/stdafx.cpp @@ -0,0 +1,78 @@ +#include "../CONFIG/config.h" +#include "miniwin.h" + +#include + +SDL_Window* window; +const char* title = "Configure LEGO Island"; + +BOOL CWinApp::InitInstance() +{ + if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK)) { + SDL_Log("SDL_Init: %s\n", SDL_GetError()); + return FALSE; + } + + window = SDL_CreateWindow(title, 640, 480, 0); + + return TRUE; +} + +int CWinApp::ExitInstance() +{ + SDL_Quit(); + return 0; +} + +CWinApp::~CWinApp() = default; + +const char* afxCurrentAppName = ""; +AFX_MODULE_STATE g_CustomModuleState; +CWinApp* wndTop; + +int main(int argc, char* argv[]) +{ + CWinApp base; + if (!base.InitInstance()) { + return 1; + } + + CConfigApp app; + wndTop = &app; + if (!app.InitInstance()) { + return 1; + } + + SDL_Event event; + bool running = true; + while (running) { + while (SDL_PollEvent(&event)) { + if (event.type == SDL_EVENT_QUIT) { + running = false; + } + } + + SDL_Delay(16); // 60 FPS + } + + return base.ExitInstance() + app.ExitInstance(); +} + +BOOL GetWindowRect(HWND hDlg, tagRECT* Rect) +{ + int x, y, w, h; + SDL_GetWindowPosition(window, &x, &y); + SDL_GetWindowSize(window, &w, &h); + + Rect->right = x; + Rect->top = y; + Rect->left = w + x; + Rect->bottom = h + y; + + return TRUE; +} + +void AfxMessageBox(const char* message) +{ + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, NULL); +} diff --git a/util/stdafx.cpp b/util/stdafx.cpp deleted file mode 100644 index 5d108e95..00000000 --- a/util/stdafx.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "../CONFIG/config.h" -#include "miniwin.h" - -BOOL CWinApp::InitInstance() -{ - return TRUE; -} - -int CWinApp::ExitInstance() -{ - return 0; -} - -CWinApp::~CWinApp() = default; - -const char* afxCurrentAppName = ""; -AFX_MODULE_STATE g_CustomModuleState; -CWinApp* wndTop; - -int main(int argc, char* argv[]) -{ - CConfigApp app; - wndTop = &app; - if (!app.InitInstance()) { - return 1; - } - return app.ExitInstance(); -}