Esempio n. 1
0
        public static string GetClassName(IntPtr hwnd, int maxLen)
        {
            StringBuilder sb = new StringBuilder(maxLen);

            Api_User32.GetClassName(hwnd, sb, sb.Capacity);
            return(sb.ToString());
        }
Esempio n. 2
0
        public static string GetWindowTitle(IntPtr hWnd, int maxLen)
        {
            StringBuilder sb = new StringBuilder(maxLen);

            Api_User32.GetWindowText(hWnd, sb, sb.Capacity);
            return(sb.ToString());
        }
Esempio n. 3
0
        public static int GetWindowProcessID(IntPtr hWnd)
        {
            int procId;

            Api_User32.GetWindowThreadProcessId(hWnd, out procId);
            return(procId);
        }
Esempio n. 4
0
        public static string SetTextContent(IntPtr hWnd)
        {
            StringBuilder sb = new StringBuilder();

            Api_User32.SendMessage(hWnd, (int)Win32Messages.WM_SETTEXT, (IntPtr)sb.Capacity, sb);
            return(sb.ToString());
        }
Esempio n. 5
0
        public static IntPtr CreateCursor(Bitmap xor, Bitmap and, int xHotspot, int yHotspot)
        {
            ImageConverter ic = new ImageConverter();

            byte[] bfrXor = (byte[])ic.ConvertTo(xor, typeof(byte[]));
            byte[] bfrAnd = (byte[])ic.ConvertTo(and, typeof(byte[]));
            return(Api_User32.CreateCursor(IntPtr.Zero, xHotspot, yHotspot, and.Width, and.Height, bfrAnd, bfrXor));
        }
Esempio n. 6
0
        public static IntPtr SendMessage(IntPtr hWnd, Win32Messages msg, int wParam, IntPtr lParam)
        {
            IntPtr retVal = Api_User32.SendMessage(hWnd, (int)msg, wParam, lParam);

            //if (retVal.ToInt32() > 0)
            //    throw new Win32Exception(retVal.ToInt32(), "An error occured while sending the window message.");
            return(retVal);
        }
Esempio n. 7
0
        public static WindowPlacement GetWindowPlacement(IntPtr hWnd)
        {
            WindowPlacement wplc = new WindowPlacement();

            if (!Api_User32.GetWindowPlacement(hWnd, ref wplc))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "An error occured trying to obtain window placement information.");
            }
            return(wplc);
        }
Esempio n. 8
0
        public static ScrollBarInfo GetScrollBarInfo(IntPtr hwnd, ScrollBarObjectID objId)
        {
            ScrollBarInfo info = new ScrollBarInfo();

            info.cbSize = Marshal.SizeOf(info);
            if (Api_User32.GetScrollBarInfo(hwnd, (uint)objId, ref info) != IntPtr.Zero)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "Unable to obtain scrollbar information.");
            }
            return(info);
        }
Esempio n. 9
0
        public static WindowInfo GetWindowInfo(IntPtr hwnd)
        {
            WindowInfo wnfo = new WindowInfo();

            wnfo.cbSize = Marshal.SizeOf(wnfo);
            if (!Api_User32.GetWindowInfo(hwnd, ref wnfo))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error(), "Unable to retrieve window information.");
            }
            return(wnfo);
        }
Esempio n. 10
0
 public static uint SendInput(INPUT[] inputs)
 {
     if (inputs.Length > 0)
     {
         return(Api_User32.SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(inputs[0])));
     }
     else
     {
         return(0);
     }
 }
Esempio n. 11
0
        public static List <string> GetListContent(IntPtr hWnd)
        {
            List <string> lst   = new List <string>();
            int           count = (int)Api_User32.SendMessage(hWnd, (int)Win32Messages.LB_GETCOUNT, IntPtr.Zero, null);

            for (int i = 0; i < count; i++)
            {
                StringBuilder sb = new StringBuilder();
                Api_User32.SendMessage(hWnd, Win32Const.WM_GETTEXT, (IntPtr)i, sb);
                lst.Add(sb.ToString());
            }
            return(lst);
        }
Esempio n. 12
0
        public static Rectangle GetClientRect(IntPtr hWnd)
        {
            RECT bnds = new RECT();

            if (Api_User32.GetClientRect(hWnd, ref bnds))
            {
                return(new Rectangle(bnds.left, bnds.top, bnds.Width, bnds.Height));
            }
            else
            {
                return(Rectangle.Empty);
            }
        }
Esempio n. 13
0
        //***************************************************************************
        // USER32 - Input
        public static void SendKeyPress(VK key)
        {
            INPUT[] inp = new INPUT[1];
            inp[0].type           = Win32Const.INPUT_KEYBOARD;
            inp[0].ki.wScan       = 0;
            inp[0].ki.dwFlags     = 0;
            inp[0].ki.time        = 0;
            inp[0].ki.wVk         = (ushort)key;
            inp[0].ki.dwExtraInfo = Api_User32.GetMessageExtraInfo();
            Win32.SendInput(inp);

            // And now send the key release.
            inp[0].ki.dwFlags = Win32Const.KEYEVENTF_KEYUP;
            Win32.SendInput(inp);
        }
Esempio n. 14
0
 public static void SetMousePosition(int dx, int dy, bool relative)
 {
     INPUT[] inp = new INPUT[1];
     inp[0].type = Win32Const.INPUT_MOUSE;
     if (relative)
     {
         inp[0].mi.dwFlags = Win32Const.MOUSEEVENTF_MOVE;
     }
     else
     {
         inp[0].mi.dwFlags = Win32Const.MOUSEEVENTF_MOVE | Win32Const.MOUSEEVENTF_ABSOLUTE;
     }
     inp[0].mi.dx          = dx;
     inp[0].mi.dy          = dy;
     inp[0].mi.mouseData   = 0;
     inp[0].mi.time        = 0;
     inp[0].mi.dwExtraInfo = Api_User32.GetMessageExtraInfo();
     Win32.SendInput(inp);
 }
Esempio n. 15
0
        public static List <IntPtr> GetChildWindows(IntPtr hwndParent)
        {
            List <IntPtr> result     = new List <IntPtr>();
            GCHandle      listHandle = GCHandle.Alloc(result);

            try
            {
                Win32Callback childProc = new Win32Callback(EnumWindow);
                Api_User32.EnumChildWindows(hwndParent, childProc, GCHandle.ToIntPtr(listHandle));
            }
            finally
            {
                if (listHandle.IsAllocated)
                {
                    listHandle.Free();
                }
            }
            return(result);
        }
Esempio n. 16
0
 public static bool ShowCaret(IntPtr hWnd)
 {
     return(Api_User32.ShowCaret(hWnd));
 }
Esempio n. 17
0
 public static bool HideCaret(IntPtr hWnd)
 {
     return(Api_User32.HideCaret(hWnd));
 }
Esempio n. 18
0
 public static IntPtr FindWindow(string className, string windowName)
 {
     return(Api_User32.FindWindow(className, windowName));
 }
Esempio n. 19
0
 public static IntPtr FindWindowEx(IntPtr parentHandle, string className)
 {
     return(Api_User32.FindWindowEx(parentHandle, IntPtr.Zero, className, IntPtr.Zero));
 }
Esempio n. 20
0
 public static void ReleaseCursor(IntPtr hCursor)
 {
     Api_User32.DestroyCursor(hCursor);
 }
Esempio n. 21
0
 public static void SetCursor(IntPtr hCursor)
 {
     Api_User32.SetCursor(hCursor);
 }
Esempio n. 22
0
 public static IntPtr GetParent(IntPtr hWnd)
 {
     return(Api_User32.GetParent(hWnd));
 }
Esempio n. 23
0
 public static void ReleaseDeviceContext(HandleRef hWnd, IntPtr hDC)
 {
     Api_User32.ReleaseDC(hWnd, hDC);
 }
Esempio n. 24
0
 public static IntPtr GetDeviceContext(HandleRef hWnd)
 {
     return(Api_User32.GetDC(hWnd));
 }
Esempio n. 25
0
 public static void RedrawWindow(IntPtr hwnd, RedrawWindowFlags flags)
 {
     Api_User32.RedrawWindow(hwnd, IntPtr.Zero, IntPtr.Zero, (uint)flags);
 }
Esempio n. 26
0
 public static bool IsWindowVisible(IntPtr hWnd)
 {
     return(Api_User32.IsWindowVisible(hWnd));
 }
Esempio n. 27
0
 public static bool BlockInputOn()
 {
     return(Api_User32.BlockInput(true));
 }
Esempio n. 28
0
 public static IntPtr GetWindowFromPoint(Point pt)
 {
     return(Api_User32.WindowFromPoint(pt));
 }
Esempio n. 29
0
 public static bool BlockInputOff()
 {
     return(Api_User32.BlockInput(false));
 }
Esempio n. 30
0
 public static void SetFocus(IntPtr hWnd)
 {
     Api_User32.SetFocus(hWnd);
 }