殼Namespace引伸: 增加習慣指令艙項目
概要
在我 更加早期的崗位我顯示了如何使用缺省IShellView實施(亦稱DefView)創造殼Namespace引伸。 您也許從樣品已经注意了的一件事是指令艙是空隙缺省項目例如「組織」和「看法」。
如果您開發您自己的Namespace并且想要包括系統設定按鈕並且/或者增加您自己的元素到指令艙,您怎麼完成此? 答復: 您必須實施 IExplorerCommand, IExplorerCommandProvider 并且 IEnumExplorerCommand 接口。
在我之下描述什麼每一個接口使用為,并且什麼您需要做適當地實施他們用您的代碼。
IExplorerCommandProvider
在您的Namespace被裝載之後,殼將請求您的Namespace IExplorerCommandProvider的事例。 這個接口暴露二個方法: GetCommand和GetCommands。 殼叫GetCommand方法檢索匹配由供應的GUID的一個具體IExplorerCommand對象(每個命令是由GUID確定的)。 GetCommands方法叫檢索IEnumExplorerCommand事例。 這個對象列舉所有IExplorerCommand事例為namespace。
您Namespace為它的IExplorerCommandProvider的實施被詢問通過它的CreateViewObject的IShellFolder的實施。 REFIID通過對CreateViewObject將是IID_IExplorerCommandProvider。 殼然後將使用這個接口檢索是實施的您的指令艙項目- IExplorerCommand 接口。
IExplorerCommand
IExplorerCommand接口用於提供項目的出現和行為給探險家的指令艙。 大多方法通過辨認的IShellItemArray什麼項目在看法當前被選擇。 這信息可以由實施用於定做行為為不同的選擇或,如果項目沒有被選擇。 例如,如果項目沒有被選擇,您可以希望設置狀態對ECS_DISABLED或ECS_HIDDEN對灰色或從指令艙完全地去除項目,分別。
這個接口暴露的方法下述。
|
方法 |
描述 |
|
EnumSubCommands |
退回用於的IEnumExplorerCommand事例列舉當前命令的次級命令。 如果GetFlags方法退回ECF_HASSUBCOMMANDS,殼只將叫這個方法。 它這裡是重要對筆記,當如此時做是可能的,有次級命令的次級命令沒有被鼓勵。 |
|
GetCanonicalName |
檢索全局唯一標識符(GUID)與這個命令相關 |
|
GetFlags |
檢索旗子與這個命令相關。 這些旗子在指令艙指定命令的出現和行為。 |
|
GetIcon |
檢索像資源串。 這串是以「myfile.dll, id」的形式。 例如: “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














