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

Commit 37cf4cc

Browse files
committed
Fixed issue with shortcuts and stopping VMs
1 parent 18a1e02 commit 37cf4cc

File tree

1 file changed

+48
-39
lines changed

1 file changed

+48
-39
lines changed

86BoxManager/frmMain.cs

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using System.Collections.Generic;
1111
using System.Threading;
1212
using _86BoxManager;
13-
//using _86BoxManager;
1413

1514
namespace _86boxManager
1615
{
@@ -25,11 +24,11 @@ public partial class frmMain : Form
2524
public static extern int PostMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam); //Sends a message to the window of hWnd
2625

2726
[StructLayout(LayoutKind.Sequential)]
28-
public struct CopyDataStruct
27+
public struct COPYDATASTRUCT
2928
{
30-
public string ID;
31-
public int Length;
32-
public string Data;
29+
public IntPtr dwData;
30+
public int cbData;
31+
public IntPtr lpData;
3332
}
3433

3534
private static RegistryKey regkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\86Box", true); //Registry key for accessing the settings and VM list
@@ -59,13 +58,15 @@ private void frmMain_Load(object sender, EventArgs e)
5958
//Check if command line arguments for starting a VM are OK
6059
if (Program.args.Length == 3 && Program.args[1] == "-S" && Program.args[2] != null)
6160
{
61+
Console.WriteLine(Program.args[2]);
6262
//Find the VM with given name
6363
ListViewItem lvi = lstVMs.FindItemWithText(Program.args[2], false, 0, false);
6464

6565
//Then select and start it if it's found
6666
if (lvi != null)
6767
{
6868
lvi.Focused = true;
69+
lvi.Selected = true;
6970
VMStart();
7071
}
7172
else
@@ -576,38 +577,45 @@ private void VMStart()
576577
private void VMStop()
577578
{
578579
VM vm = (VM)lstVMs.SelectedItems[0].Tag;
579-
if (vm.Status == VM.STATUS_RUNNING || vm.Status == VM.STATUS_PAUSED)
580+
try
580581
{
581-
PostMessage(vm.hWnd, 0x8893, IntPtr.Zero, IntPtr.Zero);
582-
vm.Status = VM.STATUS_STOPPED;
583-
vm.hWnd = IntPtr.Zero;
584-
lstVMs.SelectedItems[0].SubItems[1].Text = vm.GetStatusString();
585-
lstVMs.SelectedItems[0].ImageIndex = 0;
586-
587-
btnStart.Text = "Start";
588-
toolTip.SetToolTip(btnStart, "Start this virtual machine");
589-
btnPause.Text = "Pause";
590-
if (lstVMs.SelectedItems.Count > 0)
591-
{
592-
btnEdit.Enabled = true;
593-
btnDelete.Enabled = true;
594-
btnStart.Enabled = true;
595-
btnConfigure.Enabled = true;
596-
btnPause.Enabled = false;
597-
btnReset.Enabled = false;
598-
btnCtrlAltDel.Enabled = false;
599-
}
600-
else
582+
if (vm.Status == VM.STATUS_RUNNING || vm.Status == VM.STATUS_PAUSED)
601583
{
602-
btnEdit.Enabled = false;
603-
btnDelete.Enabled = false;
604-
btnStart.Enabled = false;
605-
btnConfigure.Enabled = false;
606-
btnPause.Enabled = false;
607-
btnReset.Enabled = false;
608-
btnCtrlAltDel.Enabled = false;
584+
PostMessage(vm.hWnd, 0x8893, IntPtr.Zero, IntPtr.Zero);
585+
vm.Status = VM.STATUS_STOPPED;
586+
vm.hWnd = IntPtr.Zero;
587+
lstVMs.SelectedItems[0].SubItems[1].Text = vm.GetStatusString();
588+
lstVMs.SelectedItems[0].ImageIndex = 0;
589+
590+
btnStart.Text = "Start";
591+
toolTip.SetToolTip(btnStart, "Start this virtual machine");
592+
btnPause.Text = "Pause";
593+
if (lstVMs.SelectedItems.Count > 0)
594+
{
595+
btnEdit.Enabled = true;
596+
btnDelete.Enabled = true;
597+
btnStart.Enabled = true;
598+
btnConfigure.Enabled = true;
599+
btnPause.Enabled = false;
600+
btnReset.Enabled = false;
601+
btnCtrlAltDel.Enabled = false;
602+
}
603+
else
604+
{
605+
btnEdit.Enabled = false;
606+
btnDelete.Enabled = false;
607+
btnStart.Enabled = false;
608+
btnConfigure.Enabled = false;
609+
btnPause.Enabled = false;
610+
btnReset.Enabled = false;
611+
btnCtrlAltDel.Enabled = false;
612+
}
609613
}
610614
}
615+
catch(Exception ex)
616+
{
617+
MessageBox.Show("An error occurred trying to stop the selected virtual machine.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
618+
}
611619
}
612620

613621
//Start VM if it's stopped or stop it if it's running/paused
@@ -1022,8 +1030,9 @@ protected override void WndProc(ref Message m)
10221030
if (m.Msg == 0x004A)
10231031
{
10241032
//Get the VM name and find the associated LVI and VM object
1025-
CopyDataStruct ds = (CopyDataStruct)m.GetLParam(typeof(CopyDataStruct));
1026-
ListViewItem lvi = lstVMs.FindItemWithText(ds.Data);
1033+
COPYDATASTRUCT ds = (COPYDATASTRUCT)m.GetLParam(typeof(COPYDATASTRUCT));
1034+
string vmName = Marshal.PtrToStringAnsi(ds.lpData, ds.cbData);
1035+
ListViewItem lvi = lstVMs.FindItemWithText(vmName);
10271036

10281037
//This check is necessary in case the specified VM was already removed but the shortcut remains
10291038
if (lvi != null)
@@ -1033,7 +1042,7 @@ protected override void WndProc(ref Message m)
10331042
//If the VM is already running, display an error, otherwise, start it
10341043
if (vm.Status != VM.STATUS_STOPPED)
10351044
{
1036-
MessageBox.Show("The virtual machine \"" + ds.Data + "\" is already running.", "Virtual machine already running", MessageBoxButtons.OK, MessageBoxIcon.Information);
1045+
MessageBox.Show("The virtual machine \"" + vmName + "\" is already running.", "Virtual machine already running", MessageBoxButtons.OK, MessageBoxIcon.Information);
10371046
}
10381047
else
10391048
{
@@ -1044,7 +1053,7 @@ protected override void WndProc(ref Message m)
10441053
}
10451054
else
10461055
{
1047-
MessageBox.Show("The virtual machine \"" + ds.Data + "\" could not be found. It may have been removed or the specified name is incorrect.", "Virtual machine not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
1056+
MessageBox.Show("The virtual machine \"" + vmName + "\" could not be found. It may have been removed or the specified name is incorrect.", "Virtual machine not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
10481057
}
10491058
}
10501059
base.WndProc(ref m);
@@ -1186,7 +1195,7 @@ private void VMKill()
11861195
{
11871196
VM vm = (VM)lstVMs.SelectedItems[0].Tag;
11881197
try
1189-
{
1198+
{
11901199
Process p = Process.GetProcessById(vm.Pid);
11911200
p.Kill();
11921201
}
@@ -1277,7 +1286,7 @@ private void VMWipe()
12771286
catch (Exception ex)
12781287
{
12791288
MessageBox.Show("An error occurred trying to wipe the selected virtual machine.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
1280-
}
1289+
}
12811290
}
12821291
}
12831292

0 commit comments

Comments
 (0)