示例#1
0
        //user32.dll
        public static IntPtr GetWindow(uint pid, string strTitle)
        {
            IntPtr hWnd      = IntPtr.Zero;
            IntPtr lngProcId = IntPtr.Zero;;

            hWnd = User32API.GetDesktopWindow();
            hWnd = User32API.GetWindow(hWnd, GetWindowEnums.GW_CHILD);
            string str = string.Empty;

            while (hWnd != IntPtr.Zero)
            {
                str = User32API.GetWindowText(hWnd);

                if (str.IndexOf(strTitle) != -1)
                {
                    //Console.WriteLine(str);
                    User32API.GetWindowThreadProcessId(hWnd, ref lngProcId);
                    if ((uint)lngProcId == pid)
                    {
                        return(hWnd);
                    }
                }
                hWnd = User32API.GetWindow(hWnd, GetWindowEnums.GW_HWNDNEXT);
            }

            //MainWindowHandle

            return(IntPtr.Zero);
        }
示例#2
0
 //AppEnd=true,追加
 public static void SendString(IntPtr hWnd, string str, bool AppEnd)
 {
     //StringIterator
     if (str == null)
     {
         return;
     }
     byte[] bhr;// = new byte[2];
     //bhr = System.Text.Encoding.Default.GetBytes(str);
     if (!AppEnd)
     {
         User32API.SendMessage(hWnd, 0x000C, IntPtr.Zero, IntPtr.Zero);//WM_SETTEXT
     }
     for (int i = 0; i < str.Length; i++)
     {
         bhr = System.Text.Encoding.Default.GetBytes(str.Substring(i, 1));
         ushort sc = 0;
         for (int j = 0; j < bhr.GetLength(0); j++)
         {
             sc = (ushort)(sc * 256 + bhr[j]);
         }
         SendMessage(hWnd, 0x0286, sc, IntPtr.Zero);//WM_IME_CHAR
         System.Threading.Thread.Sleep(10);
     }
 }
示例#3
0
        public static bool IsPid(uint pid)
        {
            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(true);
                }
                hWnd = User32API.GetWindow(hWnd, GetWindowEnums.GW_HWNDNEXT);
            }
            return(false);
        }
示例#4
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);
        }
示例#5
0
        public static string SetPicPath(string strPictureDir, string strOrderNo)
        {
            string   strPD, strFileName;
            DateTime dt = DateTime.Now;

            strPD = string.Format("{0}{1:0000}_{2:00}\\{3:00}\\{4}\\", strPictureDir, dt.Year, dt.Month, dt.Day, strOrderNo);
            User32API.MakeSureDirectoryPathExists(strPD);
            strFileName = string.Format("{0}{1:00}{2:00}{3:00}.jpg", strPD, dt.Hour, dt.Minute, dt.Second);
            return(strFileName);
        }
示例#6
0
        public static void SendUnicode(ushort data)
        {
            INPUT[] input = new INPUT[2];
            input[0].Type            = (UInt32)InputType.INPUT_KEYBOARD;
            input[0].Data.ki.wVk     = 0;
            input[0].Data.ki.wScan   = data;
            input[0].Data.ki.dwFlags = 0x4;//KEYEVENTF_UNICODE;

            input[0].Type            = (UInt32)InputType.INPUT_KEYBOARD;
            input[1].Data.ki.wVk     = 0;
            input[1].Data.ki.wScan   = data;
            input[1].Data.ki.dwFlags = 0x2 | 0x4;//KEYEVENTF_UNICODE;
            //uint tt =(uint) Marshal.SizeOf(input[0]);
            User32API.SendInput(2, input, Marshal.SizeOf(input[0]) * 4);
            //User32API.SendInput(2, input, Marshal.SizeOf(input));
        }
示例#7
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);
 }