diff --git a/src/win/win.c b/src/win/win.c
index 8afaa3c27..f4481feed 100644
--- a/src/win/win.c
+++ b/src/win/win.c
@@ -339,14 +339,6 @@ ProcessCommandLine(wchar_t ***argw)
}
-static void
-shutdown_notify(void)
-{
- if (source_hwnd)
- PostMessage((HWND) (uintptr_t) source_hwnd, WM_SENDSDSTATUS, (WPARAM) 1, (LPARAM) hwndMain);
-}
-
-
/* For the Windows platform, this is the start of the application. */
int WINAPI
WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nCmdShow)
@@ -386,7 +378,7 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nCmdShow)
CreateConsole(0);
if (source_hwnd)
- PostMessage((HWND) (uintptr_t) source_hwnd, WM_SENDSDSTATUS, (WPARAM) 1, (LPARAM) hwndMain);
+ PostMessage((HWND) (uintptr_t) source_hwnd, WM_HAS_SHUTDOWN, (WPARAM) 0, (LPARAM) hwndMain);
return(1);
}
@@ -398,8 +390,6 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nCmdShow)
/* Handle our GUI. */
i = ui_init(nCmdShow);
- atexit(shutdown_notify);
-
return(i);
}
@@ -437,7 +427,8 @@ do_stop(void)
plat_delay_ms(100);
- shutdown_notify();
+ if (source_hwnd)
+ PostMessage((HWND) (uintptr_t) source_hwnd, WM_HAS_SHUTDOWN, (WPARAM) 0, (LPARAM) hwndMain);
pc_close(thMain);
diff --git a/src/win/win.h b/src/win/win.h
index 554e7b40e..05ce73978 100644
--- a/src/win/win.h
+++ b/src/win/win.h
@@ -8,7 +8,7 @@
*
* Platform support defintions for Win32.
*
- * Version: @(#)win.h 1.0.27 2019/11/02
+ * Version: @(#)win.h 1.0.28 2019/11/02
*
* Authors: Sarah Walker,
* Miran Grca,
@@ -43,7 +43,12 @@
#define SB_MENU_NAME L"StatusBarMenu"
#define FS_CLASS_NAME L"86BoxFullScreen"
-/* Application-specific window messages. */
+/* Application-specific window messages.
+
+ A dialog sends 0x8895 with WPARAM = 1 followed by 0x8896 with WPARAM = 1 on open,
+ and 0x8895 with WPARAM = followed by 0x8896 with WPARAM = 0.
+
+ All shutdowns will send an 0x8897. */
#define WM_RESETD3D WM_USER
#define WM_LEAVEFULLSCREEN WM_USER+1
#define WM_SAVESETTINGS 0x8888
@@ -55,10 +60,10 @@
#define WM_CTRLALTDEL 0x8894
/* Pause/resume status: WPARAM = 1 for paused, 0 for resumed. */
#define WM_SENDSTATUS 0x8895
-/* Settings status: WPARAM = 1 for open, 0 for closed. */
-#define WM_SENDSSTATUS 0x8896
-/* Emulator shut down status: WPARAM = 1 for user said yes, 0 for use said no. */
-#define WM_SENDSDSTATUS 0x8897
+/* Dialog (Settings or message box) status: WPARAM = 1 for open, 0 for closed. */
+#define WM_SENDDLGSTATUS 0x8896
+/* The emulator has shut down. */
+#define WM_HAS_SHUTDOWN 0x8897
#ifdef USE_VNC
#ifdef USE_D2D
@@ -118,6 +123,9 @@ extern void win_mouse_close(void);
extern void win_mouse_handle(LPARAM lParam, int infocus);
#endif
+extern void win_notify_dlg_open(void);
+extern void win_notify_dlg_closed(void);
+
extern LPARAM win_get_string(int id);
extern intptr_t fdd_type_to_icon(int type);
diff --git a/src/win/win_settings.c b/src/win/win_settings.c
index 7c60ec5b1..5fda27cf3 100644
--- a/src/win/win_settings.c
+++ b/src/win/win_settings.c
@@ -8,7 +8,7 @@
*
* Windows 86Box Settings dialog handler.
*
- * Version: @(#)win_settings.c 1.0.58 2019/11/02
+ * Version: @(#)win_settings.c 1.0.60 2019/11/02
*
* Authors: Miran Grca,
* David Hrdlička,
@@ -4477,14 +4477,6 @@ win_settings_main_insert_categories(HWND hwndList)
-static void
-win_settings_communicate_closure(void)
-{
- if (source_hwnd)
- PostMessage((HWND) (uintptr_t) source_hwnd, WM_SENDSSTATUS, (WPARAM) 0, (LPARAM) hwndMain);
-}
-
-
#if defined(__amd64__) || defined(__aarch64__)
static LRESULT CALLBACK
#else
@@ -4502,8 +4494,7 @@ win_settings_confirm(HWND hdlg, int button)
DestroyWindow(hwndChildDialog);
EndDialog(hdlg, 0);
- plat_pause(dopause);
- win_settings_communicate_closure();
+ win_notify_dlg_closed();
return button ? TRUE : FALSE;
} else
@@ -4555,8 +4546,7 @@ win_settings_main_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
case IDCANCEL:
DestroyWindow(hwndChildDialog);
EndDialog(hdlg, 0);
- plat_pause(dopause);
- win_settings_communicate_closure();
+ win_notify_dlg_closed();
return TRUE;
}
break;
@@ -4571,10 +4561,7 @@ win_settings_main_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
void
win_settings_open_ex(HWND hwnd, int category)
{
- plat_pause(1);
-
- if (source_hwnd)
- PostMessage((HWND) (uintptr_t) source_hwnd, WM_SENDSSTATUS, (WPARAM) 1, (LPARAM) hwndMain);
+ win_notify_dlg_open();
first_cat = category;
DialogBox(hinstance, (LPCWSTR)DLG_CONFIG, hwnd, win_settings_main_proc);
diff --git a/src/win/win_ui.c b/src/win/win_ui.c
index 7908cbd43..312a76826 100644
--- a/src/win/win_ui.c
+++ b/src/win/win_ui.c
@@ -8,7 +8,7 @@
*
* user Interface module for WinAPI on Windows.
*
- * Version: @(#)win_ui.c 1.0.43 2019/11/02
+ * Version: @(#)win_ui.c 1.0.44 2019/11/02
*
* Authors: Sarah Walker,
* Miran Grca,
@@ -65,7 +65,7 @@ WCHAR wopenfilestring[260];
static wchar_t wTitle[512];
static HHOOK hKeyboardHook;
static int hook_enabled = 0, manager_wm = 0;
-static int save_window_pos = 0;
+static int save_window_pos = 0, pause_state = 0;
static int vis = -1;
@@ -270,6 +270,27 @@ LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
}
+void
+win_notify_dlg_open(void)
+{
+ manager_wm = 1;
+ pause_state = dopause;
+ plat_pause(1);
+ if (source_hwnd)
+ PostMessage((HWND) (uintptr_t) source_hwnd, WM_SENDDLGSTATUS, (WPARAM) 1, (LPARAM) hwndMain);
+}
+
+
+void
+win_notify_dlg_closed(void)
+{
+ if (source_hwnd)
+ PostMessage((HWND) (uintptr_t) source_hwnd, WM_SENDDLGSTATUS, (WPARAM) 0, (LPARAM) hwndMain);
+ plat_pause(pause_state);
+ manager_wm = 0;
+}
+
+
static LRESULT CALLBACK
MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
@@ -297,13 +318,11 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
case IDM_ACTION_HRESET:
- manager_wm = 1;
- plat_pause(1);
+ win_notify_dlg_open();
i = ui_msgbox(MBX_QUESTION_YN, (wchar_t *)IDS_2121);
if (i == 0)
pc_reset(1);
- plat_pause(dopause);
- manager_wm = 0;
+ win_notify_dlg_closed();
break;
case IDM_ACTION_RESET_CAD:
@@ -311,16 +330,14 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
case IDM_ACTION_EXIT:
- manager_wm = 1;
- plat_pause(1);
+ win_notify_dlg_open();
i = ui_msgbox(MBX_QUESTION_YN, (wchar_t *)IDS_2122);
if (i == 0) {
UnhookWindowsHookEx(hKeyboardHook);
KillTimer(hwnd, TIMER_1SEC);
PostQuitMessage(0);
- } else
- plat_pause(dopause);
- manager_wm = 0;
+ }
+ win_notify_dlg_closed();
break;
case IDM_ACTION_CTRL_ALT_ESC:
@@ -677,16 +694,14 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
return(0);
case WM_CLOSE:
- manager_wm = 1;
- plat_pause(1);
+ win_notify_dlg_open();
i = ui_msgbox(MBX_QUESTION_YN, (wchar_t *)IDS_2122);
if (i == 0) {
UnhookWindowsHookEx(hKeyboardHook);
KillTimer(hwnd, TIMER_1SEC);
PostQuitMessage(0);
- } else
- plat_pause(dopause);
- manager_wm = 0;
+ }
+ win_notify_dlg_closed();
break;
case WM_DESTROY:
@@ -709,38 +724,30 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
manager_wm = 1;
plat_pause(dopause ^ 1);
CheckMenuItem(menuMain, IDM_ACTION_PAUSE, dopause ? MF_CHECKED : MF_UNCHECKED);
- plat_pause(dopause);
manager_wm = 0;
break;
case WM_HARDRESET:
if (manager_wm)
break;
- manager_wm = 1;
- plat_pause(1);
+ win_notify_dlg_open();
i = ui_msgbox(MBX_QUESTION_YN, (wchar_t *)IDS_2121);
if (i == 0)
pc_reset(1);
- plat_pause(dopause);
- manager_wm = 0;
+ win_notify_dlg_closed();
break;
case WM_SHUTDOWN:
if (manager_wm)
break;
- manager_wm = 1;
- plat_pause(1);
+ win_notify_dlg_open();
i = ui_msgbox(MBX_QUESTION_YN, (wchar_t *)IDS_2122);
if (i == 0) {
UnhookWindowsHookEx(hKeyboardHook);
KillTimer(hwnd, TIMER_1SEC);
PostQuitMessage(0);
- } else {
- if (source_hwnd)
- PostMessage((HWND) (uintptr_t) source_hwnd, WM_SENDSDSTATUS, (WPARAM) 0, (LPARAM) hwndMain);
- plat_pause(dopause);
}
- manager_wm = 0;
+ win_notify_dlg_closed();
break;
case WM_CTRLALTDEL:
@@ -1071,7 +1078,13 @@ plat_pause(int p)
p = get_vidpause();
/* If already so, done. */
- if (dopause == p) return;
+ if (dopause == p) {
+ /* Send the WM to a manager if needed. */
+ if (source_hwnd)
+ PostMessage((HWND) (uintptr_t) source_hwnd, WM_SENDSTATUS, (WPARAM) !!dopause, (LPARAM) hwndMain);
+
+ return;
+ }
if (p) {
wcscpy(oldtitle, ui_window_title(NULL));