Exemple #1
0
        //user32.dll
        public static IntPtr GetWindow(uint pid, bool IsWD)
        {
            IntPtr hWnd      = IntPtr.Zero;
            IntPtr lngProcId = IntPtr.Zero;;

            hWnd = User32API.GetDesktopWindow();
            hWnd = User32API.GetWindow(hWnd, GetWindowEnums.GW_CHILD);
            while (hWnd != IntPtr.Zero)
            {
                //Console.WriteLine(str);
                User32API.GetWindowThreadProcessId(hWnd, ref lngProcId);
                if ((uint)lngProcId == pid)
                {
                    if (IsWD)
                    {
                        if (!User32API.IsWindowVisible(hWnd))
                        {
                            hWnd = User32API.GetWindow(hWnd, GetWindowEnums.GW_HWNDNEXT);
                            continue;
                        }
                    }
                    return(hWnd);
                }
                hWnd = User32API.GetWindow(hWnd, GetWindowEnums.GW_HWNDNEXT);
            }
            return(IntPtr.Zero);
        }
Exemple #2
0
 //.net
 public static IntPtr GetIsWindow(string strProcessName)
 {
     if (strProcessName.IndexOf(".") > 0)
     {
         strProcessName = strProcessName.Substring(0, strProcessName.LastIndexOf("."));
     }
     Process[] ps = Process.GetProcesses();
     foreach (Process item in ps)
     {
         if (item.ProcessName.ToLower() == strProcessName.ToLower())
         {
             if (User32API.IsWindowVisible(item.MainWindowHandle))
             {
                 return(item.MainWindowHandle);
             }
         }
     }
     return(IntPtr.Zero);
 }