Add your own menu in Outlook
There is a new feature in Microsoft Office 2000: COM Add-in. Profit
With COM add-on, we can integrate your own software in Office Series by writing COM components.
in. For example, Jinshan Words .NET is to use the COM add-on to implement the Add button to Word.
The following article will add a button to the Outlook icon by how to achieve the addition of the Outlook.
Now COM add-on. To establish a COM add-in VB, first need to create an ActiveX DLL project, then
Class a class (Class) in the project, implement the idTextensibility2 specified in the class code
interface. If readers have done or have contacted shell extension and interface
These possibilities may be well understood by INTERFACE. If there is no contact. Can load our COM
See how servers, Outlook as customers, how do customers call the server? This needs a
Specification, or a protocol. The server only implements the code specified by the protocol, the customer can directly pass
Call the server program without using the management server, and interfaces in Windows programming
This is the agreement.
Here is how to implement the COM add-on. First build a new ActiveX DLL project, VB will
Add a class module: Class1, change the Class1's Name property to ClsoutLook,
The Name property is changed to myoutlook and then save the project.
To implement an IDTEXTENSIBILITY2 interface, you must introduce the definition of the IDTextensibility2 interface. another
We also need to introduce Office and Outlook libraries, click on the menu Project | References item,
The references are selected in the list:
Microsoft Add-in DESING
Microsoft Outlook 9.0 Object Library
Microsoft Office 10.0 Object Library
As shown below:
Then open CLSOutlook, add the following code:
Option expedition
Implements IDTextensibility2
DIM WITHEVENTS OBJAPP As Outlook.Application
Dim objbutton as office.commandbarbutton
Dim objbar as office.commandbars
Dim objmenubar as office.commandbar
Dim objfolder as Outlook.mapiFolder
Dim Withevents ObjmyButton as Office.commandbutton
Dim withevents objresetbar as office.commandbutton
DIM WITHEVENTS OBJNAMESPACE As Outlook.namespace
Private sub idtextensibility2_onaddinsupdate (Custom () AS VARIANT)
'Msgbox "execution"
End Sub
Private sub idtextensibility2_onbeginshutdown (Custom () AS VARIANT)
MsgBox "object will be closed!"
Set objapp = NothingSet objbar = nothing
Set objbutton = Nothing
Set objfolder = Nothing
Set objmenubar = nothing
Set objmyButton = Nothing
Set objNamespace = Nothing
Set objResetBar = Nothing
End Sub
Private sub idtextensibility2_onconnection (Byval application as object, byval connection_
As addindesignerObjects.ext_connectmode, byval address, custom () as variant
DIM ObjmyControl As Object
Msgbox "Connect to Add-INS Object"
'Get an Outlook Application object.
Set objapp = Application
'Get Outlook Mapi Namespace Namespace.
Set objNamespace = objapp.getnamespace ("MAPI")
'Popping up folder selection box
Set objfolder = ObjNameSpace.Pickfolder ()
'Add and Toolbar
Set objbar = objapp.activeexplorer.commandbars
Set objmenubar = objbar.add ("My Menu", True, True)
Objmenubar.visible = TRUE
'Add main menu
Set objmyControl = _
Objmenubar.controls.add (msoControlpopup,,, true)
ObjmyControl.caption = "& menu item"
'Add a menu item
Set objresetbar = Objmycontrol.controls.add (_
Type: = msoControlButton, Temporary: = true, before: = 1)
ObjresetBar.caption = "& Reset Menu"
ObjresetBar.enabled = true
Set objmyButton = ObjmyControl.Controls.add (_
Type: = msoControlButton, Temporary: = true, before: = 1)
ObjmyButton.caption = "& test menu"
ObjmyButton.enabled = true
End Sub
Private sub IDTEXTENSIBILITY2_ONDISCONNECTION (BYVAL Removemode As _
AddindesignerObjects.ext_disconnectMode, Custom () AS VARIANT)
'
End Sub
Private sub idtextensibility2_onstartupcomplete (Custom () AS VARIANT)
'
End Sub
Private sub objapp_itemsend (Byval Item As Object, Cancel AS Boolean)
Dim Prompt As String
Prompt = "You are sure to send emails:" & item.subject & "?"
IF MSGBOX (Prompt $, Vbyesno Vbquestion, ") = vbno then
Cancel = TRUE
END IF
End Sub
Private subbjresetbar_click (Byval Ctrl as Office.commandbarbutton, _
Canceldefault as boolean)
ObjmenuBar.delete
End Sub
Save the project, then compile the code of myoutlook.dll, and the code of the COM loading program is completed. Next needs
Registration components, Windows provides registration components for registration components, and the method is knocking in the DOS command line:
Regsvr32 myoutlook.dll
The system adds myoutlook to the registry, open the Registry Editor, and find the following registration item in the registry:
Note: The Guid in the left list is different from you, this GUID is the system.
Open the text editor, enter the following:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER / Software / Microsoft / Office / Outlook / Addins / MyoutLook.clsoutlook]
"CommandLinesafe" = dword: 00000000
"Description" = "Outlook Samples"
"FriendlyName" = "Outlook Samples"
"Loadingbehavior" = dword: 00000003
Save the content you entered above to a file that is sub-suffix, and then double-click to merge it into the registry.
The COM add-in is now fully established and connected to Outlook. Open Outlook, pop up message box prompt:
"Connect to Add-INS Object" and pop up the folder selection box. In the Outlook window, you can see more menu items.
As shown below:
Now create a new message, then send it, the system will prompt you: "You have to send an email:?". Click to cancel,
Will not send mail.
Now let's see the above code, we implemented the IDTEXTENSIBILITY2 interface in the code, Outlook will call when started.
The ONCONNECTION method of the mouth, transmits its own Application object as a parameter byval application as objectt
We can access the Application objects, files, files in Outlook as long as you get an onConnection method.
Objects such as clips, contacts.
When Outlook is closed, the onbeginshutdown method is called, and we need to release all the created in the code that implements the method.
Object. The other three ways of the IDTEXTENSIBILITY2 interface We don't need to be implemented, but the code is to be written there. Otherwise, the program will not
French compilation. To disconnect the COM loading and Outlook, we will open the registry editor and go to the following item:
HKEY_CURRENT_USER / SOFTWARE / Microsoft / Office / Outlook / Addins
Delete the myoutlook.clsoutlook items can be removed. The above program is compiled by the Win2000 Chinese, Office 2000 Chinese, VB6