示例#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());
        }
示例#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());
        }
示例#3
0
        public static int GetWindowProcessID(IntPtr hWnd)
        {
            int procId;

            Api_User32.GetWindowThreadProcessId(hWnd, out procId);
            return(procId);
        }
示例#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());
        }
示例#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));
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
     }
 }
示例#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);
        }
示例#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);
            }
        }
示例#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);
        }
示例#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);
 }
示例#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);
        }
示例#16
0
 public static bool ShowCaret(IntPtr hWnd)
 {
     return(Api_User32.ShowCaret(hWnd));
 }
示例#17
0
 public static bool HideCaret(IntPtr hWnd)
 {
     return(Api_User32.HideCaret(hWnd));
 }
示例#18
0
 public static IntPtr FindWindow(string className, string windowName)
 {
     return(Api_User32.FindWindow(className, windowName));
 }
示例#19
0
 public static IntPtr FindWindowEx(IntPtr parentHandle, string className)
 {
     return(Api_User32.FindWindowEx(parentHandle, IntPtr.Zero, className, IntPtr.Zero));
 }
示例#20
0
 public static void ReleaseCursor(IntPtr hCursor)
 {
     Api_User32.DestroyCursor(hCursor);
 }
示例#21
0
 public static void SetCursor(IntPtr hCursor)
 {
     Api_User32.SetCursor(hCursor);
 }
示例#22
0
 public static IntPtr GetParent(IntPtr hWnd)
 {
     return(Api_User32.GetParent(hWnd));
 }
示例#23
0
 public static void ReleaseDeviceContext(HandleRef hWnd, IntPtr hDC)
 {
     Api_User32.ReleaseDC(hWnd, hDC);
 }
示例#24
0
 public static IntPtr GetDeviceContext(HandleRef hWnd)
 {
     return(Api_User32.GetDC(hWnd));
 }
示例#25
0
 public static void RedrawWindow(IntPtr hwnd, RedrawWindowFlags flags)
 {
     Api_User32.RedrawWindow(hwnd, IntPtr.Zero, IntPtr.Zero, (uint)flags);
 }
示例#26
0
 public static bool IsWindowVisible(IntPtr hWnd)
 {
     return(Api_User32.IsWindowVisible(hWnd));
 }
示例#27
0
 public static bool BlockInputOn()
 {
     return(Api_User32.BlockInput(true));
 }
示例#28
0
 public static IntPtr GetWindowFromPoint(Point pt)
 {
     return(Api_User32.WindowFromPoint(pt));
 }
示例#29
0
 public static bool BlockInputOff()
 {
     return(Api_User32.BlockInput(false));
 }
示例#30
0
 public static void SetFocus(IntPtr hWnd)
 {
     Api_User32.SetFocus(hWnd);
 }