|
/* AutoStartUp.cpp
*
* Copyright (C) 3 September, 2005 Priyank Bolia
* http://www.priyank.in
*
* This code is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA
*/
#include "autostartup.h"
bool wxAutoStartUp(bool bAdd, wxString strAppName, wxString strAppPath)
{
if(strAppName == wxT(""))
{
strAppName = wxTheApp->GetAppName();
}
if(strAppPath == wxT(""))
{
strAppPath = GetExecutablePath();
}
#ifdef __WXMSW__
wxRegKey *pRegKey = new wxRegKey("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run");
//will return false if the key does not exist
if( !pRegKey->Exists() )
{
delete pRegKey;
return false;
}
if(bAdd)
{
strAppPath = wxT("\"") + strAppPath + wxT("\"");
if(!pRegKey->SetValue(strAppName, strAppPath))
{
delete pRegKey;
return false;
}
}
else
{
pRegKey->DeleteValue(strAppName);
}
delete pRegKey;
return true;
#endif
return false;
}
#ifdef __WXMAC__
# ifdef __DARWIN__
# include
# else
# include
# endif
# include "wx/filename.h"
#endif
wxString GetExecutablePath(void)
{
static bool found = false;
static wxString path;
if (found)
return path;
else
{
#ifdef __WXMSW__
char buf[512];
*buf = '\0';
GetModuleFileName(NULL, buf, 511);
path = buf;
#elif defined(__WXMAC__)
ProcessInfoRec processinfo;
ProcessSerialNumber procno ;
FSSpec fsSpec;
procno.highLongOfPSN = NULL ;
procno.lowLongOfPSN = kCurrentProcess ;
processinfo.processInfoLength = sizeof(ProcessInfoRec);
processinfo.processName = NULL;
processinfo.processAppSpec = &fsSpec;
GetProcessInformation( &procno , &processinfo ) ;
path = wxMacFSSpec2MacFilename(&fsSpec);
#else
wxString argv0 = wxTheApp->argv[0];
if (wxIsAbsolutePath(argv0))
path = argv0;
else
{
wxPathList pathlist;
pathlist.AddEnvList(wxT("PATH"));
path = pathlist.FindAbsoluteValidPath(argv0);
}
wxFileName filename(path);
filename.Normalize();
path = filename.GetFullPath();
#endif
found = true;
return path;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.