Relationship between a window and its associated taskbar button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Rae [MVP]

    Relationship between a window and its associated taskbar button

    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


  • Jeff Johnson

    #2
    Re: Relationship between a window and its associated taskbar button

    "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
    news:%237vZ1WoO JHA.1144@TK2MSF TNGP05.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.publi c.win32.program mer.shell
    group, so the closest thing might be microsoft.publi c.win32.program mer.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.


    Comment

    • Mark Rae [MVP]

      #3
      Re: Relationship between a window and its associated taskbar button

      "Jeff Johnson" <i.get@enough.s pamwrote in message
      news:OGu8CupOJH A.1164@TK2MSFTN GP03.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.publi c.win32.program mer.shell
      group, so the closest thing might be microsoft.publi c.win32.program mer.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:


      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


      Comment

      • Jeff Johnson

        #4
        Re: Relationship between a window and its associated taskbar button

        "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
        news:uUwIp0pOJH A.4700@TK2MSFTN GP03.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.


        Comment

        • Mark Rae [MVP]

          #5
          Re: Relationship between a window and its associated taskbar button

          "Jeff Johnson" <i.get@enough.s pamwrote in message
          news:uYoLQIqOJH A.1172@TK2MSFTN GP03.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 "associatio n" 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


          Comment

          • Jeff Johnson

            #6
            Re: Relationship between a window and its associated taskbar button

            "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
            news:e1Mr4hqOJH A.2312@TK2MSFTN GP03.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.


            Comment

            • Jeff Johnson

              #7
              Re: Relationship between a window and its associated taskbar button

              "Jeff Johnson" <i.get@enough.s pamwrote in message
              news:ez%238pjsO JHA.4304@TK2MSF TNGP05.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++.


              Comment

              • Jeff Johnson

                #8
                Re: Relationship between a window and its associated taskbar button

                "Jeff Johnson" <i.get@enough.s pamwrote in message
                news:O7z2HqsOJH A.4304@TK2MSFTN GP05.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.


                Comment

                • Mark Rae [MVP]

                  #9
                  Re: Relationship between a window and its associated taskbar button

                  "Jeff Johnson" <i.get@enough.s pamwrote in message
                  news:uFcQI2sOJH A.780@TK2MSFTNG P05.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
                  >ShowInTaskba r 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


                  Comment

                  • Ben Voigt [C++ MVP]

                    #10
                    Re: Relationship between a window and its associated taskbar button



                    "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
                    news:u9nsx5sOJH A.1012@TK2MSFTN GP04.phx.gbl...
                    "Jeff Johnson" <i.get@enough.s pamwrote in message
                    news:uFcQI2sOJH A.780@TK2MSFTNG P05.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
                    >>ShowInTaskb ar 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_APPWINDO W. When ShowInTaskbar is true the bit in the BitVector is
                    >set to 1, so that could corresponding to turning on this flag.
                    >
                    Interesting - thanks.

                    Creates an overlapped, pop-up, or child window with an extended window style; otherwise, this function is identical to the CreateWindow function. (ANSI)

                    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

                    Comment

                    • Jeff Johnson

                      #11
                      Re: Relationship between a window and its associated taskbar button

                      "Ben Voigt [C++ MVP]" <rbv@nospam.nos pamwrote in message
                      news:78D5176A-9CCA-4A32-ABDB-0E6E138506E6@mi crosoft.com...
                      Creates an overlapped, pop-up, or child window with an extended window style; otherwise, this function is identical to the CreateWindow function. (ANSI)

                      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?


                      Comment

                      Working...