Skip to content
This repository was archived by the owner on Aug 23, 2025. It is now read-only.

Commit dc2642e

Browse files
committed
Fixed issue #68
Manager now waits for the user to answer the shutdown confirmaton dialog in 86Box before doing anything else with the VM
1 parent 10e59d7 commit dc2642e

File tree

1 file changed

+60
-31
lines changed

1 file changed

+60
-31
lines changed

86BoxManager/frmMain.cs

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ public partial class frmMain : Form
2020
[return: MarshalAs(UnmanagedType.Bool)]
2121
static extern bool IsWindow(IntPtr hWnd); //Checks if hWnd belongs to an existing window
2222

23+
//Posts a message to the window with specified handle - DOES NOT WAIT FOR THE RECIPIENT TO PROCESS THE MESSAGE!!!
2324
[DllImport("user32.dll")]
24-
public static extern int PostMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam); //Sends a message to the window of hWnd
25+
public static extern int PostMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
26+
27+
//Sends a message to the window with specified handle - WAITS FOR THE RECIPIENT TO PROCESS THE MESSAGE!!!
28+
[DllImport("user32.dll")]
29+
public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
2530

2631
[StructLayout(LayoutKind.Sequential)]
2732
public struct COPYDATASTRUCT
@@ -649,35 +654,7 @@ private void VMStop()
649654
{
650655
if (vm.Status == VM.STATUS_RUNNING || vm.Status == VM.STATUS_PAUSED)
651656
{
652-
PostMessage(vm.hWnd, 0x8893, IntPtr.Zero, IntPtr.Zero);
653-
vm.Status = VM.STATUS_STOPPED;
654-
vm.hWnd = IntPtr.Zero;
655-
lstVMs.SelectedItems[0].SubItems[1].Text = vm.GetStatusString();
656-
lstVMs.SelectedItems[0].ImageIndex = 0;
657-
658-
btnStart.Text = "Start";
659-
toolTip.SetToolTip(btnStart, "Start this virtual machine");
660-
btnPause.Text = "Pause";
661-
if (lstVMs.SelectedItems.Count > 0)
662-
{
663-
btnEdit.Enabled = true;
664-
btnDelete.Enabled = true;
665-
btnStart.Enabled = true;
666-
btnConfigure.Enabled = true;
667-
btnPause.Enabled = false;
668-
btnReset.Enabled = false;
669-
btnCtrlAltDel.Enabled = false;
670-
}
671-
else
672-
{
673-
btnEdit.Enabled = false;
674-
btnDelete.Enabled = false;
675-
btnStart.Enabled = false;
676-
btnConfigure.Enabled = false;
677-
btnPause.Enabled = false;
678-
btnReset.Enabled = false;
679-
btnCtrlAltDel.Enabled = false;
680-
}
657+
SendMessage(vm.hWnd, 0x8893, IntPtr.Zero, IntPtr.Zero);
681658
}
682659
}
683660
catch(Exception ex)
@@ -1043,9 +1020,12 @@ private void btnPause_Click(object sender, EventArgs e)
10431020
//This function monitors recieved window messages
10441021
protected override void WndProc(ref Message m)
10451022
{
1046-
// WM_SENDSTATUS (0x8895) - wparam = 1: vm paused, wparam = 0: vm resumed
1023+
// WM_SENDSTATUS (0x8895) - wparam = 1: VM paused, wparam = 0: VM resumed
10471024
// WM_SENDSSTATUS (0x8896) - wparam = 1: settings open, wparam = 0: settings closed
10481025
// NOTE: This code works only with 86Box build 1799 or later!!!
1026+
//
1027+
// WM_SHUTDOWN_DONE (0x8897) - user confirmed shutdown
1028+
// NOTE: This one works only with 86Box build 2006 or later!!!
10491029
if (m.Msg == 0x8895)
10501030
{
10511031
if (m.WParam.ToInt32() == 1) //VM was paused
@@ -1134,6 +1114,55 @@ protected override void WndProc(ref Message m)
11341114
}
11351115
}
11361116
}
1117+
if (m.Msg == 0x8897) //User confirmed shutdown
1118+
{
1119+
foreach (ListViewItem lvi in lstVMs.Items)
1120+
{
1121+
VM vm = (VM)lvi.Tag;
1122+
if (vm.hWnd.Equals(m.LParam) && vm.Status != VM.STATUS_STOPPED)
1123+
{
1124+
vm.Status = VM.STATUS_STOPPED;
1125+
vm.hWnd = IntPtr.Zero;
1126+
lvi.SubItems[1].Text = vm.GetStatusString();
1127+
lvi.ImageIndex = 0;
1128+
1129+
btnStart.Text = "Start";
1130+
toolTip.SetToolTip(btnStart, "Start this virtual machine");
1131+
btnPause.Text = "Pause";
1132+
if (lstVMs.SelectedItems.Count == 1)
1133+
{
1134+
btnEdit.Enabled = true;
1135+
btnDelete.Enabled = true;
1136+
btnStart.Enabled = true;
1137+
btnConfigure.Enabled = true;
1138+
btnPause.Enabled = false;
1139+
btnReset.Enabled = false;
1140+
btnCtrlAltDel.Enabled = false;
1141+
}
1142+
else if (lstVMs.SelectedItems.Count == 0)
1143+
{
1144+
btnEdit.Enabled = false;
1145+
btnDelete.Enabled = false;
1146+
btnStart.Enabled = false;
1147+
btnConfigure.Enabled = false;
1148+
btnPause.Enabled = false;
1149+
btnReset.Enabled = false;
1150+
btnCtrlAltDel.Enabled = false;
1151+
}
1152+
else
1153+
{
1154+
btnEdit.Enabled = false;
1155+
btnDelete.Enabled = true;
1156+
btnStart.Enabled = false;
1157+
btnConfigure.Enabled = false;
1158+
btnPause.Enabled = false;
1159+
btnReset.Enabled = false;
1160+
btnCtrlAltDel.Enabled = false;
1161+
}
1162+
}
1163+
}
1164+
}
1165+
11371166
//This is the WM_COPYDATA message, used here to pass command line args to an already running instance
11381167
//NOTE: This code will have to be modified in case more command line arguments are added in the future.
11391168
if (m.Msg == 0x004A)

0 commit comments

Comments
 (0)