As part of a program I am updating, I need to have a really really old program called labcalc to run. I have installed a program called dosbox to run it and it works well by opening and closing before and after each call to labcalc. Now I want to implement the idea of minimizing and maximizing vs open/closing on each call.
Here is what I did:
Try
If (labCalcProcess.Id > 0) Then ' this throws an error if it is not running, so handle it like a goto line.
tempLCProcID = labCalcProcess.Id
frmMain.TextBox1.Text = "labcalc was running"
AppActivate("LC")
Sleep(300)
System.Windows.Forms.SendKeys.SendWait("+(^%L)") ' this is the converted version of: SendKeys "+(^%L)" , True
System.Windows.Forms.SendKeys.SendWait("+(^(%(L)))") 'Hotkey for LabCalc is Shift, Alt, Ctrl, L
End If
Catch ex As Exception
frmMain.TextBox1.Text = "labcalc was not running"
labCalcProcess.StartInfo.Arguments = dosboxConfiguration 'pass it " -userconfig" to make dosbox work correctly
labCalcProcess.StartInfo.FileName = LabCalcPgm ' Tell the process where dosbox is located
labCalcProcess.Start() 'NOTE: LabCalc requires a startup macro "s" which starts SPECDRVR.AB
End Try
Now, my question is this: I had hoped to find something like labCalcProcess.IsRunning or Is minimized, or something like that, but can't. Is it ok to start the program like I am by catching the exception that was created in the If statement? or is there a better way. One thought was to try to find the open window and if you can't find it, then it must not be running. In fact now that I think about it I think that is a better way to go than catching an exception.
adam
Here is what I did:
Try
If (labCalcProcess.Id > 0) Then ' this throws an error if it is not running, so handle it like a goto line.
tempLCProcID = labCalcProcess.Id
frmMain.TextBox1.Text = "labcalc was running"
AppActivate("LC")
Sleep(300)
System.Windows.Forms.SendKeys.SendWait("+(^%L)") ' this is the converted version of: SendKeys "+(^%L)" , True
System.Windows.Forms.SendKeys.SendWait("+(^(%(L)))") 'Hotkey for LabCalc is Shift, Alt, Ctrl, L
End If
Catch ex As Exception
frmMain.TextBox1.Text = "labcalc was not running"
labCalcProcess.StartInfo.Arguments = dosboxConfiguration 'pass it " -userconfig" to make dosbox work correctly
labCalcProcess.StartInfo.FileName = LabCalcPgm ' Tell the process where dosbox is located
labCalcProcess.Start() 'NOTE: LabCalc requires a startup macro "s" which starts SPECDRVR.AB
End Try
Now, my question is this: I had hoped to find something like labCalcProcess.IsRunning or Is minimized, or something like that, but can't. Is it ok to start the program like I am by catching the exception that was created in the If statement? or is there a better way. One thought was to try to find the open window and if you can't find it, then it must not be running. In fact now that I think about it I think that is a better way to go than catching an exception.
adam