貝Namespace延長: 注文のコマンド・モジュール項目を加えること
概観
私 より早いポストデフォルトのIShellViewの実施(別名DefView)を使用して貝Namespace延長を作成する方法を、私は示した。 あなたがサンプルから気づくかもしれない1つの事はコマンド・モジュールがデフォルト項目の無効のような「組織する」 「意見」であることであり。
あなた自身のNamespaceを開発して、デフォルト・ボタンを含みおよび/またはコマンド・モジュールにあなた自身の要素をまた加えたいと思えばいかにこれを達成するか。 答え: 実行しなければならない IExplorerCommand, IExplorerCommandProvider そして IEnumExplorerCommand インターフェイス。
私はの下でeach ofインターフェイスが使用され、もののためにきちんとあなたのコードのそれらを実行するために必要があるものを記述するする。
IExplorerCommandProvider
あなたのNamespaceが荷を積まれた後、貝はIExplorerCommandProviderの例をあなたのNamespaceに頼む。 このインターフェイスは2つの方法を露出する: GetCommandおよびGetCommands。 貝はGetCommand供給されたGUIDに一致させるIExplorerCommandの特定の目的を取り出すために方法を呼ぶ(各命令はGUIDによって識別される)。 GetCommands方法はIEnumExplorerCommandの例を取り出すために呼ばれる。 この目的はnamespaceのためのIExplorerCommandのall the例を列挙する。
IShellFolderのCreateViewObjectの実施によってIExplorerCommandProviderの実施のためにNamespaceただされる。 CreateViewObjectに通じたREFIIDはIID_IExplorerCommandProviderである。 貝はそれからこのインターフェイスを取り出すのにの実施であるあなたのコマンド・モジュール項目使用する IExplorerCommand インターフェイス。
IExplorerCommand
IExplorerCommandインターフェイスが探検家のコマンド・モジュールに項目の出現そして行動を提供するのに使用されている。 方法のほとんどは項目が眺めで現在選ばれるものを識別するIShellItemArrayを渡す。 項目が選ばれなければ実施によってこの情報が異なった選択のための行動をカスタマイズするのにまたは使用することができる。 例えば、項目が選ばれなければ、それぞれ州をECS_DISABLEDかECS_HIDDENに灰色に置くか、またはコマンド・モジュールから項目を完全に取除きたい場合もある。
このインターフェイスによって露出される方法は後で記述されている。
|
方法 |
記述 |
|
EnumSubCommands |
現在の命令の補助的な命令を列挙するのに使用されるIEnumExplorerCommandの例を戻す。 貝はGetFlags方法がECF_HASSUBCOMMANDSを戻せばその時だけこの方法を呼ぶ。 それはそうすることは可能な間、補助的な命令自身がある補助的な命令は励まされないことノートにとってここに重要である。 |
|
GetCanonicalName |
この命令と関連付けられるグローバルに固有のの鑑定器(GUID)を取り出す |
|
GetFlags |
この命令と関連付けられる旗を取り出す。 これらの旗はコマンド・モジュールで命令の出現そして行動を指定する。 |
|
GetIcon |
アイコン資源のひもを取り出す。 このひもは「myfile.dll、IDの形に」ある。 For example: “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.
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
- To build the FolderViewImpl sample, be sure to download and install the Windows SDK.
- Download the modified FolderView SDK sample
- Launch FolderViewImpl.sln in Visual Studio
- Open the properties for the project
- Add a path to the SDK includes to the C/C++ - General page
- Add a path to the SDK libs to the Linker – General page
- Build
Installing the FolderView SDK Sample
- Once you have built the sample, copy the FolderViewImpl.dll and FolderViewImpl.propdesc to the same directory
- From an elevated cmd window, regsvr32 FolderViewImpl.dll
- Restart explorer
- Open explorer to Computer
- There should be a list item named “FolderView SDK Sample”
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.
- [+] Digg: Feature this article
- [+] Del.icio.us: Bookmark this article
- [+] Furl: Bookmark this article














