RE: Controlling when a toolbar button is enabled/visible?



This sample is far more appropriate to your situation:

How to: Add Custom Toolbars and Toolbar Items to Outlook:
http://msdn2.microsoft.com/en-us/library/ms268864(en-US,VS.80).aspx

Just replace trapping Explorers with Inspectors to trap the opening of a new
item window. But when you trap the Inspectors.NewInspector event, check that
the Class property is equal to olContact before you create the button, or
hide/disable it if it is not a Contact Item.

If you can live with the originally opened item window not responding to
your toolbar button clicks if subsequent windows are opened, then you're good
to go. Otherwise you do need to use wrapper collections to have every open
window respond to the click event.

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"kfrost" wrote:

> :) Thanks Eric,
>
> I did download the zip but like I said I don't have anything to open the
> files other than notepad. Plus I'm trying to finish up something I'm
> doodling with and don't want to spend 40 hours trying to go through VB 6 code
> and get it into something that I'm comfortable reading. :)
>
> I kind of understand the concepts but I'm an examples kind of guy. Think I
> may have found what I need though. Or at least a good start because it's
> firing everytime I change folders. Bad thing it's firing everytime I click
> anything in Outlook.
>
> Like I said, I could live with the button installing in the standard toolbar
> and being visible in any window. The only problem it's not showing up in the
> contact item window.
>
> private void ThisApplication_Startup(object sender, System.EventArgs e)
> {
> currentExplorer = this.ActiveExplorer();
> currentExplorer.SelectionChange += new
> Outlook.ExplorerEvents_10_SelectionChangeEventHandler(CurrentExplorer_Event);
> }
>
> private void CurrentExplorer_Event()
> {
> Outlook.MAPIFolder selectedFolder =
> this.ActiveExplorer().CurrentFolder;
> String expMessage = "Your current folder is "
> + selectedFolder.Name + ".\n"
> }
>
> Pretty decent example in VB.Net and C#
> http://msdn2.microsoft.com/en-us/library/ms268994(en-US,VS.80).aspx
>
> But again as I stated this fires everytime you click on anything in Outlook,
> I'm going to play around and see if I can find an event that just fires when
> the window changes.
>
> Thanks.
>
> --
> kris@xxxxxxxxx<Remove This Before Emailing>
>
> Network & Software Integration
> www.n-sv.com
>
> "Helping put the pieces of your IT puzzle together"
>
>
> "Eric Legault [MVP - Outlook]" wrote:
>
> > It doesn't matter though if you use VB6 or .NET. You still have to implement
> > Explorer and Inspector wrapper collections and objects so that you can trap
> > the individual events for Outlook windows.
> >
> > The code on Ken Slovak's page explaining Inspector wrappers can be ported to
> > using Explorer object using the same concepts (if you don't want to download
> > the ItemsCB add-in to view the Explorer examples in Visual Basic 6).
> >
> > Essentially, you need global collection variables that can be added to as
> > soon as the collection object itself is added to. For example, generally the
> > AddIn class hooks into the Explorers collection:
> >
> > Private WithEvents colExpl As Outlook.Explorers
> >
> > This allows you to hook into the NewExplorer event:
> >
> > Private Sub colExpl_NewExplorer(ByVal Explorer As Outlook.Explorer)
> > On Error Resume Next
> > gblnNewExpl = True
> > AddExpl Explorer
> > End Sub
> >
> > There, you can then call the AddExpl method and pass the newly loaded
> > Explorer object. This method lives in a kind of maintenance module for
> > Explorer objects, which maintains the global collection variable for all
> > Explorer objects that get created.
> >
> > What that module then does when the AddExpl method is called is create an
> > instance of an ExplWrap class. This class has all of the Outlook.Explorer
> > object events wired in, so you can trap a new Outlook window as soon as it
> > opens – which is exactly where you want to instantiate (or create for the
> > first time) your custom toolbars and buttons. If a user creates yet another
> > Outlook window (to view their Calendar separate from their e-mail for
> > example), the AddExpl method will be called *again*, and a NEW ExplWrap class
> > will be added to the Explorer collection. Now the Outlook.Explorer object
> > related events in those classes will fire independently of each other.
> >
> > If wrappers weren’t used, then the LAST object created is the one whose
> > events will be handled. This is the important point to understand the
> > requirement for using wrappers. Otherwise, with no wrappers, after the user
> > cycles back to their Inbox window after looking at their Calendar in another
> > Window, any events bound to your custom toolbars or buttons will NOT fire.
> >
> > The exact same concept applies to e-mail item or appointment item Windows
> > (Inspectors).
> >
> > Let me know if I haven’t thoroughly muddled the waters too much with my airy
> > explanations.
> >
> > --
> > Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
> > Try Picture Attachments Wizard for Outlook:
> > http://www.collaborativeinnovations.ca
> > Blog: http://blogs.officezealot.com/legault/
> >
> >
> > "kfrost" wrote:
> >
> > > Hello,
> > >
> > > I'm creating a toolbar button for use with contacts. I planned to just add
> > > it to the standard toolbar which looks like it shows up no matter what window
> > > you have open. Via it Mail, contacts Tasks etc.
> > >
> > > I was cool with that but now when I opent a contact Item in it's own window,
> > > the standard toolbar does contain my button anymore.
> > >
> > > Basically what I need to accomplish is the same as what happens with the MS
> > > dialer icon. It appears when you open a contact folder and it's still
> > > present when you open an individual contact.
> > >
> > > I assume I'm going to have add events to my code to enable and disable this
> > > button, correct?
> > >
> > > Anybody have any concise sample code?
> > >
> > > Thanks.
> > >
> > > --
> > > kris@xxxxxxxxx<Remove This Before Emailing>
> > >
> > > Network & Software Integration
> > > www.n-sv.com
> > >
> > > "Helping put the pieces of your IT puzzle together"
.


Loading