Windows 7 Development: Shell Library

Source: Internet
Author: User
Tags commit file system

2. Compile and test:

A. Open a command line window and switch the directory (CD) to the location where SLUtil.exe is located.

B. Open the Library shell folder next to the Command Line window and you will see the changes you have made using the Slutil tool.

C. In the Command Line window, test the Slutil command.

D. Try to use the same icon as the Pictures library for your Mylib library.

E. Try locking and unlocking your library in the file Management panel.

F. Change the default storage location of the library, move this location to another location in the file system, and test whether the default storage location resolves the change.

Task 6– Add foldertype command

Each library has a folder template type. This type defines the look and feel of the Shell Library window, for example, there are different templates for pictures and music. The Ishelllibrary Setfoldertype () method uses a GUID to represent the type ID of the folder. The Getfoldertype () method returns the ID of the current folder. By default, user-created libraries are general folder types.

In order for the user to use the text type instead of using a GUID, we need to use a Help class. Cfoldertypeidnameconverter This class knows how to convert pictures, Music, Documents, videos, and generic to the corresponding foldertypeid_*, and vice versa. At the same time, this method also knows to take a part of the name, such as vid is videos. These will make the type of the Settings Library folder simple: Slutil foldertype mylib doc

1. Add FolderTypeIdNameConverter.h and FolderTypeIdNameConverter.cpp files to the project. You can find them from the starter folder.

2. Add #include "FolderTypeIdNameConverter.h"

3. Add the following code fragment to implement the FolderType command:

C + + (SLUtil.cpp)

Set or get the library ' s folder template


void FolderType (const CCommand &command, const vector<pcwstr> &arguments)


{


ishelllibrary *shelllibrary = NULL;


HRESULT hr = S_OK;


Foldertypeid Foldertypeid;





Cfoldertypeidnameconverter Converter;





//show current Folder type


if (arguments.size () = 1)


                 {


//open Library with Read permissions


ishelllibrary *shelllibrary =


openlibrary (L "FolderType", Argume Nts[0]);





hr = Shelllibrary->getfoldertype (&foldertypeid);


if (FAILED (HR))


                                 {


Wcerr <<


L "Foldertype:can ' t get the library ' s folder template."


<< Endl;


exit (5);


                                 }


wcout << L "Library" << arguments[0] << L ": Folder template is: "<< converter. Getfoldertypeidname (Foldertypeid) << Endl;


                 }


else//set the current folder type


                 {


//open Library with Read/write permissions


ishelllibrary *shelllibrary =


openlibrary (L "FolderType", Arguments[0], false);





hr = converter. Getfoldertypeidfromname (Arguments[1],


&foldertypeid);


if (FAILED (HR))


                                 {


wcerr << L "Foldertype:invalida folder template name." < <


Endl


exit (6);


                                 }





hr = Shelllibrary->setfoldertype (Foldertypeid);


if (FAILED (HR))


                                 {


Wcerr <<


L "Foldertype:can ' t set the library ' s folder template,"


<< Endl;


Exit (7);


                                 }


//commit the library changes


shelllibrary->commit ();


                 }


if (shelllibrary!= NULL)


shelllibrary->release ();


}


COMMAND (L "FolderType",


L "Slutil foldertype libraryname [documents| pictures| music| videos| Generic] ",


L "Set or get the library ' s folder Template", L "Slutil mylib Documents", 1,


foldertype);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.