Windows Live Writer hosts an Internet Explorer control for editing, but there’s no zoom control. I’d like to be able to send a zoom command to it. Since other apps host the IE browser, I’d think a utility that can send zoom commands to specific IE browser instances would be really handy, but I haven’t found one.
I’ve seen there’s a command, OLECMDID_OPTICAL_ZOOM, but I’m not sure how to send that command to it. Ideally I’d like to do this from C# or Powershell.
Note: The question is asking about controlling the zoom in a web browser control in a running application which I did not create, the main example being the editor surface in Windows Live Writer.
Short version: I’m not entirely sure you can do what you’re attempting to do.
I have some code that actually gets a handle on the HTML document inside the WLW window, and that works, but what I’m finding is that I can’t actually get a reference to the parent window of the document. I’m no native Windows guy, but I’ve done some PInvoke in my time. It may be just that my lack of native Windows knowledge is stopping me from bridging that last gap.
From what I’ve put together, the general process for getting a reference to an IE window is:
Once you have that parent window, you can call the IWebBrowser2.ExecWB method to run your OLE zoom command.
The problem is that the IHTMLDocument2.parentWindow property always seems to throw an InvalidCastException when you try to access it. From what I’ve read, that’s the deal when you try to grab the parent window from a thread other than the one the document is running on.
So, anyway, I’ll drop the code on you that gets the HTML document reference and if you can bridge that tiny last step of the way, you’ll have your answer. I just couldn’t figure it out myself.
This is a console app. You’ll need a reference to Microsoft.mshtml for the IHTMLDocument2 interface.