Sign in to follow this  
Followers 0
mjolnirmarkiv

Creating custom context menu item in Outlook

9 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Which version of AutoIt and Outlook do you run?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

 

Which version of AutoIt and Outlook do you run?

Hi water,

 

That'd be AutoIt 3.3.12.0 and Outlook 2010.

Edited by mjolnirmarkiv

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Seems it gets much more complex in Outlook 2010.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0