27. Extended extention of Windows API Shell

Source: Internet
Author: User

Shell can be extended, shell ExtensionProgramThe following functions can be implemented.

◇ Specific file type, all file types, network neighbors, recycle bin, drive, network shared folder, printer, disc drive, directory, folder background (blank area of the window) add a menu item to the context menu of a shell object.

◇ Related processing is performed when the menu items in the context menu are selected.

◇ Custom operations to drag files and folders to other directories.

◇ Customize the menu and operations for right-clicking and dragging shell object icons.

◇ Customize icons Based on the file content.

◇ Custom Properties dialog box and paging items.

◇ Custom prompt dialog box (the prompt message popped up when the mouse pointer stays on the icon ).

◇ Use the "details" icon to customize columns.

◇ Accelerate or prohibit operations such as moving, copying, deleting, and renaming directories and specific files.

◇ Add a custom search engine in the Start Menu or explorer.

Many special applications can be extended from these features, such:

◇ Monitor the movement of files or directories.

◇ Monitor the action of the recycle bin, such as restoring a project and clearing it.

I. Basic Concepts

Shell extension processing routineCodeThe implementation is located in the DLL file and is an object that complies with the COM interface. After completing the DLL design, You need to register in the registry, and the shell extension can work normally.

1. Handler (Processing Routine)

Handler is a series of functions and interfaces. When a shell event occurs, it calls a processing routine for processing.

For example, when you right-click an icon, the context menu handler is called and the Customized menu item in the context menu is selected, related Function interfaces are also called to process menu selection events.

The shell extension DLL should include the following export functions.

◇ Dllmain: Standard DLL entry function.

◇ Dllgetclassobject: This export function provides the class factory interface.

◇ Dllcanunloadnow: indicates whether the DLL is still in use and whether the system can uninstall the DLL. Like all other COM programs, shell extensions must implement an iunlnown interface and a class factory. In most cases, you also need to implement an ipersistfile or ishellextinit interface.

2. progid and special progid

Each file type corresponds to a progid, which represents a file type. Some special progids are shown in the table.

The shellex sub-Key of progid specifies the processing routine corresponding to progjd. These subkeys include columnhandlers (used to view the file list in "details" mode and called when the column is displayed), contextmenuhandlers (called when the menu is right-clicked), copyhookhandlers (called when you move, copy, delete, or rename an object), dragdrophandlers (called when you right-click to drag a menu), and propertysheethandlers (called when viewing shell object attributes), datahandler, drophandler, and iconhandler (called when an icon is displayed and used for personalized icons.

3. CLSID: The GUID of the processing routine

GUID (globally unique identifier) is used to uniquely identify an object in the system. CLSID is a guid in the registry. It is used to uniquely identify a COM object in the registry.

CLSID can have many subkeys. In Shell extension, the inprochandler32 and inprocserver32 subkeys are often used to register the processing routines DLL and In-process service DLL with Shell respectively.

For specific examples, see [3].

4. com

The shell Extension Program is a COM (Component Object Model, Component Object Model) program.

Com is a platform-independent, distributed, and object-oriented program interface standard. It is generally used to expand the functions of applications.

Most applications developed by Microsoft support COM interface extensions. com programs are generally DLL files (ActiveX programs are files with the. ocx extension ).

The com program is provided to the main program for calling. The com program provides a Fixed Interface (dllgetclassobject export function) for the main program to obtain other interfaces through a fixed function interface. In Shell extension, different interface functions are called in different situations through configuration in the registry. Different com programs have different interfaces,All interfaces are obtained from the class factory and iunknown interfaces. Therefore, the com program must implement the class factory and iunknown interfaces.

In fact, all other interfaces returned by the class factory and iunknown interfaces are returned in the form of function pointers. Therefore, any program language that has a struct pointer and can call a function through a function pointer can be used to compile a com program.

Only by understanding the interface specifications that must be followed by Shell extension as a com program can we understand how shell extension works.

Because the com program is called by other programs, the com program has a main program. .

5. Related APIs

1) The main function of the dllgetclassobject function is to return the Calling Interface (after the com program is implemented, it is called by other programs, and the com program is called by the COM program.

2) The iclassfactory com program is released to implement the iclassfactory interface. The iclassfactory interface is used to return the interface implemented by the COM program according to the requirements of the main program for calling the main function. The iclassfactory interface must implement two member functions: createinstance and lockserver. The main program calls these two member functions. The createinstance member function is called by the main program to instantiate the interface required by the main program and return the interface instance.

3) iunknown.

Each com program must implement two interfaces. One is iclassfactory and the other is iunknown.

Iunknown requires three member functions: QueryInterface, addref, and release.

6. The functions of QueryInterface are similar to those of other interfaces. addref and release are used to increase and decrease the number of COM Object references respectively. When COM is referenced and released, the main program will call these two interfaces.

7. The shell extension must implement the ishellextinit interface. The ishellextinit interface should have the member function Initialize. The initialize function is used to initialize attributes page extension processing routines, context menu processing routines, and drag and drop processing routines implemented by Shell extensions. This member function is called before the shell needs to bring up the context menu or property page to instantiate related interfaces.

The pidfolder parameter is a variable pointing to the itemidlist type. The menu used to identify the object will be displayed. If it is an attribute page extension, this parameter is null. If it is an upper/lower file menu extension, this parameter represents the directory of the object to be popped up.

The pdataobj parameter points to the idataobj ect interface, which is used to obtain the operation object.

The hkeyprogid parameter indicates the registry value of the Directory type.

1) In general conditions, initialize member functions need to instantiate different handler Interfaces Based on the extension types specified by parameters. For example, the icontextmenu interface is instantiated for context menu handlers.

Icontextmenu needs to implement the getcommandstring, invokecommand, and querycontextmenu member functions.

When the shell needs to display the upper and lower file menus, The querycontextmenu function is called. The querycontextmenu function should set items in the menu. Getcommandstring is used to return the string associated with the menu item to the main program. After you click an item in the context menu, invokecommand is called. In the implementation of the invokecommand function, actions that should be executed after the menu item is clicked should be processed.

2) The ishellpropsheetext interface must be implemented to extend the property page. The ishell prop sheetext interface includes two member functions: addpages and replacepage.

The master program calls addpages and replacepage Based on the configuration in the Registry to add and replace attribute pages respectively. The property page is essentially a dialog box.

3) To implement icon extension in Shell extension, you need to implement the iextracticon interface.

Iextracticon requires two member functions: extract and geticonlocation. Getprivateprofileint is called in the geticonlocation function to obtain the content configured in the file. The geticonlocation function is returned using the piindex and sziconfile parameters, indicating that the piindex icon in the file specified by sziconfile should be used.

4) if copyhookhandlers is registered in the Registry, the icopyhook interface copycallback member function will be called when you operate files or folders related to file types.

Reference

[1] proficient in Windows API functions, interfaces, and programming instances

[2]Http://msdn.microsoft.com/en-us/library/bb773177%28VS.85%29.aspx

[3] http://www.cnblogs.com/mydomain/archive/2010/12/03/1895050.html

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.