By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,115 Members | 894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,115 IT Pros & Developers. It's quick & easy.

Relationship between a window and its associated taskbar button

P: n/a
Hi,

This is really just a theoretical question for my own interest, and not for
any nefarious purpose... :-)

Say we have three applications running - Notepad, Wordpad and Excel - and
each window is in its "normal" state i.e. not maximised, and not minimised
to the taskbar.

We click each of the three taskbar buttons in turn and, of course, the three
applications receive focus one after the other... We click on the Notepad
taskbar button, and Notepad receives focus. Obviously!

Similarly, if we click each of the applications in turn, their associated
taskbar button appears indented, i.e. as if it has been clicked.

My question is, how does Windows relate an application to its associated
taskbar button? I.e. when you click on Notepad, how does Windows "know"
which of the taskbar buttons to indent? I'm assuming it must use a hWnd...?

Assuming it does, is there any way to discover an application's taskbar
button's hWnd from the hWnd of the application itself?

Any assistance gratefully received.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 30 '08 #1
Share this Question
Share on Google+
10 Replies


P: n/a
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
My question is, how does Windows relate an application to its associated
taskbar button? I.e. when you click on Notepad, how does Windows "know"
which of the taskbar buttons to indent? I'm assuming it must use a
hWnd...?

Assuming it does, is there any way to discover an application's taskbar
button's hWnd from the hWnd of the application itself?
Hmmm, unfortunately there's no microsoft.public.win32.programmer.shell
group, so the closest thing might be microsoft.public.win32.programmer.ui.
I've seen tray questions there, so perhaps a taskbar question would be
well-suited there too. I definitely think you need to ask outside of the
..NET groups on this one. But please report your findings! I, too, find this
interesting on a theoretical level. I can't even think of how I might ever
use it, but it'd be cool to know.

However, my prediction is that the info is stored in an internal structure
and is not exposed. A cursory glance of the appbar-related stuff doesn't
reveal any functions or messages that relate to buttons.
Oct 30 '08 #2

P: n/a
"Jeff Johnson" <i.***@enough.spamwrote in message
news:OG**************@TK2MSFTNGP03.phx.gbl...
>My question is, how does Windows relate an application to its associated
taskbar button? I.e. when you click on Notepad, how does Windows "know"
which of the taskbar buttons to indent? I'm assuming it must use a
hWnd...?

Assuming it does, is there any way to discover an application's taskbar
button's hWnd from the hWnd of the application itself?

Hmmm, unfortunately there's no microsoft.public.win32.programmer.shell
group, so the closest thing might be microsoft.public.win32.programmer.ui.
I've seen tray questions there, so perhaps a taskbar question would be
well-suited there too. I definitely think you need to ask outside of the
.NET groups on this one. But please report your findings! I, too, find
this interesting on a theoretical level. I can't even think of how I might
ever use it, but it'd be cool to know.
OK - I'll try a more appropriate newsgroup...
However, my prediction is that the info is stored in an internal structure
and is not exposed. A cursory glance of the appbar-related stuff doesn't
reveal any functions or messages that relate to buttons.
Getting the taskbar button for any running application is (relatively)
easily achievable through a whole slew of p/invoke calls and a bit of unsafe
code:
http://www.codeproject.com/KB/shell/taskbarsorter.aspx

I just can't imagine that Windows is going through all of this every time
someone clicks a taskbar button or a running application's window...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 30 '08 #3

P: n/a
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:uU**************@TK2MSFTNGP03.phx.gbl...
>However, my prediction is that the info is stored in an internal
structure and is not exposed. A cursory glance of the appbar-related
stuff doesn't reveal any functions or messages that relate to buttons.

Getting the taskbar button for any running application is (relatively)
easily achievable through a whole slew of p/invoke calls and a bit of
unsafe code:
http://www.codeproject.com/KB/shell/taskbarsorter.aspx
Egad. I regularly use a utility called TaskArrange, which does just this! I
can't believe I forgot about that. Well, that's cool then.
Oct 30 '08 #4

P: n/a
"Jeff Johnson" <i.***@enough.spamwrote in message
news:uY**************@TK2MSFTNGP03.phx.gbl...
>>However, my prediction is that the info is stored in an internal
structure and is not exposed. A cursory glance of the appbar-related
stuff doesn't reveal any functions or messages that relate to buttons.

Getting the taskbar button for any running application is (relatively)
easily achievable through a whole slew of p/invoke calls and a bit of
unsafe code:
http://www.codeproject.com/KB/shell/taskbarsorter.aspx

Egad. I regularly use a utility called TaskArrange, which does just this!
I use this: http://taskix.robustit.com/
I can't believe I forgot about that. Well, that's cool then.
That certainly allows me to drill down into the taskbar's button collection
(for want of a better term) and find one whose title is the same or similar
to the title of an application's window - it doesn't get me any closer to
finding an "association" between a window and its taskbar button, though...

AAMOI, do you know how a C# WinForms app "suppresses" a form's taskbar
button when its ShowInTaskbar property is set to false...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 30 '08 #5

P: n/a
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:e1**************@TK2MSFTNGP03.phx.gbl...
AAMOI, do you know how a C# WinForms app "suppresses" a form's taskbar
button when its ShowInTaskbar property is set to false...?
No, but since VB6 offers the same capability I'd say there's defintely a
Windows API method of doing it, i.e., it's not a .NET-specific thing.
Oct 30 '08 #6

P: n/a
"Jeff Johnson" <i.***@enough.spamwrote in message
news:ez****************@TK2MSFTNGP05.phx.gbl...
>AAMOI, do you know how a C# WinForms app "suppresses" a form's taskbar
button when its ShowInTaskbar property is set to false...?

No, but since VB6 offers the same capability I'd say there's defintely a
Windows API method of doing it, i.e., it's not a .NET-specific thing.
That was an incomplete answer. Now for the second part: I recommend creating
a couple of windows, identical in all ways except for ShowInTaskbar being
true in one and false in the other and then checking out their window styles
via Spy++.
Oct 30 '08 #7

P: n/a
"Jeff Johnson" <i.***@enough.spamwrote in message
news:O7**************@TK2MSFTNGP05.phx.gbl...
>>AAMOI, do you know how a C# WinForms app "suppresses" a form's taskbar
button when its ShowInTaskbar property is set to false...?

No, but since VB6 offers the same capability I'd say there's defintely a
Windows API method of doing it, i.e., it's not a .NET-specific thing.

That was an incomplete answer. Now for the second part: I recommend
creating a couple of windows, identical in all ways except for
ShowInTaskbar being true in one and false in the other and then checking
out their window styles via Spy++.
Reflector shows that the ShowInTaskbar property controls a bit in a
BitVector32 instance, so I'm really willing to bet it corresponding to a
window style now. Perhaps I should just look up some window styles....

Hmmm, nothing's jumping out at me, but is might be the extended style
WS_EX_APPWINDOW. When ShowInTaskbar is true the bit in the BitVector is set
to 1, so that could corresponding to turning on this flag.
Oct 30 '08 #8

P: n/a
"Jeff Johnson" <i.***@enough.spamwrote in message
news:uF*************@TK2MSFTNGP05.phx.gbl...
>>>AAMOI, do you know how a C# WinForms app "suppresses" a form's taskbar
button when its ShowInTaskbar property is set to false...?

No, but since VB6 offers the same capability I'd say there's defintely a
Windows API method of doing it, i.e., it's not a .NET-specific thing.

That was an incomplete answer. Now for the second part: I recommend
creating a couple of windows, identical in all ways except for
ShowInTaskbar being true in one and false in the other and then checking
out their window styles via Spy++.

Reflector shows that the ShowInTaskbar property controls a bit in a
BitVector32 instance, so I'm really willing to bet it corresponding to a
window style now. Perhaps I should just look up some window styles....

Hmmm, nothing's jumping out at me, but is might be the extended style
WS_EX_APPWINDOW. When ShowInTaskbar is true the bit in the BitVector is
set to 1, so that could corresponding to turning on this flag.
Interesting - thanks.
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 30 '08 #9

P: n/a


"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:u9**************@TK2MSFTNGP04.phx.gbl...
"Jeff Johnson" <i.***@enough.spamwrote in message
news:uF*************@TK2MSFTNGP05.phx.gbl...
>>>>AAMOI, do you know how a C# WinForms app "suppresses" a form's taskbar
button when its ShowInTaskbar property is set to false...?

No, but since VB6 offers the same capability I'd say there's defintely
a Windows API method of doing it, i.e., it's not a .NET-specific thing.

That was an incomplete answer. Now for the second part: I recommend
creating a couple of windows, identical in all ways except for
ShowInTaskbar being true in one and false in the other and then checking
out their window styles via Spy++.

Reflector shows that the ShowInTaskbar property controls a bit in a
BitVector32 instance, so I'm really willing to bet it corresponding to a
window style now. Perhaps I should just look up some window styles....

Hmmm, nothing's jumping out at me, but is might be the extended style
WS_EX_APPWINDOW. When ShowInTaskbar is true the bit in the BitVector is
set to 1, so that could corresponding to turning on this flag.

Interesting - thanks.

http://msdn.microsoft.com/en-us/libr...80(VS.85).aspx
WS_EX_APPWINDOW
Forces a top-level window onto the taskbar when the window is visible.
>

--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Oct 31 '08 #10

P: n/a
"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
news:78**********************************@microsof t.com...
http://msdn.microsoft.com/en-us/libr...80(VS.85).aspx
WS_EX_APPWINDOW
Forces a top-level window onto the taskbar when the window is visible.
Now here's the question: does the LACK of this flag always PREVENT a window
from displaying on the task bar?

What messes with me is the use of the word "force." "Force" suggests to me
that "sometimes apps MAY appear on the taskbar without this flag, but using
it ENSURES that the app will display on the taskbar." See what I mean about
the wording?
Oct 31 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.