Click here to Skip to main content
Click here to Skip to main content

ACF Does Shell - Part 2

, 30 Jun 2004
Rate this:
Please Sign up or sign in to vote.
This article shows how to create and open shell link with the WinShell library built on ACF.

Introduction

In my previous article ACF Does Shell – Part 1, I talked about how to use the Item class to navigate Windows Shell and retrieve item information. In this article, I will show you how to use the Item and LinkItem classes to create and open shell links (shortcuts). If you are not familiar with the Item class, please check my previous article first.

Creating shell links

The following code snippet shows how to create a link to "My Documents" and then save it to desktop:

ItemPtr target = new Item(SpecialFolder::Personal); // My Documents
ItemPtr location = Item::get_Desktop(); // Desktop

LinkItemPtr link = new LinkItem(target); // The link
link->Save(location);

As you can see, the API is very straightforward.

Opening existing shell links

The following code snippet shows how to open an existing link file and retrieve its properties (description, target, arguments, etc.):

StringPtr path = ...; // Path to a file
ItemPtr item = new Item(path);

if (item->IsLink) {
    LinkItemPtr link = item->LinkItem;

    StringPtr description = link->Description;
    StringPtr targetPath = link->Target->FileSysPath;
    StringPtr args = link->Arguments;
    StringPtr dir = link->WorkingDirectory;
}

The sample application demonstrates how to use these classes.

Class Item

Properties

  • bool IsLink;

    Gets a value indicating whether this object is a shortcut.

  • LinkItemPtr LinkItem;

    Gets a LinkItem object representing a shortcut item.

For other members, please check my previous article.

Class LinkItem

Constructors

  • LinkItem();

    Constructs a new shortcut.

  • LinkItem(Item* target);

    Constructs a new shortcut with the specified target.

Properties

  • StringPtr Description;

    Gets or sets the description string.

  • ItemPtr Target;

    Gets or sets the target.

  • StringPtr Arguments;

    Gets or sets the command-line arguments.

  • StringPtr WorkingDirectory;

    Gets or sets the working directory.

  • bool IsDirty;

    Gets a value indicating whether this object is dirty since it was last saved.

Methods

  • void Resolve();

    Resolves the shortcut. See IShellLink::Resolve.

  • void Save();

    Saves the shortcut. See IPersistFile::Save.

  • void Save(Item* parentFolder);

    Saves the shortcut to the specified location. See IPersistFile::Save.

  • void Save(Item* parentFolder, String* name, bool rememberSaveLocation = true);

    Saves the shortcut to the specified location with the specified name. See IPersistFile::Save.

Reference

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Yingle Jia
Web Developer
China China
Yingle Jia is a software engineer located in Beijing, China. He currently works at IBM CSDL (China Software Development Lab). His interests include C++/COM/C#/.NET/XML, etc. He likes coding and writing.
 
He is the creator of ACF (Another C++ Framework) project. See http://acfproj.sourceforge.net/.
 
He also has a blog at http://blogs.wwwcoder.com/yljia/

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 1 Jul 2004
Article Copyright 2004 by Yingle Jia
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid