Click here to Skip to main content
15,915,163 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Change image saturation...? Pin
Christian Graus20-Mar-02 9:53
protectorChristian Graus20-Mar-02 9:53 
AnswerRe: Change image saturation...? Pin
Joaquín M López Muñoz20-Mar-02 10:50
Joaquín M López Muñoz20-Mar-02 10:50 
GeneralRe: Change image saturation...? Pin
Chris Losinger20-Mar-02 15:08
professionalChris Losinger20-Mar-02 15:08 
Generalcan't create modeless dialog Pin
Hans Ruck20-Mar-02 6:17
Hans Ruck20-Mar-02 6:17 
GeneralRe: can't create modeless dialog Pin
Joaquín M López Muñoz20-Mar-02 9:26
Joaquín M López Muñoz20-Mar-02 9:26 
Generalquick question - need the registry key name which makes application to start at boot - Thanks Pin
20-Mar-02 5:59
suss20-Mar-02 5:59 
GeneralRe: quick question - need the registry key name which makes application to start at boot - Thanks Pin
20-Mar-02 6:15
suss20-Mar-02 6:15 
GeneralRe: quick question - need the registry key name which makes application to start at boot - Thanks Pin
Bill Wilson20-Mar-02 6:56
Bill Wilson20-Mar-02 6:56 
If you only want it to happen once, use adara's suggestion with this key

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce


If you want it to run everytime the machine is restarted, a better practice is to put a short cut in the startup folder. All of the systems services will have started before the applications in the Startup folder are run.

BTW: The registry path shown above and those used in the sample below are guaranteed on all MS platforms.

Usage:

CreateShortcutEx("Startup","MyAppShortcut","What ever this thing does","c:\\program files\\MyAppFolder\\MyApp.exe","");

This routine builds the shortcut itself.


CString CHSD30App::CreateShortcutEx(CString szWhere, CString szLinkName, CString szDesc, CString szFile, CString szArguments){
//	TCHAR szFile[MAX_PATH];
//	TCHAR szDesc[MAX_PATH];
	TCHAR szLink[MAX_PATH];
	DWORD cchCurDir = MAX_PATH;
	DWORD cchStartDir = MAX_PATH;
	char *pDot;
	TCHAR szStartInDirectory[MAX_PATH];
    HRESULT hres;
    IShellLink *psl;
	HKEY hCU;
	DWORD lpType;
	ULONG ulSize = MAX_PATH;
	BOOL bRetVal;
	DWORD dwRetVal =  0;	// Set default value

	bRetVal = FALSE;		// Set to failure mode

	// Get the directory for the Startup Folder. This is
	// stored in the Registry under HKEY_CURRENT_USER\Software\
	// Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Startup.

	if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, 
			"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", 
			0,KEY_QUERY_VALUE,
			&hCU))
	{
		RegQueryValueEx( hCU,
			LPCSTR(szWhere),					// startup entry
			NULL,
			&lpType,
			(unsigned char *)&szLink,
			&ulSize);

		RegCloseKey(hCU);
	}

	// Set the path and filename to our cd's setup.exe
	//
		bRetVal =  FALSE;

	// Testing getting the file name sans extension
    pDot = strrchr(szFile, '.');

	// Add the forward slash for the path
	lstrcat (szLink, LPCSTR(szLinkName));

	// Strip off the extension, if any
	if (pDot = strstr(szLink, "."))
		*pDot = (char)NULL;

	// Add in the .LNK extension
	lstrcat (szLink, ".LNK");

	// Get the current directory.
//	GetCurrentDirectory(cchStartDir, _T(szStartInDirectory));


	// All the prep. work is done so create the actual shortcut.
	//
	// CoInitialize (ole and ishelllink require this)
	hres = CoInitialize(NULL);
	
	if( !SUCCEEDED(hres))        
		bRetVal = FALSE;
	else
		bRetVal = TRUE;

	// Create an IShellLink object and get a pointer to the IShellLink
	// interface (returned from CoCreateInstance).
    hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
                            IID_IShellLink, (void **)&psl);
    if (SUCCEEDED(hres))
    {
       IPersistFile *ppf;
       
	   // Query IShellLink for the IPersistFile interface for
	   // saving the shortcut in persistent storage.
       hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
	   if (SUCCEEDED(hres))
	   {   
	        WORD wsz[MAX_PATH];   // buffer for Unicode string

	   		// Set the path to the shortcut target.
          	hres = psl->SetPath(szFile);

			if (!SUCCEEDED(hres))
				bRetVal = FALSE;
			else
				bRetVal = TRUE;

			// Set the arguments
			if (!szArguments.IsEmpty())
			{
				hres = psl->SetArguments(szArguments);

				if (!SUCCEEDED(hres))
					bRetVal = FALSE;
				else
					bRetVal = TRUE;
			}

            // Set the description of the shortcut.
          	hres = psl->SetDescription(szDesc);

			if (!SUCCEEDED(hres))
				bRetVal = FALSE;
			else
				bRetVal = TRUE;

			// Set the Start In directory so our shortcut works.
			GetCurrentDirectory(MAX_PATH,szStartInDirectory);
			hres = psl->SetWorkingDirectory(szStartInDirectory);

			if (!SUCCEEDED(hres))
				bRetVal = FALSE;
			else
				bRetVal = TRUE;

	     	// Ensure that the string consists of ANSI characters.
	     	MultiByteToWideChar(CP_ACP, 0, szLink, -1, wsz, MAX_PATH);

          	// Save the shortcut via the IPersistFile::Save member function.
          	hres = ppf->Save(wsz, TRUE);

			if (E_FAIL == hres)
				bRetVal = FALSE;
			else
				bRetVal = TRUE;

            // Release the pointer to IPersistFile.
          	ppf->Release();
       }
       // Release the pointer to IShellLink.
       psl->Release();
    }
	else
		bRetVal = FALSE;

	CoUninitialize();
	CString retString =  szLink;
	if( !bRetVal) 
		retString.Empty();
	

	return retString;
}




Good Luck,
Bill
Questionmodem connection RAS or TAPI or ??? Pin
20-Mar-02 5:57
suss20-Mar-02 5:57 
AnswerI'm too Pin
dlhson20-Mar-02 6:07
dlhson20-Mar-02 6:07 
Questionhow to get a process name attached to a given udp port ? Pin
20-Mar-02 5:45
suss20-Mar-02 5:45 
Generala strange debug error Pin
Gérald Mercet20-Mar-02 5:04
Gérald Mercet20-Mar-02 5:04 
GeneralRe: a strange debug error Pin
Joaquín M López Muñoz20-Mar-02 7:34
Joaquín M López Muñoz20-Mar-02 7:34 
GeneralRe: a strange debug error Pin
Gérald Mercet21-Mar-02 3:06
Gérald Mercet21-Mar-02 3:06 
GeneralNeed HELP - Linking DLL with TEMPLATE Pin
20-Mar-02 5:04
suss20-Mar-02 5:04 
GeneralRe: Need HELP - Linking DLL with TEMPLATE Pin
Joaquín M López Muñoz20-Mar-02 7:30
Joaquín M López Muñoz20-Mar-02 7:30 
GeneralRe: Need HELP - Linking DLL with TEMPLATE Pin
20-Mar-02 10:11
suss20-Mar-02 10:11 
GeneralRe: Need HELP - Linking DLL with TEMPLATE Pin
Joaquín M López Muñoz20-Mar-02 10:39
Joaquín M López Muñoz20-Mar-02 10:39 
GeneralRe: Need HELP - Linking DLL with TEMPLATE Pin
20-Mar-02 16:53
suss20-Mar-02 16:53 
GeneralRe: Need HELP - Linking DLL with TEMPLATE Pin
Joaquín M López Muñoz20-Mar-02 22:14
Joaquín M López Muñoz20-Mar-02 22:14 
GeneralRe: Need HELP - Linking DLL with TEMPLATE Pin
21-Mar-02 3:21
suss21-Mar-02 3:21 
GeneralRe: Need HELP - Linking DLL with TEMPLATE Pin
Joaquín M López Muñoz21-Mar-02 8:23
Joaquín M López Muñoz21-Mar-02 8:23 
Generalbmp on a dialog Pin
20-Mar-02 3:25
suss20-Mar-02 3:25 
GeneralRe: bmp on a dialog Pin
Rickard Andersson2020-Mar-02 3:31
Rickard Andersson2020-Mar-02 3:31 
GeneralRe: bmp on a dialog Pin
dlhson20-Mar-02 6:51
dlhson20-Mar-02 6:51 

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.