Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Selecting the WinXP Address Toolbar & Activating it

174 views
Skip to first unread message

Alex Maghen

unread,
Sep 26, 2004, 9:29:01 AM9/26/04
to
Hi. From within a C# windows application, I'd like to effectively "click" in
the WinXP taskbar Address Toolbar box. In other words, I'd like my app to set
the UI so that that toolbar is selected and activated.

I imagine that that's done with some Win32 stuff but I have no idea how.
Ideas?

Alex

Jim Barry

unread,
Sep 29, 2004, 12:24:46 PM9/29/04
to
Alex Maghen wrote:
> Hi. From within a C# windows application, I'd like to effectively "click" in
> the WinXP taskbar Address Toolbar box. In other words, I'd like my app to set
> the UI so that that toolbar is selected and activated.

Amazingly enough, it turns out that this is possible to do without even needing to resort to any undocumented hacks! The key is the TrayBandSiteService class, whose CLSID is defined in the headers but is otherwise totally undocumented. The CLSID does not actually appear under [HKEY_CLASSES_ROOT\CLSID] but Explorer, on startup, registers a class factory whose CreateInstance method returns the tray's band site object. Marshalling support is provided for IBandSite and IDeskBand so this works nicely. Having got the tray's IBandSite interface, the desk bands can be enumerated. The "Address" band can be identified by comparing its known CLSID with that returned by IPersist::GetClassID. The final piece of the puzzle is finding and activating the band's window. The window can be obtained via IOleWindow::GetWindow; however, because the band is in a different thread (indeed a different process), the two threads must be attached using AttachThreadInput before calling SetFocus.

Here is some sample code:

#include <Windows.h>
#include <ShlObj.h>
#include <ComDef.h>

_COM_SMARTPTR_TYPEDEF(IBandSite, __uuidof(IBandSite));
#define QI_ARGS(Type, pp) IID_##Type, reinterpret_cast<void**>(static_cast<Type**>(pp))

bool ActivateAddressBand()
{
// The address band CLSID is not in any header but can be found in the "Desktop Bands" component category.
CLSID CLSID_AddressBand = {0x01E04581, 0x4EEE, 0x11d0, 0xBF, 0xE9, 0x00, 0xAA, 0x00, 0x5B, 0x43, 0x83};

// Connect to the tray band site.
IBandSitePtr bs;
bs.CreateInstance(CLSID_TrayBandSiteService);
if (bs)
{
// Iterate through the available bands.
LONG count = bs->EnumBands(UINT(-1), 0);
for (LONG i = 0; i != count; ++i)
{
// Get the band object.
IDeskBandPtr band;
DWORD bandID = 0;
bs->EnumBands(i, &bandID);
bs->GetBandObject(bandID, QI_ARGS(IDeskBand, &band));

// Get IPersist so we can check the CLSID.
if (IPersistPtr persist = band)
{
// Is it the Address band?
CLSID clsid = CLSID_NULL;
persist->GetClassID(&clsid);
if (clsid == CLSID_AddressBand)
{
// Found the band, so get its window handle.
if (IOleWindowPtr ow = band)
{
HWND window = 0;
ow->GetWindow(&window);

// To set the focus to a window in another thread, we need to use AttachThreadInput.
DWORD thread = GetWindowThreadProcessId(window, 0);
AttachThreadInput(GetCurrentThreadId(), thread, TRUE);
SetFocus(window);
AttachThreadInput(GetCurrentThreadId(), thread, FALSE);
return true;
}
}
}
}
}
return false;
}


--
Jim Barry, MVP for Windows SDK

Tibor Jakab-Barthi

unread,
Nov 25, 2004, 10:17:03 AM11/25/04
to
Do you know if TrayBandSiteService si available on W2K too?
It seems to me that it isn't, but maybe I'm doing something wrong.

I have some code running on XP, but on W2K i get:
"System.Runtime.InteropServices.COMException
Message: COM object with CLSID {F60AD0A0-E5E1-45CB-B51A-E15B9F8B2934} is
either not valid or not registered."

Regards, Tibor

"Jim Barry" <j...@mvps.org> wrote in message
news:e6uzXDkp...@TK2MSFTNGP15.phx.gbl...

Jim Barry

unread,
Nov 25, 2004, 10:55:21 AM11/25/04
to
Tibor Jakab-Barthi wrote:
> Do you know if TrayBandSiteService si available on W2K too?

No, it was introduced in XP.

Tibor Jakab-Barthi

unread,
Nov 26, 2004, 11:58:31 AM11/26/04
to
Thanks, I was afraid of this.

What do you suggest:
1. Use messaging both on 2K and XP
2. Use messaging on 2K and TrayBandSiteService on XP?

BR, Tibor

"Jim Barry" <j...@mvps.org> wrote in message

news:%239Sttcw...@TK2MSFTNGP15.phx.gbl...

Jim Barry

unread,
Nov 29, 2004, 7:38:20 AM11/29/04
to
Tibor Jakab-Barthi wrote:
> What do you suggest:
> 1. Use messaging both on 2K and XP
> 2. Use messaging on 2K and TrayBandSiteService on XP?

I would go for #2, though I would avoid an explicit version check, i.e. use TrayBandSiteService if available, otherwise do the other thing.

Tibor Jakab-Barthi

unread,
Nov 29, 2004, 12:57:53 PM11/29/04
to
Thanks for you advice.

Have a nice day!

"Jim Barry" <j...@mvps.org> wrote in message

news:uW%23ARBh1...@tk2msftngp13.phx.gbl...

Jim Barry

unread,
Apr 28, 2005, 6:53:33 PM4/28/05
to
Marco wrote:
>> _COM_SMARTPTR_TYPEDEF(IBandSite, __uuidof(IBandSite));
>
> Hi Jim,
> I tried to compile this sample code, but the line above produces this
> compiler error:
>
> "error C2259: 'IBandSite' : cannot instantiate abstract class"
>
> Do you can tell me why ?! :-S

Again, you may need to update your SDK.

Marco

unread,
Apr 29, 2005, 8:30:06 AM4/29/05
to
Jim Barry" wrote:


I installed the latest Paltform SDK (windows 2003 SP1 released in april) but
the compiler error persists ! :-(

Regards,
Marco

Jim Barry

unread,
May 3, 2005, 11:05:03 AM5/3/05
to
Marco wrote:
>> _COM_SMARTPTR_TYPEDEF(IBandSite, __uuidof(IBandSite));
>
> Hi Jim,
> I tried to compile this sample code, but the line above produces this
> compiler error:
>
> "error C2259: 'IBandSite' : cannot instantiate abstract class"

Hmmm, that is the error I get if I don't #include <ComDef.h>...

Jim Barry

unread,
May 6, 2005, 6:32:50 AM5/6/05
to
Marco wrote:
> No, sorry, the #include <comdef.h> is present. :-S

I'm all out of ideas then, I'm afraid.

Demián Gutierrez

unread,
Jun 27, 2005, 6:05:04 PM6/27/05
to
Hello

Please, how is the messaging way for 2K, I have to do that but I don't find
documentation, do you have a link or a hint/clue to beging to search about?

Thanks, Demian.

Jim Barry

unread,
Jun 28, 2005, 8:08:13 PM6/28/05
to
Demián Gutierrez wrote:
> Please, how is the messaging way for 2K, I have to do that but I don't find
> documentation, do you have a link or a hint/clue to beging to search about?

Sorry, I'm actually not too sure what method Tibor was referring to.

0 new messages