Board index » delphi » Canceling default action of a button in Outlook.
Paul Bayston
Delphi Developer |
Canceling default action of a button in Outlook.2005-10-11 12:30:32 AM delphi180 I am trying to write an COM Addin for Outlook 2000 using Delphi 7 that intercepts when a user is trying to add an attachment to an e-mail by hooking into the OnClick event for that button and setting CancelDefault to True. This is, I believe, how you are supposed to be able to override default button behaviour in Outlook. I have created a tCommandBarButton wrapper object that is connected to the 'Attach' button, and I have written a simple OnClick handler that pops up a message and sets CancelDefault to True. However, when I click my button, I not only get my message box, I also get the 'Insert File' dialog appearing, even though this is supposed to be cancelled. (See below for code sample) Therefore, I'd be most grateful if anyone could give me any pointers as to what I may be doing wrong, or if there is a bug in the Delphi implementation, etc... Thanks, Regards, Paul Bayston ------------------------------------------------------------ procedure TAttachmentTest2.MyNewInspector( Sender: tOutlookInspectors; const MyInspector: _Inspector ); var xButton: CommandBarButton; xButtonWrapper: TOutlookCommandBarButton; xStandard: CommandBar; xInspector: TOutlookInspector; begin xInspector := TOutlookInspector.Create( MyInspector ); xInspector.OnClose := MyCloseInspector; xStandard := MyInspector.CommandBars[ 'Standard' ]; xButton := xStandard.Controls.Item[ 10 ] as CommandBarButton;// Current index of Attach button xButtonWrapper := TOutlookCommandBarButton.Create( xStandard.Controls.Item[ 10 ] ); xButtonWrapper.OnClick := OnButtonClick; end; procedure TAttachmentTest2.OnButtonClick( Sender: TOutlookCommandBarButton; const Ctrl: CommandBarButton; var CancelDefault: WordBool ); begin ShowMessage( 'Hello' ); CancelDefault := True; end; |