# Programmatically Showing/Hiding Desktop Toolbars

This topic is 4423 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I'm trying to find some Windows API call that will allow me to show and hide my custom Desk Band toolbar through code. When I install the Desk Band I want it to automatically be visible to the user, so they won't have to right click the system toolbar and enable it through the popup menu (like you do with the Quick Launch and Desktop toolbars, for example). I know that the Google Search Bar, for one, can do this, so it must be possible... I appreciate any pointers in the right direction.

##### Share on other sites
I've been searching for a few days now without luck, so I'm starting to resort to hacks.

What I'm trying to do in this code is manually manipulate the taskbar's popup menu that lets the user show and hide toolbars:

HWND hParent;
hParent = FindWindowEx(hParent, NULL, "Shell_TrayWnd", NULL);

if (hParent == NULL)
return 0;

hParent = FindWindowEx(hParent, NULL, "ReBarWindow32", NULL);

if (hParent == NULL)
return 0;

POINT pt = {0,0};

Sending the message shows the popup menu at point 0,0 on the screen, and I can grab its window handle in hPopupMenu, but I don't know how to go about manipulating the popup menu from here. Is there anyway I can convert the window handle to a menu handle, and then use the standard menu functions to select the right command?

Thanks,
Jon

##### Share on other sites
I havent made desk bands so forgive me if I've misinterpreted the documentation and online example, but...

When you create the window for the desk band, I believe it should automatically show if you specify WS_VISIBLE. Attempting to access the menu by hand seems like a Bad Idea to me.

##### Share on other sites
Take the code out of this MSDN sample, and hack it around, and run it from your installer code. You may have to do some Evil COM Stuff to invoke that from something that isn't a BHO (in my experience, using a BHO for deskband toggling is retardedly overcomplicating things, whatever Microsoft says). In my case, I had an IE toolbar plugin, so I basically took that code and ran it in the DLL registration process, so that when the DLL gets RegSvr32'd by my installer script, the visibility toggle is done automatically. You may have to run the toggle two times to get it to take effect properly because of the dark voodoo in the deskband preferences serialization code.

BTW, when I was doing work on this stuff, I found that the magic word is "toolband." Virtually all of the good resources out there seem to be keyed on the term "toolband" even though it is rarely (if ever) mentioned in the MSDN docs on the technology. Go figure...

I've got some stock code for doing this visibility toggle laying around; if I remember tomorrow at work I'll post it up. Drop me a PM if I go more than 24 hours or so without showing up here again [wink]

##### Share on other sites
Here we go; this should drop into basically any Windows code and do the job you need. Fairly easy to adapt and hopefully straightforward.

	IWebBrowser2 *pIE;	HRESULT hr =  CoCreateInstance(CLSID_InternetExplorer, NULL,								   CLSCTX_LOCAL_SERVER,								  IID_IWebBrowser2,(void**)&pIE);	pIE->put_Visible(VARIANT_FALSE);	VARIANT vtBandGUID;	VARIANT vtShow;	VARIANT vtUnused;	vtBandGUID.vt = VT_BSTR;	// Put your band's GUID here	vtBandGUID.bstrVal = SysAllocString(OLESTR("{00000000-0000-0000-0000-000000000000}"));	vtUnused.vt = VT_BOOL;	vtUnused.boolVal = true;	vtShow.vt = VT_BOOL;	vtShow.boolVal = false;	pIE->ShowBrowserBar(&vtBandGUID, &vtShow, &vtUnused);	vtShow.boolVal = true;	pIE->ShowBrowserBar(&vtBandGUID, &vtShow, &vtUnused);	SysFreeString(vtBandGUID.bstrVal);	pIE->Quit();	pIE->Release();

##### Share on other sites
I appreciate the link, but I don't think it is going to help in my case.

A deskband, as I've created it, is similar to the different types of IE bands, but it is loaded from the Windows shell and creates a toolbar on the Windows taskbar. To see an example, right click the taskbar and check the Quick Launch item under Toolbars, for example.

Microsoft's terminology seems to be used interchangeably for deskbands, IE tool bands, and IE explorer bands. That is what is making my job so hard here. The IE bands modify not only IE, but also Windows Explorer, so I don't know if there really is much of a difference after all.

Here's what I based my code on:

You can see pictures of the different types of bands.

##### Share on other sites
Ahh, right... of course manipulating IE won't work for the taskbar. My oversight [smile]

This is a bit of a sick hack, but the thing that comes to mind at the moment is to use a registry monitor tool and see what happens when you toggle a toolbar manually. That should reveal the key(s) used to store the settings. If you're lucky, they will be stored in a different format than IE's, and be relatively easy to manipulate programatically. Failing that, I don't have any ideas, unless you know of another program that does this programmatically that you can reverse engineer.

##### Share on other sites
Yeah, at this point I'm just trying to find the least-sick hack possible ;)

I found several sites that said Microsoft intentionally left out this functionality, as they want the user to have complete control over their taskbar. Sounds reasonable, but it is kind of silly to force users to manually enable a toolbar after just going through the install process for it, especially for applications like mine that assume the user is inexperienced with computers.

Like I said, the Google toolbar can show and hide itself through its system tray icon. Perhaps I could go through their code to see how they did it. But if the Google Police find out and slap me with the google.com ban stick, my life will be over :)

If anyone knows how I could programmatically manipulate that popup menu, as shown in the first screenshot above, that would be another viable route...

##### Share on other sites
i'm confused; doesn't calling IDockingWindow::ShowDW work for you? assuming of course that you're instancing an IDeskBand object and then getting the IDockingWindow pointer via QueryInterface.

##### Share on other sites
You mean calling it from the deskband object itself? Until the deskband is enabled by the user, its dll is not loaded.