C#获取句柄

[DllImport("User32.dll", EntryPoint = "FindWindow")]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("User32.dll", EntryPoint = "FindWindowEx")]
        private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

上面是windowsapi函数     
mainwin = FindWindow("wndclass_desked_gsk", "Microsoft SQL Server Management Studio");
                IntPtr smyPtr = new IntPtr(0);
                smyPtr = FindWindowEx(mainwin, smyPtr, "GenericPane", "对象资源管理器");

smyptr是在主窗口Microsoft SQL Server Management Studio下的一个叫对象资源管理器的控件,我现在要获取这个控件就得一层层的对应下来

                IntPtr cwin = new IntPtr(0);
                cwin = FindWindowEx(smyPtr, cwin, "GenericPane", null);
                IntPtr myPtr = new IntPtr(0);
                myPtr = FindWindowEx(cwin, myPtr, "WindowsForms10.SysTreeView32.app.0.33c0d9d", null);  

这上面几句话是我想获取smyptr中的一个treeview32的控件句柄,可以利用spy++来打开进程管理找到对应从属关系,然后一层层的获取到。

你可能感兴趣的:(api,C#)