在做一个打开一个播放器让它自动最大化的那个东西,获取刚打开的那个播放器的句柄

解决方案 »

  1.   

    窗体对象.Handle不就可以了么。
    2L貌似很多帖子都是这句:“查了资料,想了很久,还是没能解答你的问题,不过还是帮你顶上,希望高手光临......”
      

  2.   

    或者findwindow来查询窗体句柄如果不适用就用EnumWindow来遍历窗体
      

  3.   

    用C# 干嘛要用Windows的APIC#不是提供了UIAutomaiton类么,这个就是专么用来自动化测试的,里面可以去操作其他窗体
      

  4.   

    调用API 代码这里 有兴趣可以看下 汗 没分结贴了。
    #region 打开指定的文件
            public static Process OpenFile(string filePath)
            {
                int num = 0;
                Process pro = null;
                try
                {
                    if (File.Exists(filePath))
                    {
                        pro = Process.Start(filePath);
                        while (num < 10)
                        {
                            num++;
                            Action action = new Action(delegate()
                            {
                                Thread.Sleep(500);
                                IntPtr ht = pro.MainWindowHandle;
                                ShowWindow(pro.MainWindowHandle, 3); //将窗口最大化
                                SetForegroundWindow(pro.MainWindowHandle); //如果没有ShowWindow,此方法不能设置最小化的窗口
                            });
                            action.BeginInvoke(null, null);
                        }
                    }
                }
                catch (Exception ex)
                {                throw;
                }
                return pro;
            }
            [DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)]
            public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
            [DllImport("user32.dll")]
            private static extern bool SetForegroundWindow(IntPtr hWnd);
        } 
            #endregion