From 01ad1ed98c132d5a5f065eb5cf3d78e20ced320e Mon Sep 17 00:00:00 2001 From: SarahW Date: Fri, 10 Jun 2016 20:49:03 +0100 Subject: [PATCH] Add option to remember window size & position. --- src/ibm.h | 1 + src/pc.c | 14 ++++++++++++++ src/pc.rc | 1 + src/resources.h | 1 + src/win.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 62 insertions(+) diff --git a/src/ibm.h b/src/ibm.h index c5a5622..4bd838c 100644 --- a/src/ibm.h +++ b/src/ibm.h @@ -504,3 +504,4 @@ void onesec(); void resetpc_cad(); extern int start_in_fullscreen; +extern int window_w, window_h, window_x, window_y, window_remember; diff --git a/src/pc.c b/src/pc.c index 53afd1b..4b00bf2 100644 --- a/src/pc.c +++ b/src/pc.c @@ -38,6 +38,8 @@ #include "vid_voodoo.h" #include "video.h" +int window_w, window_h, window_x, window_y, window_remember; + int start_in_fullscreen = 0; int frame = 0; @@ -647,6 +649,12 @@ void loadconfig(char *fn) fdd_set_type(0, config_get_int(NULL, "drive_a_type", 7)); fdd_set_type(1, config_get_int(NULL, "drive_b_type", 7)); + + window_w = config_get_int(NULL, "window_w", 0); + window_h = config_get_int(NULL, "window_h", 0); + window_x = config_get_int(NULL, "window_x", 0); + window_y = config_get_int(NULL, "window_y", 0); + window_remember = config_get_int(NULL, "window_remember", 0); } void saveconfig() @@ -700,6 +708,12 @@ void saveconfig() config_set_int(NULL, "drive_a_type", fdd_get_type(0)); config_set_int(NULL, "drive_b_type", fdd_get_type(1)); + + config_set_int(NULL, "window_w", window_w); + config_set_int(NULL, "window_h", window_h); + config_set_int(NULL, "window_x", window_x); + config_set_int(NULL, "window_y", window_y); + config_set_int(NULL, "window_remember", window_remember); config_save(config_file_default); } diff --git a/src/pc.rc b/src/pc.rc index 921015e..b83778e 100644 --- a/src/pc.rc +++ b/src/pc.rc @@ -33,6 +33,7 @@ BEGIN POPUP "&Video" BEGIN MENUITEM "&Resizeable window",IDM_VID_RESIZE + MENUITEM "Remember size && position",IDM_VID_REMEMBER MENUITEM SEPARATOR MENUITEM "&DirectDraw", IDM_VID_DDRAW MENUITEM "Direct&3D", IDM_VID_D3D diff --git a/src/resources.h b/src/resources.h index aef9948..2218ea0 100644 --- a/src/resources.h +++ b/src/resources.h @@ -12,6 +12,7 @@ #define IDM_CONFIG_SAVE 40022 #define IDM_STATUS 40030 #define IDM_VID_RESIZE 40050 +#define IDM_VID_REMEMBER 40051 #define IDM_VID_DDRAW 40060 #define IDM_VID_D3D 40061 #define IDM_VID_FULLSCREEN 40070 diff --git a/src/win.c b/src/win.c index 36b0a36..8d6c972 100644 --- a/src/win.c +++ b/src/win.c @@ -41,6 +41,7 @@ #define MAPVK_VK_TO_VSC 0 #endif +static int save_window_pos = 0; uint64_t timer_freq; int rawinputkey[272]; @@ -564,6 +565,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance, if (vid_resize) CheckMenuItem(menu, IDM_VID_RESIZE, MF_CHECKED); CheckMenuItem(menu, IDM_VID_DDRAW + vid_api, MF_CHECKED); CheckMenuItem(menu, IDM_VID_FS_FULL + video_fullscreen_scale, MF_CHECKED); + CheckMenuItem(menu, IDM_VID_REMEMBER, window_remember ? MF_CHECKED : MF_UNCHECKED); // set_display_switch_mode(SWITCH_BACKGROUND); d=romset; @@ -661,6 +663,13 @@ int WINAPI WinMain (HINSTANCE hThisInstance, endblit(); device_force_redraw(); } + if (window_remember) + { + MoveWindow(hwnd, window_x, window_y, + window_w, + window_h, + TRUE); + } /* Run the message loop. It will run until GetMessage() returns 0 */ while (!quited) @@ -707,6 +716,8 @@ int WINAPI WinMain (HINSTANCE hThisInstance, TerminateThread(mainthreadh,0); // pclog("Quited? %i\n",quited); // pclog("Closepc\n"); + if (save_window_pos && window_remember) + saveconfig(); closepc(); // pclog("dumpregs\n"); @@ -926,6 +937,19 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM SetWindowPos(hwnd, 0, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_FRAMECHANGED); saveconfig(); break; + case IDM_VID_REMEMBER: + window_remember = !window_remember; + CheckMenuItem(hmenu, IDM_VID_REMEMBER, window_remember ? MF_CHECKED : MF_UNCHECKED); + GetWindowRect(hwnd, &rect); + if (window_remember) + { + window_x = rect.left; + window_y = rect.top; + window_w = rect.right - rect.left; + window_h = rect.bottom - rect.top; + } + saveconfig(); + break; case IDM_VID_DDRAW: case IDM_VID_D3D: startblit(); @@ -1259,8 +1283,29 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM pcclip.bottom -= GetSystemMetrics(SM_CXFIXEDFRAME) + 10; ClipCursor(&pcclip); } + if (window_remember) + { + GetWindowRect(hwnd, &rect); + window_x = rect.left; + window_y = rect.top; + window_w = rect.right - rect.left; + window_h = rect.bottom - rect.top; + save_window_pos = 1; + } break; + case WM_MOVE: + if (window_remember) + { + GetWindowRect(hwnd, &rect); + window_x = rect.left; + window_y = rect.top; + window_w = rect.right - rect.left; + window_h = rect.bottom - rect.top; + save_window_pos = 1; + } + break; + case WM_TIMER: if (wParam == TIMER_1SEC) onesec();