Η καλύτερη πηγή σας πληροφοριών και ειδήσεων περίπου υλικό, xp και Vista υλικό στο διαδίκτυο

Vista ΑΡΘΡΑ ΚΟΡΥΦΗ 50 Vista ΒΙΝΤΕΟ Vista SOFT Vista ΒΟΗΘΕΙΑ

Επέκταση της Shell Namespace: Προσθήκη των στοιχείων ενότητας εντολής συνήθειας


Επισκόπηση

Στο μου προηγούμενη θέση, επέδειξα πώς να δημιουργήσω μια επέκταση της Shell Namespace χρησιμοποιώντας την εφαρμογή IShellView προεπιλογής (επίσης γνωστή ως DefView). Ένα πράγμα που δύναμη έχετε παρατηρήσει από το δείγμα είναι ότι η ενότητα εντολών είναι κενή ακόμη και των στοιχείων προεπιλογής όπως «Organize» και «οι απόψεις».

Ενότητα εντολών - FolderViewImpl

Εάν αναπτύσσετε το Namespace σας και θέλετε να περιλάβετε τα κουμπιά προεπιλογής ή/και να προσθέσετε τα στοιχεία σας στην ενότητα εντολών επίσης, πώς ολοκληρώνετε αυτό; Η απάντηση: πρέπει να εφαρμόσετε IExplorerCommand, IExplorerCommandProvider και IEnumExplorerCommand διεπαφές.

Κατωτέρω περιγράφω ποια κάθε μια από τις διεπαφές χρησιμοποιείται για και τι πρέπει να κάνετε για να τους εφαρμόσετε κατάλληλα στον κώδικά σας.

IExplorerCommandProvider

Αφότου φορτώνεται το Namespace σας, η Shell θα ρωτήσει το Namespace σας για μια περίπτωση ενός IExplorerCommandProvider. Αυτή η διεπαφή εκθέτει δύο μεθόδους: GetCommand και GetCommands. Η Shell καλεί τη μέθοδο GetCommand για να ανακτήσει ένα συγκεκριμένο αντικείμενο IExplorerCommand που ταιριάζει με το παρεχόμενο GUID (κάθε εντολή προσδιορίζεται από ένα GUID). Η μέθοδος GetCommands καλείται για να ανακτήσει μια περίπτωση IEnumExplorerCommand. Αυτό το αντικείμενο απαριθμεί όλες τις περιπτώσεις IExplorerCommand για το namespace.

Namespace ρωτιέστε για την εφαρμογή IExplorerCommandProvider της μέσω της εφαρμογής του IShellFolder της CreateViewObject. Το REFIID που περνούν σε CreateViewObject θα είναι IID_IExplorerCommandProvider. Η Shell θα χρησιμοποιήσει έπειτα αυτήν την διεπαφή για να ανακτήσει τα στοιχεία ενότητας εντολών σας - που είναι εφαρμογές IExplorerCommand διεπαφή.

IExplorerCommand

Η διεπαφή IExplorerCommand χρησιμοποιείται για να παρέχει την εμφάνιση και τη συμπεριφορά του στοιχείου στην ενότητα εντολών του εξερευνητή. Οι περισσότερες από τις μεθόδους περνούν ένα IShellItemArray που προσδιορίζει ποια στοιχεία επιλέγονται αυτήν την περίοδο κατά την άποψη. Αυτές οι πληροφορίες μπορούν να χρησιμοποιηθούν από την εφαρμογή για να προσαρμόσουν τη συμπεριφορά για τις διαφορετικές επιλογές ή εάν κανένα στοιχείο δεν επιλέγεται. Παραδείγματος χάριν, εάν κανένα στοιχείο δεν επιλέγεται, μπορείτε να επιθυμήσετε να θέσετε το κράτος σε ECS_DISABLED ή ECS_HIDDEN γκρίζος-έξω ή να αφαιρέσετε το στοιχείο εντελώς από την ενότητα εντολών, αντίστοιχα.

Οι μέθοδοι που εκτίθενται από αυτήν την διεπαφή περιγράφονται κατωτέρω.

Μέθοδος

Περιγραφή

EnumSubCommands

Επιστρέφει μια περίπτωση IEnumExplorerCommand που χρησιμοποιείται για να απαριθμήσει τις υπο- εντολές της τρέχουσας εντολής. Η Shell θα καλέσει μόνο αυτήν την μέθοδο εάν η μέθοδος GetFlags επιστρέψει ECF_HASSUBCOMMANDS. Είναι σημαντικό να σημειωθεί εδώ ότι ενώ είναι δυνατό να κάνει έτσι, οι υπο- εντολές που έχουν τις υπο- εντολές οι ίδιοι δεν ενθαρρύνονται.

GetCanonicalName

Ανακτά το συνολικά μοναδικό προσδιοριστικό (GUID) που συνδέεται με αυτήν την εντολή

GetFlags

Ανακτά τις σημαίες που συνδέονται με αυτήν την εντολή. Αυτές οι σημαίες διευκρινίζουν την εμφάνιση και τη συμπεριφορά της εντολής στην ενότητα εντολής.

GetIcon

Ανακτά μια σειρά των πόρων εικόνων. Αυτή η σειρά είναι υπό μορφή «myfile.dll, ταυτότητα». 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.

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: 1%


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.

Related articles

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> .