Jump to content

Creating custom context menu item in Outlook


Go to solution Solved by water,

Recommended Posts

Hi there!

Experienceing problems creating custom item in the context menu. Wondering if anyone could help?

Here's very rough example, on "F1" it creates menu bar control "New Item" and displays it (just to check if it works at all). On context menu display it creates "New Item" context menu control (it does indeed, $outlook.ActiveExplorer.CommandBars("Context Menu").Controls collection returns new control among others) but doesn't not display it in actual context menu.

So that'd be the problem right now -- I'm obviously missing smth here and trying to figure out how to display newly created item in the context menu.

HotKeySet ("{F1}", "CreateMenuBarItem")

Global $outlook = ObjGet ("", "Outlook.Application")
If not IsObj ($outlook) Then Exit MsgBox (48, "Error", "Launch Outlook first!")
Global $outlook_event = ObjEvent ($outlook, "Outlook")

While 1
  Sleep (10)
WEnd

$outlook_event.Stop
$outlook_event = ""

Func OutlookItemContextMenuDisplay ($p_command_bar, $p_selection)
  ;MsoControlType constants: http://msdn.microsoft.com/en-us/library/office/aa170976.aspx
  OutlookCommandBarAddItem ($p_command_bar, 1, "New Item", "NewItem")
  Switch @error
    Case 0
      ToolTip ("No errors!")
    Case 1
      ToolTip ("Specified command bar does not exists!")
    Case 2
      ToolTip ("Not allowed item type has been specified!")
    Case 3
      ToolTip ("Specified control already exists!")
    Case 4
      ToolTip ("Failed to create new control!")
  EndSwitch
EndFunc

Func OutlookCommandBarAddItem ($p_command_bar, $p_item_type, $p_item_caption, $p_item_tag, $p_item_faceid = 0, $p_item_visible = true, $p_item_id = 1, $p_item_param = "", $p_item_before = 1, $p_item_temp = false)
  ;Check if command bar object exists
  If not IsObj ($p_command_bar) Then Return SetError (1, 0, 0)
  ;Check if item type is within allowed values
  If $p_item_type < 1 or ($p_item_type > 5 and $p_item_type <> 10) Then Return SetError (2, 0, 0)
  ;Check if specified item already exists in the command bar
  ;See: http://msdn.microsoft.com/en-us/library/microsoft.office.core.commandbar.findcontrol.aspx
  If IsObj ($p_command_bar.FindControl($p_item_type, $p_item_id, $p_item_tag)) Then Return SetError (3, 0, 0)

  ;See: http://msdn.microsoft.com/en-us/library/microsoft.office.core.commandbarcontrols.add.aspx
  Local $new_item = $p_command_bar.Controls.Add($p_item_type, $p_item_id, $p_item_param, $p_item_before, $p_item_temp)
  If not IsObj ($new_item) Then Return SetError (4, 0, 0)

  $new_item.Caption = $p_item_caption
  $new_item.Tag     = $p_item_tag
  $new_item.FaceId  = $p_item_faceid
  $new_item.Visible = $p_item_visible

  Return $new_item
EndFunc

Func CreateMenuBarItem ()
  Local $menu_bar = $outlook.ActiveExplorer.CommandBars("Menu Bar")
  OutlookCommandBarAddItem ($menu_bar, 1, "New Item", "NewItem")
EndFunc

Thanks in advance for the help!

P.S.: Just FYI, I have used this as template: http://office.microsoft.com/en-us/outlook-help/HV080800048.aspx

Edited by mjolnirmarkiv
Link to comment
Share on other sites

Still trying to figure out the problem here when I have a minute to spare, won't mind a little help. Because I have no idea how Outlooks creates it's context menu in any given situtation before it shows it to the user. Thought that command bar returned by "ItemContextMenuDisplay" would do the trick, but regardless of how many custom controls I create there -- it won't show them.

Link to comment
Share on other sites

Which version of AutoIt and Outlook do you run?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I have the same environment here. And I get the same result: It doesn't work.

What exactly do you want to do?

Right click on an item in the explorer and have the "New Item" entry be displayed in the context menu?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I have the same environment here. And I get the same result: It doesn't work.

What exactly do you want to do?

Right click on an item in the explorer and have the "New Item" entry be displayed in the context menu?

Yep, exactly. And then do whatever on that item click, should not be a problem I hope.

Link to comment
Share on other sites

Seems it gets much more complex in Outlook 2010.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Solution

Maybe this article sheds some light on the subject.

Extending the User Interface in Outlook 2010

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...