AutoStart - Launch applications automatically when starting visual studio





2.00/5 (2 votes)
This is an addin for visual studio 2003 and 2005, it launches applications which your defined automatically when starting visual studio
Introduction
When I open visual studio to do some code work, I often need to run several utiltiy to help me make my work easy and with funs. I write this very simple addin to do these things automatically, when start visual studio, it load informations from an ini file, and launch the utility applications which I need, and close them when I exit visual studio.
Using the code
The code is very simple, there's only one class and several functions.
first the class CAppInfo, it descript the application we want to run:
class CAppInfo
{
public:
string strWindowTitle; // the main window title
string strAppPath; // the application's exe file path
BOOL bLoaded; // indicate if the application is launch by this addin
CAppInfo & operator =(CAppInfo & ai)
{
strWindowTitle = ai.strWindowTitle;
strAppPath = ai.strAppPath;
bLoaded = ai.bLoaded;
return * this;
}
};
Next one variable and four functions in CConect:
protected:
list<cappinfo> AppList; // store the applications info loaded from an ini file
void LoadAppInfo(LPCTSTR strIniFile); // load applications info from ini file
void LaunchApp(CAppInfo & ai); // launch an application
void StartApp(LPCTSTR strIniFile); // load applications info from ini file and launch then all
void EndApp(void); // close all launched applications
Their functions descript in the comment.
Last, call our functions at appropriate time, in CConnect class:
STDMETHODIMP CConnect::OnStartupComplete (SAFEARRAY ** /*custom*/ )
{
StartApp(STRINIFILE);
return S_OK;
}
STDMETHODIMP CConnect::OnBeginShutdown (SAFEARRAY ** /*custom*/ )
{
EndApp();
return S_OK;
}
That's all.
The ini file
It use an ini file named AutoStart.ini to descript the applications info, it must be put to your system folder(C:\\windows or something like that).
if you want to launch "n" applications, it must have n sections. The sections named [Application 1], [Application 2], ..., [Application n], each section descripted an application. Below is a sample:
[Application 1]
ClassName=AfxFrameOrView42s
WindowTitle="Perfect Keyboard - cpp.4pk"
AppPath="E:\Program Files\Perfect Keyboard AS\pk32.exe"
[Application 2]
ClassName=HamsinClipboardClassName
AppPath="E:\Program Files\Hamsin Clipboard\HamsinClipboard.exe"
We use "ClassName" and "WindowTitle" to find the application's main window so we can close it by send a WM_CLOSE message when we exit the visual studio, so they are optional.
We need the "AppPath" to launch the application, so it necessary.
History
2007-05-16 original version posted.