JeffV wrote:
Can anyone tell me if this is even possible? What I want to do is something like the following:
I have a small user interface I developed in Visual Studio (2005). I want this program to launch another Windows program that was developed by someone else at the press of a button.
The other application I would run normally brings up a big window with lots of complicated menus. In this case, I would like to hide all this from the user (they don't need to see it) and let it run in the background. All they would see is my simpler interface I developed. So is it possible to either launch this other application and keep it minimized, or maybe specify the position of the window to be off-screen (this might be preferred)?
If anyone has any ideas how to accomplish this, it would be greatly appreciated. Thanks!
Couple of questions on this.
1. Is the Child Process a windowless application or console application or does it have its own gui?
2. If it has its own gui is their an sdk or api available for this application?
3. If it has its own gui and there is an sdk or api for this application is it redistributable under appropriate licenses?
Generally speaking without an sdk or api written to expose methods and properties to the developer where a windows GUI is involved there is no way to "access" the executable at the command level (like passing runtime parameters to the application in the case of a DOS style command) other than running the application.
That said it is possible to call an external process or library inside a program written in .NET (C# C++ VB J++ or other .NET language) by creating a reference to an object in your project and then using the CreateObject function to open an instance of an object.
Consider the following example:
C#
Code:
using Excel = Microsoft.Office.Interop.Excel;
.
.
.
public class ExcelObjectTest()
{
.
.
.
private static string m_OutputFilePath = "";
private static string m_OutputFileName = "";
private static string m_OutputFileExtension = "";
public static string OutputFilePath{get{return m_OutputfilePath;}set{m_OutputFilePath = value;}}
public static string OutputFileName{get{return m_OutputFileName;}set{m_OutputFileName=value;}}
public static string OutputFileExtension{get{return m_OutputFileExtension;}set{m_OutputFileExtension=value;}}
public ExcelObjectTest()
{
try
{
OutputFilePath = "C:\\ExcelFiles\";
OutputFileName = "MyExcelFile";
OutputFileExtension = "xls";
ExcelFileName = OutputFilePath + OutputFileName + "." + OutputFileExtension;
Excel.Application objExcel = new Excel.Application();
Excel.Workbooks oWorkbooks = (Excel.Workbooks)objExcel.Workbooks;
Excel.Workbook objbook = (Excel.Workbook)(oWorkbooks.Add(objOpt));
Excel.Sheets objSheets = (Excel.Sheets)objbook.Worksheets;
Excel.Worksheet objSheet = (Excel.Worksheet)(objSheets.get_Item(1));
objSheet.Cells[1, 1] = "PRODUCT";
objSheet.Cells[1, 2] = "GL";
Range objRange;
objRange = objSheet.UsedRange;
objRange.Columns.AutoFit();
objRange.Rows.AutoFit();
objRange = null;
objbook.SaveAs(ExcelFileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
objbook.Close(XlSaveAction.xlSaveChanges, ExcelFileName, Type.Missing);
objSheet = null;
objbook = null;
catch(Exception ex)
{
//Implement exception handler here
}
finally
{
// do cleanup here
// because its Excel use a kill process call to ensure garbage cleanup happens in a timely fashion
KillExcell(Excel);
}
}
}
The previous code snippet shows one way to instantiate an object within your application. There are other ways to do this in .NET each with its advantages and disadvantages. The important parts of the code are the using line and the instantiation lines. If your object follows a particular object application model like Office and has a library that can be included int the solution or project the set a reference to the object call the using/imports functionality Instantiate the object and set its properties (if exposed) then end any methods used Close any subsidiary objects then the object itself then destroy the object or call for garbage cleanup.
If the application does not have this and it uses a Windows GUI its still possible to use the application directly through either an api call or by setting a reference directly to the application through the using/imports call and then obtaining a list of properties and methods through either CreateObject or CreateServer for the object.
Now again I must stress that a runtime redistributable or License must be available to use these methods. Using another application without the owners permission is Illegal and it is probably impossible to do if that functionality is not exposed by the application in question.
HTH