Su mejor fuente de la información y de las noticias alrededor Vista, BIOS y winvista en el Internet

ARTÍCULOS de Vista TAPA 50 Vista VIDEOS Vista SUAVE AYUDA de Vista

Extensión del namespace de Shell: Adición de artículos de encargo del módulo de comando


Descripción

En mi poste anterior, Demostré cómo crear una extensión del namespace de Shell usando la puesta en práctica de IShellView del defecto (también conocida como DefView). Una cosa que usted puede ser que haya notado de la muestra es que el módulo de comandos es vacío de uniforme los artículos del defecto por ejemplo “organiza” y las “opiniónes”.

Módulo de comandos - FolderViewImpl

¿Si usted está desarrollando su propio namespace y desea incluir el defecto abotona y/o agrega sus propios elementos al módulo de comandos también, cómo usted logra esto? La respuesta: usted debe poner en ejecución IExplorerCommand, IExplorerCommandProvider y IEnumExplorerCommand interfaces.

Debajo de mí describo para lo que se utiliza cada uno de los interfaces y lo que usted necesita hacer para ponerlos correctamente en ejecución en su código.

IExplorerCommandProvider

Después de que se cargue su namespace, Shell pedirá su namespace un caso de un IExplorerCommandProvider. Este interfaz expone dos métodos: GetCommand y GetCommands. Shell llama el método de GetCommand para recuperar un objeto específico de IExplorerCommand que empareje el GUID proveído (cada comando es identificado por un GUID). El método de GetCommands se llama para recuperar un caso de IEnumExplorerCommand. Este objeto enumera todos los casos de IExplorerCommand para el namespace.

Le namespace preguntan para su puesta en práctica de IExplorerCommandProvider vía la puesta en práctica de su IShellFolder de CreateViewObject. El REFIID pasado a CreateViewObject será IID_IExplorerCommandProvider. Shell entonces utilizará este interfaz para recuperar sus artículos del módulo de comandos - que sean puestas en práctica del IExplorerCommand interfaz.

IExplorerCommand

El interfaz de IExplorerCommand se utiliza para proporcionar el aspecto y el comportamiento del artículo al módulo de comandos del explorador. La mayor parte de los métodos pasan un IShellItemArray que identifique lo que se seleccionan los artículos actualmente en la visión. Esta información se puede utilizar por la puesta en práctica para modificar el comportamiento para requisitos particulares para diversas selecciones o si no se selecciona ningunos artículos. Por ejemplo, si no se selecciona ningunos artículos, usted puede desear fijar el estado a ECS_DISABLED o a ECS_HIDDEN a gris-hacia fuera o quitar el artículo totalmente del módulo de comandos, respectivamente.

Los métodos expuestos por este interfaz son descritos más abajo.

Método

Descripción

EnumSubCommands

Vuelve un caso de IEnumExplorerCommand usado para enumerar comandos secundarios del comando actual. Shell llamará solamente este método si el método de GetFlags vuelve ECF_HASSUBCOMMANDS. Es importante observar aquí que mientras que es posible hacer así pues, los comandos secundarios que tienen comandos secundarios ellos mismos no están animados.

GetCanonicalName

Recupera el identificador global único (GUID) asociado a este comando

GetFlags

Recupera las banderas asociadas a este comando. Estas banderas especifican el aspecto y el comportamiento del comando en el módulo de comando.

GetIcon

Recupera una secuencia del recurso del icono. Esta secuencia está bajo la forma de “myfile.dll, identificación”. Por ejemplo: “shell32.dll,-101”

GetState

Retrieves the state of the command item. This is the first method of the interface that is called. The state that is returned affects the appearance and behavior of the command item. This method also passes a BOOL to let the command implementation know if the slow response rule is in effect.

GetTitle

Retrieves the string to display for the command item.

GetToolTip

Retrieves the string to use in the ToolTip associated with this command item.

Invoke

Called by the Shell when the user has activated a command on the Commands Module.

The above methods GetState and GetFlags return values that determine the appearance and behavior of the item in the Command Module. In the table below are screenshots of the command resulting from the combinations of the flags/states values.

ECS_ENABLED

ECS_DISABLED

ECS_HIDDEN

NONE

ECF_HASSUBCOMMANDS

ECF_HASSPLITBUTTON

ECF_HIDELABEL

ECF_ISSEPARATOR

N/A

ECF_HASLUASHIELD

ECS_CHECKBOX

ECS_CHECKBOX|

ECS_CHECKED

NONE

ECF_HASSUBCOMMANDS

ECF_HASSPLITBUTTON

ECF_HIDELABEL

ECF_ISSEPARATOR

N/A

N/A

ECF_HASLUASHIELD

*ECS_CHECKBOX and ECS_CHECKED only apply to sub items

** ECF_ISSEPARATOR can only be added as a sub item

Slow Response Rule

The second parameter of the GetState method is a BOOL (fOkToBeSlow) that lets the implementation of IExplorerCommand know if the “slow response rule” is in effect. If this value is FALSE, and your implementation performs slow operations (such as I/O, network calls or calls to out of thread COM objects) then your command should return E_PENDING. This will cause the Commands Module to call the command’s GetState (and other methods) on a background thread with fOkToBeSlow set to TRUE. This prevents slow operations in your implementation from running on the UI thread, thus preventing performance issues.

Command Item Ordering

It is important to note here that the developer of the Namespace Extension has no control over the ordering of command items. For example, you cannot force your command items before the default View and Organize command items or have the View or Organize command items renamed/removed. Items are simply appended to the end of the Commands Module in the order returned from the IEnumExplorerCommand instance.

IEnumExplorerCommand

The IEnumExplorerCommand is returned to the Shell by the GetCommands method of the IExplorerCommandProvider interface. As the name suggests, it permits enumeration of the IExplorerCommand instances by the Shell.

FolderViewImpl Sample Code

The above interfaces have been implemented in the attached Shell Namespace Extension sample code derived from the FolderViewImpl SDK sample. The structure of the command items (as well as sub items) is data-driven from an array of structures that define the command items (see the array of FVCOMMANDITEMs in fvcommands.cpp). This approach was used to make it easy to experiment with the hierarchy of command items as well as their behavior/appearance. The way you implement commands in your Namespace Extension may differ.

Commands Module - Modified FolderViewImpl

The above is a screenshot of the modified SDK sample. Notice we now have the default command items (Organize and Views) as well as our custom items. The Display command item performs the same function as right-clicking items in the view and selecting “Display” from the context menu. The Settings button is used to demonstrate a command item with sub items. All it does is display a message box with the name of the sub item when the user invokes the specified sub item.

It should also be noted that if you are using a custom view in your Namespace by implementing your own IShellView (instead of using DefView) you will need to include an implementation of IFolderView::GetFolder. In your GetFolder implementation you will need to include the ability to QueryService for SID_SFolderView.

Building the FolderView SDK Sample

  1. To build the FolderViewImpl sample, be sure to download and install the Windows SDK.
  2. Download the modified FolderView SDK sample
  3. Launch FolderViewImpl.sln in Visual Studio
  4. Open the properties for the project
  5. Add a path to the SDK includes to the C/C++ - General page
  6. Add a path to the SDK libs to the Linker – General page
  7. Build

Installing the FolderView SDK Sample

  1. Once you have built the sample, copy the FolderViewImpl.dll and FolderViewImpl.propdesc to the same directory
  2. From an elevated cmd window, regsvr32 FolderViewImpl.dll
  3. Restart explorer
  4. Open explorer to Computer
  5. There should be a list item named “FolderView SDK Sample”

Popularity: 3%


Written by chrdavis. Read more great feeds at is source WEBSITE
no comments.
Read more articles on shell and namespace and Coding and API and Programming and vista and Windows Vista.

No comments

There are still no comments on this article.

Leave your comment...

If you want to leave your comment on this article, simply fill out the next form:




You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> .