|
#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include "ShellLink.h"
void main()
{
//Initialise the OLE subsystem
HRESULT hRes = ::CoInitialize(NULL);
if (!SUCCEEDED(hRes))
{
TRACE(_T("Failed to initialize OLE\n"));
return;
}
//Test all the functionality of the classes
//First Saving
CShellLinkInfo sli1;
sli1.m_sTarget = _T("notepad.exe");
sli1.m_sArguments = _T("c:\\config.sys");
sli1.m_sWorkingDirectory = _T("c:\\");
sli1.m_sDescription = _T("Edit your config.sys");
sli1.m_sIconLocation = _T("shell32.dll");
sli1.m_nIconIndex = 21; //Use an interesting icon
sli1.m_nShowCmd = SW_MAXIMIZE;
CShellLink sl1;
if (sl1.Create(sli1))
{
if (!sl1.Save(_T("c:\\Edit your config.sys.lnk")))
TRACE(_T("Failed to save link\n"));
else
_tprintf(_T("A shortcut to edit your config.sys had been created on you C:\\ drive\n"));
}
else
TRACE(_T("Failed to create link\n"));
//Now loading
CShellLink sl2;
if (!sl2.Load(_T("c:\\Edit your config.sys.lnk")))
TRACE(_T("Failed to open link\n"));
//Now Resolving
if (!sl2.Resolve(NULL, SLR_ANY_MATCH))
TRACE(_T("Failed to resolve link\n"));
//Now try saving a URL shortcut
CShellLinkInfo sli2;
sli2.m_sTarget = _T("http://indigo.ie/~pjn");
sli2.m_sWorkingDirectory = _T("c:\\");
sli2.m_sDescription = _T("Visit the authors Web Site");
sli2.m_sIconLocation = _T("shell32.dll");
sli2.m_nIconIndex = 14; //Use an interesting icon
sli2.m_nShowCmd = SW_MAXIMIZE;
CUrlShellLink sl4;
if (sl4.Create(sli2))
{
if (!sl4.Save(_T("c:\\PJ Naughters Web Site.url")))
TRACE(_T("Failed to save URL link\n"));
else
_tprintf(_T("A shortcut to my web site had been created on you C:\\ drive\n"));
}
else
TRACE(_T("Failed to create URL link\n"));
//and loading a URL shortcut
CUrlShellLink sl5;
if (!sl5.Load(_T("c:\\PJ Naughters Web Site.url")))
TRACE(_T("Failed to load URL link\n"));
//and loading a URL shortcut
if (!sl5.Invoke(NULL, IURL_INVOKECOMMAND_FL_USE_DEFAULT_VERB, _T("")))
TRACE(_T("Failed to invoke URL link\n"));
else
_tprintf(_T("Now conneting to my web site\n"));
//Closedown the OLE subsystem
::CoUninitialize();
_tprintf(_T("Till Next time!!!, Press any key to exit\n"));
int ch = getch();
}
|
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.