IE add-on development: help, my toolbar looks ugly!

As promised, this is the first in what will be a few articles about some of the pitfalls involved in writing IE add-ons, based on my own experience in writing Find As You Type for Internet Explorer. This isn't meant to be a tutorial or a definitive guide to writing add-ons; it's assumed you have at least some knowledge on how to do this. For a review of the basics, you can check this article on MSDN.

A list of the articles in this series is available here.

The first item I will cover is visual styles. Suppose you were to write you own add-on based on the guide at the link above, or even if you just compile the samples from MSDN or CodeProject or similar, and then run them. You will soon notice that your toolbar or explorer bar doesn't use the Windows XP theme (or the Vista theme on Vista), or visual style. Instead it will use the Windows Classic look. Here's what the Find As You Type toolbar looks like without visual styles:

Find As You Type without XP Visual Styles applied

As you can see, this looks quite out of place, because the rest of Internet Explorer is using the proper theme.

So how to go about fixing this. Unfortunately, the answer to that is quite hard to find. Some casual googling will not reveal it (although it can be found that way, but it's quite buried). Of course it's my hope that if you googled this problem, you ended up on this page. :)

Fortunately, once you know the answer, it's quite simple to actually do it. The answer is described in Microsoft Knowledge Base article 830033, which, although it says it's about Office add-ons, it also applies to Internet Explorer add-ons.

As it turns out, you must add a special manifest resource to your application. This is quite similar to how you'd make any application support visual styles. The difference is that, instead of the normal CREATEPROCESS_MANIFEST_RESOURCE_ID, you must use the ISOLATIONAWARE_MANIFEST_RESOURCE_ID.

Note that if you are using Visual Studio 2005, you don't actually need to create (or modify) a resource file like it specifies in the article. You can simply add the manifest file to your Visual C++ Win32 DLL project, and it will be embedded automatically. For DLL projects, Visual Studio 2005 automatically uses the ISOLATIONAWARE_MANIFEST_RESOURCE_ID to do this. After this is done, Find As You Type looks like this.

Find As You Type with XP Visual Styles applied

And that, of course, looks much nicer. There remains one problem that I do not yet know how to solve. If you open any windows from your add-on, for instance using the Win32 MessageBox or DialogBox function, they will still not have visual styles. Considering that even Microsoft's own Internet Explorer Developer Toolbar suffers from this problem, I don't know if there even is a solution for that. But if anyone knows how, I'd appreciate it if they'd let me know.

That concludes my first IE add-on article. Next time, we'll look at how to handle messages if you're writing a toolbar.

Categories: Programming
Posted on: 2006-08-31 21:35 UTC.

Comments

frustrated IE toolbar developer

2006-12-28 14:29 UTC

It rocks! I was frustrated by that I couldn't find how to make the controls look like other IE controls, and now after 1.5 minutes they do... amazing!

wtbw

2007-02-22 19:59 UTC

Isolation is dealt with in WinUser.Inl, part of the PSDK. If you look right at the end of that file, you can see that it takes over several common win32 functions (CreateWindowEx/DialogBoxParam/etc) to make isolation work. However, it deliberately omits MessageBox and GetClassInfo, "as [they are] popular C++ member function name[s]". So the simple answer to your question is, use MessageBoxEx instead of MessageBox, and that should work. DialogBox is a macro that uses DialogBoxParam, so that *should* work already.

Be sure you've defined ISOLATION_AWARE_ENABLED before any includes in stdafx.h as well (it's mentioned in the article you linked, but not in your post).

wtbw

2007-02-22 20:26 UTC

After a bit more digging, if you (or someone else reading this blog entry after googling!) are using ATL/MFC, then you might run into more problems as apparently their runtime libraries weren't compiled isolation aware. You'll need to use the activation context APIs manually; there's a good thread about it here:

http://groups.google.com/group/microsoft.public.platformsdk.shell/browse_thread/thread/f1aece47175ebae8/17d14d09ecf4ecfd?lnk=st&rnum=7

In case that link dies at some point in the future: Activation contexts aren't as scary as they may first seem. Just create one with CreateActCtx with your HMODULE and the resource ID of your manifest, activate it with ActivateActCtx before you call Create/DoModal/whatever does your window creation, and deactivate it afterwards with DeactivateActCtx (and release once you're finished with ReleaseActCtx).

Hope that helps someone!

Sven Groot Author comment

2007-02-22 21:53 UTC

Thanks for the information, I'll definitely look at that for the next version. I had already discovered that I was wrong about DialogBox, since I use that in version 1.2 and it doesn't have that problem.

As for your second entry, I'm not using ATL/MFC, but it's useful information nonetheless.

Sven Groot Author comment

2007-02-23 00:15 UTC

I tried it, and it works. I don't even need to use MessageBoxEx; explicitly calling IsolationAwareMessageBox also works.

Thanks again.

Tien Tien

2008-02-14 02:06 UTC

I try to write a add-on for IE (auto print without dialog), but i have some problem
Do you know where i setfocus to IE for this code SendKeys.SendWait("^{p}") work
This is my code:
Int32 hMain = Win32Lib.FindWindow("IEFrame", "TestPrint - Windows Internet Explorer");
Win32Lib.SetForegroundWindow(hMain);
System.Threading.Thread.Sleep(2000);
SendKeys.SendWait("^{p}");

The code above only work when i call a nother page but when it call itself, it not work

Add comment

Comments are closed for this post. Sorry.

Latest posts

Categories

Archive

Syndication

RSS Subscribe