Outlook Add-ins for clipboard enhancement

Add-in Express™ Support Service
That's what is more important than anything else

Outlook Add-ins for clipboard enhancement
 
George Robinson




Posts: 10
Joined: 2010-10-20
Dear Andrei,

I saw your old article at The Code Project about Microsoft Outlook Add-ins.

Before I learn how to write these beasties (I'm a kernel-mode programmer, so high level stuff is shunned in my community), I wanted to ask you to define the capabilities of COM Addins for Outlook 2000 and 2002.

I just want to know if it is possible to intercept a built-in keyboard shortcut (CTRL-V) by a COM Add-in?

Before you ask me "what for?" I will explain what I am trying to do:

I would like to write an Addin to Outlook 2000 and 2002, that would insert an inline GIF or PNG image from the clipboard into the body of an email (inline), when the user presses CTRL-V.

A similar effect can be achieved by the menu command "Insert / Picture...", albeit only from GIF or PNG files on the disk (not from images on the clipboard :/).

In Outlook 2000 and 2002, a native GIF or PNG image present on the clipboard CANNOT be pasted inline into the body of an email, because Outlook does not recognize the GIF nor PNG clipboard formats (incidentally PowerPoint 2002 does recognize them and a native GIF or PNG can be pasted into PP, WITHOUT conversion to a huge CF_BITMAP or CF_DIB).

I am well versed in clipboard WinAPI and file format conversions, but I do not know if a built-in keyboard shortcut can be intercepted and enhanced like that by COM Add-in in Outlook 2000 and 2002.

Can you elaborate ? I'd like to beforehand know before I start learning this hairy high-level stuff...


Regards,
George
Posted 20 Oct, 2010 20:21:19 Top
George Robinson




Posts: 10
Joined: 2010-10-20
I was thinking how to narrow down my questions and I came up with these 5 most important items:

1) Is this possible for an Outlook 2000 or 2002 Add-in, at all?

2) Does Outlook have an event for the "Paste Action" (invoked via kbd shortcut or the Edit menu)? What is its name?

3) If answer to pt.2 is "No" - what is the keyboard event during email editing (for CTRL-V interception)?

4) Does Outlook Object Model have an event for painting the "Paste" command on the Edit menu ? (in this event Outlook must decide whether to gray-out the "Paste" command if the clipboard does not contain a known format). What is the name of this event and a property to enable this "Paste" command - so it is not grayed-out on the Edit menu ?

5) I don't want to reinvent the wheel. Does an Add-in that adds support for a new clipboard format already exist somewhere ?


Thanks in advance,
George

P.S.
I do not want to intercept WM_KEYDOWN sent to the email editing window, but I will if I have to...
Posted 21 Oct, 2010 06:45:57 Top
Andrei Smolin


Add-in Express team


Posts: 18791
Joined: 2006-05-11
Hi George,

George Robinson wrote:
1) Is this possible for an Outlook 2000 or 2002 Add-in, at all?


Yes.

George Robinson wrote:
2) Does Outlook have an event for the "Paste Action"? What is its name?


There are two e-mail editors in Outlook 2000-2003: the built-in one and Word. The Outlook object model allow you to do nothing with the built-in editor. Still, you can use Spy++ to understand what is possibile to do with it using Win32 API.

When Word is used as the default e-mail editor, you can intercept many pure-Word events such as WindowSelectionChange (I assume it occurs after the paste). Anyway, this approach requires that your add-in is loaded by Word since Outlook starts Word in a new process (or re-use an existing Word preocess) and opens a WordMail inspector window in that process.

I've created a simple add-in supporting Word and Outlook, added a Keyboard Shortcut component onto the add-in module and wrote the code below:

private void adxKeyboardShortcut1_Action(object sender)
{
    System.Diagnostics.Debug.WriteLine(this.HostName);
}


That code prints "Word" in Word in the WordMail inspector window. In the built-in Outlook editor it prints "Outlook". I've tested the code in Outlook 2000 SP-3 and Outlook 2002 SP3.

George Robinson wrote:
4) I don't want to reinvent the wheel. Does an Add-in that adds support for a new clipboard format already exist somewhere ?


I'm not aware of such an add-in.

George Robinson wrote:
I do not want to intercept WM_KEYDOWN sent to the email editing window, but I will if I have to...


Add-in Express handles keyboard shortcuts by creating hooks, sending messages to a hidden add-in window and cancelling the actions; the window procedure of that window initiates the Action event of ADXKeyboardShortcut. In the built-in e-mail editor case, that approach will not allow you to get the desired goal unless you are lucky with the Win32 API side of the editor. That is, it looks like you need to intercept Ctrl+V yourself.

In Outlook 2000 and 2002, a native GIF or PNG image present on the clipboard CANNOT be pasted inline into the body of an email...
I would like to write an Addin to Outlook 2000 and 2002, that would insert an inline GIF or PNG image from the clipboard into the body of an email (inline), when the user presses CTRL-V


Is that a contradiction?


Andrei Smolin
Add-in Express Team Leader
Posted 21 Oct, 2010 07:56:39 Top
Andrei Smolin


Add-in Express team


Posts: 18791
Joined: 2006-05-11
George Robinson wrote:
4) Does Outlook Object Model have an event for painting the "Paste" command on the Edit menu ? (in this event Outlook must decide whether to gray-out the "Paste" command if the clipboard does not contain a known format). What is the name of this event and a property to enable this "Paste" command - so it is not grayed-out on the Edit menu ?


Thre's no such event but because that item is of the CommandBarButton type (whether it is on the main menu or in a context menu), you can find it in the command bar system and handle its Click event.

Note, that the built-in e-mail editor isn't a CommandbarButton. There's nothing to deal with it except for using Win32 API but I don't know if it is possible at all.


Andrei Smolin
Add-in Express Team Leader
Posted 21 Oct, 2010 08:01:19 Top
George Robinson




Posts: 10
Joined: 2010-10-20
No it is not a contradiction, because there is a big difference between "pasting" and "inserting".
The GIF or PNG image can be inserted from a file via the Insert / Picture... menu command, but it cannot be "pasted" from the clipboard.


George wrote:
In Outlook 2000 and 2002, a native GIF or PNG image present on the clipboard CANNOT be pasted inline into the body of an email...
I would like to write an Addin to Outlook 2000 and 2002, that would insert an inline GIF or PNG image from the clipboard into the body of an email (inline), when the user presses CTRL-V


Is that a contradiction?


Anyway, thanks for answering my questions. Knowing from an expert what is possible with these COM Add-ins and what is not, will save me a lot of time by not going the wrong path :)

Regards,
George
Posted 21 Oct, 2010 08:37:11 Top
Andrei Smolin


Add-in Express team


Posts: 18791
Joined: 2006-05-11
Andrei Smolin wrote:
Note, that the built-in e-mail editor isn't a CommandbarButton. There's nothing to deal with it except for using Win32 API but I don't know if it is possible at all.


A correction. The above should read as folows:

Note, that the Paste command in the context menu of the built-in e-mail editor isn't a CommandbarButton. There's nothing to deal with it except for using Win32 API but I don't know if it is possible at all.

You are welcome.


Andrei Smolin
Add-in Express Team Leader
Posted 21 Oct, 2010 08:54:17 Top
George Robinson




Posts: 10
Joined: 2010-10-20
On a non-technical and philosophical side of things...
Do you think that my goal: "adding support for new clipboard format to Outlook", has merit, or it is useless and nobody needs it but me?

Also, why do you think Microsoft allowed inserting the PNG/GIF images from files but not from the clipboard?


Regards,
George
Posted 21 Oct, 2010 09:04:33 Top
Andrei Smolin


Add-in Express team


Posts: 18791
Joined: 2006-05-11
Hi George,

I've never met such a request. I'd check if Google noticed the existence of that problem.

George Robinson wrote:
Also, why do you think Microsoft allowed inserting the PNG/GIF images from files but not from the clipboard?


Oh, I know nothing about this. Probably, that is a known issue or bug mentioned on support.microsoft.com, see http://www.google.com/search?q=paste+image+png+OR+gif+site%3Asupport.microsoft.com&sourceid=ie7&rls=com.microsoft:en-us:IE-SearchBox&ie=&oe=#sclient=psy&hl=en&rls=com.microsoft:en-us%3AIE-SearchBox&q=paste+image+gif+site:support.microsoft.com+-ASP+-UserForm+clipboard&aq=f&aqi=&aql=&oq=&gs_rfai=&pbx=1&fp=956ab502b015b9a1


Andrei Smolin
Add-in Express Team Leader
Posted 21 Oct, 2010 09:27:47 Top
George Robinson




Posts: 10
Joined: 2010-10-20
BTW: I have verified that when the option "Use Microsoft Word to edit -email messages" is enabled in Outlook 2002, then it is possible to paste inline PNG images from the clipboard into the message body. However when the message arrived it contained a GIF file instead. I wonder who converted the PNG to GIF - MS-Word or MS-Outlook ?!

I hate when programs do that behind my back and without my permission. In this case the conversion to GIF format forces the color palette to 8-bit GIF index, which is a considerable loss of information from the 24-bit palette of the original PNG file.
Posted 21 Oct, 2010 09:43:44 Top
Andrei Smolin


Add-in Express team


Posts: 18791
Joined: 2006-05-11
Hi George,

I think it's Word. But I'd check the HTML it generates, see MailItem.HTMLBody.


Andrei Smolin
Add-in Express Team Leader
Posted 21 Oct, 2010 10:43:38 Top