Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Getting Shell Tray Info In C#?

Getting Shell Tray Info In C#?

Scheduled Pinned Locked Moved C#
csharpc++comlinuxhelp
17 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Giorgi Dalakishvili

    You can use P/Invoke to call unmanaged functions.

    Giorgi Dalakishvili #region signature my articles My blog[^] #endregion

    A Offline
    A Offline
    Abydosgater
    wrote on last edited by
    #3

    Thanks. Just read your article on minimizing applications to tray with P/Invoke and user32.dll's unmanaged functions, Do you know anywhere i could find an example of the unmanaged function i would use to get a list of the icons and their context menus?

    G 1 Reply Last reply
    0
    • A Abydosgater

      Thanks. Just read your article on minimizing applications to tray with P/Invoke and user32.dll's unmanaged functions, Do you know anywhere i could find an example of the unmanaged function i would use to get a list of the icons and their context menus?

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #4

      What do you mean by list of the icons? Which icons do you mean?

      Giorgi Dalakishvili #region signature my articles My blog[^] #endregion

      A 1 Reply Last reply
      0
      • G Giorgi Dalakishvili

        What do you mean by list of the icons? Which icons do you mean?

        Giorgi Dalakishvili #region signature my articles My blog[^] #endregion

        A Offline
        A Offline
        Abydosgater
        wrote on last edited by
        #5

        I would like to be able to display a list of applications in the shell tray. Just like the application in the C++ Article above, I was wondering if C# had a method to enumerate the tray icons (Bottom left of windows taskbar) and the context menus for them.

        G 1 Reply Last reply
        0
        • A Abydosgater

          I would like to be able to display a list of applications in the shell tray. Just like the application in the C++ Article above, I was wondering if C# had a method to enumerate the tray icons (Bottom left of windows taskbar) and the context menus for them.

          G Offline
          G Offline
          Giorgi Dalakishvili
          wrote on last edited by
          #6

          You can use the methods and functions described in that article. You can use P/Invoke[^] to call functions from native dlls used in that article

          Giorgi Dalakishvili #region signature my articles My blog[^] #endregion

          A 1 Reply Last reply
          0
          • G Giorgi Dalakishvili

            You can use the methods and functions described in that article. You can use P/Invoke[^] to call functions from native dlls used in that article

            Giorgi Dalakishvili #region signature my articles My blog[^] #endregion

            A Offline
            A Offline
            Abydosgater
            wrote on last edited by
            #7

            Ok thanks ill see what i can come up with :)

            G 1 Reply Last reply
            0
            • A Abydosgater

              Ok thanks ill see what i can come up with :)

              G Offline
              G Offline
              Giorgi Dalakishvili
              wrote on last edited by
              #8

              You are welcome :)

              Giorgi Dalakishvili #region signature my articles My blog[^] #endregion

              A 1 Reply Last reply
              0
              • G Giorgi Dalakishvili

                You are welcome :)

                Giorgi Dalakishvili #region signature my articles My blog[^] #endregion

                A Offline
                A Offline
                Abydosgater
                wrote on last edited by
                #9

                Back Again, Having read both your article, and the article i linked above, I have tried to work this out in C# using P/Invoke and FindWindow(). My issue is with FindWindow, Im trying to find the window "Shell_TrayWnd". But when i pass "Shell_TrayWnd" as a parameter for FindWindow i get the following exception:

                Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

                Any idea how i could get around this so i can access the TrayWnd?

                G 1 Reply Last reply
                0
                • A Abydosgater

                  Back Again, Having read both your article, and the article i linked above, I have tried to work this out in C# using P/Invoke and FindWindow(). My issue is with FindWindow, Im trying to find the window "Shell_TrayWnd". But when i pass "Shell_TrayWnd" as a parameter for FindWindow i get the following exception:

                  Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

                  Any idea how i could get around this so i can access the TrayWnd?

                  G Offline
                  G Offline
                  Giorgi Dalakishvili
                  wrote on last edited by
                  #10

                  Usually you get this exception when the signature of method you imported is incorrect. Have you looked at the source code of my articles to see how to declare FindWindow method? You can also find P/Invoke definitions here: P/Invoke[^] or you can use an addin for Visual Studio that generates signature - Redgate has one.

                  Giorgi Dalakishvili #region signature my articles My blog[^] #endregion

                  A 1 Reply Last reply
                  0
                  • G Giorgi Dalakishvili

                    Usually you get this exception when the signature of method you imported is incorrect. Have you looked at the source code of my articles to see how to declare FindWindow method? You can also find P/Invoke definitions here: P/Invoke[^] or you can use an addin for Visual Studio that generates signature - Redgate has one.

                    Giorgi Dalakishvili #region signature my articles My blog[^] #endregion

                    A Offline
                    A Offline
                    Abydosgater
                    wrote on last edited by
                    #11

                    Ah thanks, Yeah i was declaring it wrong, I had a look in your source code and imported the dll and function same as you. Now it works and returns the IntPrt. Back to research for next step.

                    G 1 Reply Last reply
                    0
                    • A Abydosgater

                      Ah thanks, Yeah i was declaring it wrong, I had a look in your source code and imported the dll and function same as you. Now it works and returns the IntPrt. Back to research for next step.

                      G Offline
                      G Offline
                      Giorgi Dalakishvili
                      wrote on last edited by
                      #12

                      Nice to see that you are advancing. Please post if you need more help. Also, please report your progress when you are done :) Thanks.

                      Giorgi Dalakishvili #region signature my articles My blog[^] #endregion

                      A 1 Reply Last reply
                      0
                      • G Giorgi Dalakishvili

                        Nice to see that you are advancing. Please post if you need more help. Also, please report your progress when you are done :) Thanks.

                        Giorgi Dalakishvili #region signature my articles My blog[^] #endregion

                        A Offline
                        A Offline
                        Abydosgater
                        wrote on last edited by
                        #13

                        Thank you for your interest it is extremely appriciated. From what i can tell the next step is to get a count of the icons. To do this i know i must send a message to the window with SendMessage(). I tried something along the lines of:

                        IntPtr intPrtShellTrayWnd = FindWindow("ToolbarWindow32", "");
                        int Count = (int)SendMessage(intPrtShellTrayWnd, TB_GETBUTTON, intPrtShellTrayWnd, "");

                        But i have no definition of TB_GETBUTTON. Im hoping to get it to result just a count of the icons, then ill worry about looping though the tray icons themselves. Have you any idea on TB_GETBUTTON?

                        G 1 Reply Last reply
                        0
                        • A Abydosgater

                          Thank you for your interest it is extremely appriciated. From what i can tell the next step is to get a count of the icons. To do this i know i must send a message to the window with SendMessage(). I tried something along the lines of:

                          IntPtr intPrtShellTrayWnd = FindWindow("ToolbarWindow32", "");
                          int Count = (int)SendMessage(intPrtShellTrayWnd, TB_GETBUTTON, intPrtShellTrayWnd, "");

                          But i have no definition of TB_GETBUTTON. Im hoping to get it to result just a count of the icons, then ill worry about looping though the tray icons themselves. Have you any idea on TB_GETBUTTON?

                          G Offline
                          G Offline
                          Giorgi Dalakishvili
                          wrote on last edited by
                          #14

                          According to the article link you provided you need to send TB_BUTTONCOUNT message. Why don't you follow the article? Secondly, TB_BUTTONCOUNT and TB_GETBUTTON are integeres defined in some header value. So you need to find out int value of these constants and then either define the constants in your program or just use the integer values.

                          Giorgi Dalakishvili #region signature my articles My blog[^] #endregion

                          A 1 Reply Last reply
                          0
                          • G Giorgi Dalakishvili

                            According to the article link you provided you need to send TB_BUTTONCOUNT message. Why don't you follow the article? Secondly, TB_BUTTONCOUNT and TB_GETBUTTON are integeres defined in some header value. So you need to find out int value of these constants and then either define the constants in your program or just use the integer values.

                            Giorgi Dalakishvili #region signature my articles My blog[^] #endregion

                            A Offline
                            A Offline
                            Abydosgater
                            wrote on last edited by
                            #15

                            Thanks for the advice. I read up a bit more, Also found this article: http://www.codeproject.com/KB/shell/taskbarsorter.aspx[^] Which supplies a good user32.cs for a win32api. In the user32 class i have the TB_BUTTONCOUNT and GETBUTTON. There is also a good TBBUTTON Struct for storing the hWnd info for each tray icon. But that Article only works for the windows in the tray, not the notify icons. To the point, I have gotten the count to work, and i can return the value of how many Nofication Icons there are, But i am unsure of how for loop the send message to return each notify icons details. In the C++ it is:

                            for(int i=0; i<count;>{
                            ::SendMessage(m_hTrayWnd, TB_GETBUTTON, i, (LPARAM)data.GetData());
                            data.ReadData(&tb);
                            data.ReadData(&tray,(LPCVOID)tb.dwData);

                            I have the TB_GETBUTTON but i am unsure of what to set for the data variable. Could anyone offer some advice?

                            G 1 Reply Last reply
                            0
                            • A Abydosgater

                              Thanks for the advice. I read up a bit more, Also found this article: http://www.codeproject.com/KB/shell/taskbarsorter.aspx[^] Which supplies a good user32.cs for a win32api. In the user32 class i have the TB_BUTTONCOUNT and GETBUTTON. There is also a good TBBUTTON Struct for storing the hWnd info for each tray icon. But that Article only works for the windows in the tray, not the notify icons. To the point, I have gotten the count to work, and i can return the value of how many Nofication Icons there are, But i am unsure of how for loop the send message to return each notify icons details. In the C++ it is:

                              for(int i=0; i<count;>{
                              ::SendMessage(m_hTrayWnd, TB_GETBUTTON, i, (LPARAM)data.GetData());
                              data.ReadData(&tb);
                              data.ReadData(&tray,(LPCVOID)tb.dwData);

                              I have the TB_GETBUTTON but i am unsure of what to set for the data variable. Could anyone offer some advice?

                              G Offline
                              G Offline
                              Giorgi Dalakishvili
                              wrote on last edited by
                              #16

                              As I can see from the code author uses a class written by him so you need to import that class in your program using DllImport. I am not sure how to do that so you can ask the author of the article. By the way, I have just remembered that there is another way (and probably easier) to call native methods from your application. Are you familiar with Managed c++? It's sort of combination of native c++ and managed code. You can write a dll in managed c++ that does the same job as the article and you will not need to use DllImport. You will just include the header files you need. The dll will be managed so you can reference it from your c# application. Here is an example: Wrapping Around a Native C++ Class[^] Netting C++[^] Wrapping Unmanaged Classes Using Managed Extensions for C++[^] NativeWrapper: a tool for Native Interoperability[^]

                              Giorgi Dalakishvili #region signature my articles My blog[^] #endregion

                              A 1 Reply Last reply
                              0
                              • G Giorgi Dalakishvili

                                As I can see from the code author uses a class written by him so you need to import that class in your program using DllImport. I am not sure how to do that so you can ask the author of the article. By the way, I have just remembered that there is another way (and probably easier) to call native methods from your application. Are you familiar with Managed c++? It's sort of combination of native c++ and managed code. You can write a dll in managed c++ that does the same job as the article and you will not need to use DllImport. You will just include the header files you need. The dll will be managed so you can reference it from your c# application. Here is an example: Wrapping Around a Native C++ Class[^] Netting C++[^] Wrapping Unmanaged Classes Using Managed Extensions for C++[^] NativeWrapper: a tool for Native Interoperability[^]

                                Giorgi Dalakishvili #region signature my articles My blog[^] #endregion

                                A Offline
                                A Offline
                                Abydosgater
                                wrote on last edited by
                                #17

                                Thanks ill see if i can get in contact with him. Have had no luck myself. Also i dont have experience with managed c++.

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups