Click here to Skip to main content
15,880,392 members
Articles / Desktop Programming / ATL
Article

AutoStart - Launch applications automatically when starting visual studio

Rate me:
Please Sign up or sign in to vote.
2.00/5 (2 votes)
15 May 2007CPOL1 min read 26K   190   7   3
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:

C++
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:

C++
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:

C++
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Rantthanks Pin
Milad.D23-Jun-10 0:33
Milad.D23-Jun-10 0:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.