If my window hosts multiple windowless ActiveX controls, which one do I call IOleInPlaceActiveObject::TranslateAccelerator and IOleInPlaceObjectWindowless::OnWindowMessage on?

Commenter Farproc asks how one goes about hosting two windowless ActiveX controls in a single window. In particular, "none of the documentation explains how to choose which control to send IOle­In­Place­Active­Object::Translate­Accelerator and IOle­In­Place­Object­Windowless::On­Window­Message on?"

Actually, the documentation does say.

The documentation for IOle­In­Place­Active­Object::Translate­Accelerator says, "Active in-place objects must always be given the first chance at translating accelerator keystrokes." So you pass the message to the active in-place object. Your window may host multiple windowless ActiveX controls, but at most one of them is the active object at a time. And most of the time, none of them will be active. For example, in Word, most of the time the insertion point is in the text part of the document. Only occasionally do you activate an in-place object by, say, double-clicking on an embedded Excel spreadsheet, at which point Excel adds its menu items to your menu bar and basically takes over your application window for a while.

Here's an example of Windows 95's Wordpad hosting Paint as an in-place active object.

Source: 2.1.6 OLE/COM example: using compound documents

If you have an in-place active object, then it's the one that gets the IOle­In­Place­Active­Object::Translate­Accelerator If, as is usually the case, you don't have an in-place active object, then nobody's IOle­In­Place­Active­Object::Translate­Accelerator gets called because they aren't the in-place active object. (It's right there in the interface name.)

For IOle­In­Place­Object­Windowless::On­Window­Message, the documentation is even more explicit. It contains pretty much a checklist of what you need to do.

For the following messages, the container should first dispatch the message to the windowless object that has captured the mouse, if any. Otherwise, the container should dispatch the message to the windowless object under the mouse cursor. If there is no such object, the container is free to process the message itself:


The container should dispatch the message to the windowless object with the keyboard focus for the following messages:

  • WM_IMExxx

For all other messages, the container should process the message on its own.

There it is, plain as day.

Farproc's last question was "how to track or set 'focus' if there is at least one windowless control."

Um, in a variable?

I was kind of confused by this question because it's part of the deal that when you use windowless controls, you don't have the window manager to take care of keeping track of which sub-object has focus. That now becomes your job.

The user clicked on an object. I guess that's the focus object now. Oh wait, now the user hit the left arrow. I guess the object to the left of that object has focus now. It's just like any other control with windowless sub-components, like list boxes. You have to keep track yourself of the currently-selected item and other properties which the window manager normally does for you. If you don't have any windows, then there is nothing for the window manager to manage. From the window manager's point of view, focus is on your container. You then have to manage focus within your window yourself by keeping track of which of your sub-objects is the focus object.

Comments (15)
  1. Antonio Rodríguez says:

    Woha! Mark this date, 28/5/2012, in your calendars. It's historical: the first time Raymond has posted a picture in his blog!

    To stay in topic, most of what is told in this post is common sense, and it's summed up in the last paragraph: if you don't use the window manager, you can't use it (welcome to Tautology Club!). I understand there are places where windowless controls are needed (i.e.: when you have to show controls inside other application's documents, or when you can't create windows for some other reason), but I have never understood using them as primary controls, given the extra work needed for them to work (and the possible incompatibilities with accessibility software).

  2. jk says:

    the first rule of tautology club is the first rule of tautology club

  3. Marcos Martínez says:

    @Antonio Rodríguez, Raymond has posted several pictures to date.

    Btw, he has hotlinked something hosted in other server. They may replace it with a Goatse. I'd do it. And it would be very funny. ;)

  4. JM says:

    @Marcos: that's just juvenile. Replacing it with Ubuntu screenshots would be better. Actually, replacing it with screenshots of Ubuntu hosting Wordpad hosting Paint would be even better — but I don't know if Wine can make it that far yet.

  5. Marcel says:

    @Marcos: I've been reading this blog daily for about 8 years and this is indeed the first picture I can remember. Everything else were clever CSS or (IIRC) SVG tricks.

  6. @Marcos says:

    @Marcos: I've been reading this blog daily for about 8 years and this is indeed the first picture I can remember. Everything else were clever CSS or (IIRC) SVG tricks.

  7. Ian Boyd says:

    i guess the confusion in the documentation is that you don't give the "Active in-place object" first chance to translate accelerators, you give the "active in-place object" first chance.

    Someone (e.g. me) might might be read documentation as , "ActiveX in-place objects must always…"

    "Active" doesn't mean "ActiveX/COM", it means "has input focus".

  8. steven says:

    8 years isn't long enough :P Raymond has indeed posted pictures before: blogs.msdn.com/…/54831.aspx

    Back on topic: in-place active objects were always touted as a pretty big deal and I could see how they would be useful, but I don't think I've ever truly encountered any real life situation where OLE/COM was used to truly host an application, UI and all, in another. As much as they seem useful, they also seem confusing. Are there many people who used this functionality? Or are there many, less obvious ways in which this was used? Browser plugins seem the closest to me.

  9. voo says:

    @Steven Damn I also couldn't remember that post, my memory is getting hazy :p

    Wrt in-pace active objects: Doesn't word support this for excel tables? I dimly remember this, although I didn't find it ever especially useful

  10. Ivan K says:

    I've used OLE many-a-time to make small changes to Visio documents embedded in Word documents, but for real editing I reckon it's easier to launch full-blown Visio (Visio Object->Open) and then have the changes applied back to the document when exiting). ps: This language, 'Dylan', sounds like the way of the future :)

  11. @Steven Don

    The biggest one that I know of is Internet Explorer. I'm not talking about the ActiveX controls here, but these are examples of an inplace object and having their complete ui hosted. But Internet Explorer is one very big host around the Web Browser control. Office too supports OLE in that you can embed other Office application's document types (it has been so long since I had to do it myself since I usually only use Word for typing documentation these days). Not only that, it should be possible to embed other document types into it, like PDF.

    As far as people using this functionality. Well, I think these days it has dropped off, but I'm not sure how much support OLE had in the first place. OLE could be rather awkward to use from C++ anyway. However, there are still lots of places in Windows that relies on it.

    Anyway, just remember that embeding could be rather seamless depending on how much work was put into the host application, so it is actually rather difficult to know exactly how many applications fully use it, but every time you see someone use the web browser control, then that is one more at least.

  12. kog999 says:

    @Steven Don

    Thanks for linking to that other post. i'm gonna at it to my mental collection of Raymond Quotes.

    Why do some people call the taskbar the "tray"?

    Because they're wrong.

  13. Chris Becke says:

    The problem is, the documentation that exists for OLE sometimes uses the phrase "the windowless object with the keyboard focus" and sometimes refers to the "Active object" – without ever making it explicit that the in-place-active-object is defined as the object-with-keyboard-focus.

  14. 640k says:

    @Marcel: Raymond didn't use the standard SVG, he used VML, which is one of the deprecated non-standard technologies IE6 became infamous for.

  15. Klimax says:

    VML was originally supposed to be standard and directly competed with SVG (which was missing many things back then). Result is known… So it wasn't nonstandard technology, but was made so by W3C.

Comments are closed.