how to get handle or thread information c#

plastic refusal 1 Reputation point
2020-12-14T23:41:18.81+00:00

ok so after a lot of testing, two months ago the media control buttons would not work properly
i guess microsoft updated something recently so they work again

issuing the media control commands to the current main window does seem to get it into the right pool

i'll handle all the issues with movies & tv taking hostage of the interface and all that later
it's doing it blindly its obviously a $5 application but really - expecting people to make the $10 version?

history shows in terms of MS it takes 20 years -------- i'll be the first guy upgrading file explorer for instance
or the audio interface for sound themes - 20 years man
code is still there looks exactly the same, still has all the 100 problems and bugs

thanks for the handle stuff its easier to use process than enum at all apparently
though i still havent gotten to adjusting volume for individual apps ow.
ive done it succesfully i know how, the code is 10x longer than my app

though.

thanks again
deleted all 10 of the photos and explanations hope you saw them first

check me out at plastic-inc.com at some point in the future , but i cant send you a ticket that will renew in , i dunno 20 days
20 days with 20 day increments

favorites that reach out of the screen at you right --------------- its going into my buttons
long live corsair !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Microsoft Edge
Microsoft Edge
A Microsoft cross-platform web browser that provides privacy, learning, and accessibility tools.
2,161 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,364 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Timon Yang-MSFT 9,576 Reputation points
    2020-12-15T05:21:31.217+00:00

    Please try this code to get all the handlers based on the application name.

        public class WindowHandleInfo  
        {  
            private delegate bool EnumWindowProc(IntPtr hwnd, IntPtr lParam);  
      
            [DllImport("user32")]  
            [return: MarshalAs(UnmanagedType.Bool)]  
            private static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr lParam);  
      
            private IntPtr _MainHandle;  
      
            public WindowHandleInfo(IntPtr handle)  
            {  
                this._MainHandle = handle;  
            }  
      
            public List<IntPtr> GetAllChildHandles()  
            {  
                List<IntPtr> childHandles = new List<IntPtr>();  
      
                GCHandle gcChildhandlesList = GCHandle.Alloc(childHandles);  
                IntPtr pointerChildHandlesList = GCHandle.ToIntPtr(gcChildhandlesList);  
      
                try  
                {  
                    EnumWindowProc childProc = new EnumWindowProc(EnumWindow);  
                    EnumChildWindows(this._MainHandle, childProc, pointerChildHandlesList);  
                }  
                finally  
                {  
                    gcChildhandlesList.Free();  
                }  
      
                return childHandles;  
            }  
      
            private bool EnumWindow(IntPtr hWnd, IntPtr lParam)  
            {  
                GCHandle gcChildhandlesList = GCHandle.FromIntPtr(lParam);  
      
                if (gcChildhandlesList == null || gcChildhandlesList.Target == null)  
                {  
                    return false;  
                }  
      
                List<IntPtr> childHandles = gcChildhandlesList.Target as List<IntPtr>;  
                childHandles.Add(hWnd);  
      
                return true;  
            }  
        }  
    

    Use this class:

            [DllImport("user32.dll", EntryPoint = "FindWindowEx")]  
            public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);  
      
            static void Main(string[] args)  
            {  
                Process[] anotherApps = Process.GetProcessesByName("CHROME");  
                if (anotherApps.Length == 0) return;  
                if (anotherApps[0] != null)  
                {  
                    List<IntPtr> allChildWindows = new WindowHandleInfo(anotherApps[0].MainWindowHandle).GetAllChildHandles();  
                }  
            }  
    

    The code basically comes from here: How can I get the child windows of a window given its HWND?


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments