private Dictionary<string, int> GetWindowSize(string processName)
		{
			IntPtr handle = IntPtr.Zero;
			foreach (Process process in Process.GetProcesses())
			{


				if (process.MainWindowTitle.IndexOf(processName) >= 0)
				{
					handle = process.MainWindowHandle;
				}
			}
			if (handle == IntPtr.Zero)
				throw new WindowNotFoundException();

			RECT rect = new RECT(); POINT point = new POINT();
			GetClientRect(handle, out rect);
			ClientToScreen(handle, out point);
			var result = new Dictionary<string, int>();
			result.Add("width", (int)(rect.right - rect.left));
			result.Add("height", (int)(rect.bottom - rect.top));
			result.Add("x", (int)point.x);
			result.Add("y", (int)point.y);
			return result;
		}
Beispiel #2
0
        public MainAppContext()
        {
            NotifyIcon trayIcon = new NotifyIcon() { Icon = Properties.Resources.TopMost, Text = "MakeTopMost", Visible = true };
            trayIcon.Click += (s, e) =>
                {
                    if (this.lastMenu != null)
                    {
                        this.lastMenu.Dispose();
                    }

                    this.lastMenu = this.CreateMenu();

                    NativeWindow trayIconWindow = (NativeWindow)typeof(NotifyIcon).GetField("window", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(trayIcon);
                    POINT cursorLocation = new POINT(); NativeMethods.GetCursorPos(out cursorLocation);
                    SystemWindow.ForegroundWindow = new SystemWindow(trayIconWindow.Handle);
                    NativeMethods.TrackPopupMenuEx(new HandleRef(this.lastMenu, this.lastMenu.Handle), 72, cursorLocation.X, cursorLocation.Y, new HandleRef(trayIconWindow, trayIconWindow.Handle), IntPtr.Zero);
                    NativeMethods.PostMessage(new HandleRef(trayIconWindow, trayIconWindow.Handle), 0, IntPtr.Zero, IntPtr.Zero);
                };

            this.ThreadExit += (s, e) =>
                {
                    trayIcon.Dispose();
                    if (this.lastMenu != null)
                    {
                        this.lastMenu.Dispose();
                    }
                };
        }
        private int HandleMouseEvent(int inEvtDispId, IHTMLEventObj pIEventObj)
        {
            // WinLive 160252: MSHTML throws a COMException with HRESULT 0x8000FFFF (E_UNEXPECTED) when calling
            // IHTMLPaintSite.TransformGlobalToLocal if the table has no height.
            IHTMLElement tableElement = (IHTMLElement)_table;
            if (tableElement.offsetHeight <= 0 || tableElement.offsetWidth <= 0)
            {
                return HRESULT.S_FALSE;
            }

            // compute the element local coordinates of the point
            POINT clientMouseLocation = new POINT();
            clientMouseLocation.x = pIEventObj.clientX;
            clientMouseLocation.y = pIEventObj.clientY;
            POINT localMouseLocation = new POINT();
            _paintSite.TransformGlobalToLocal(clientMouseLocation, ref localMouseLocation);

            // determine if the point is within our bounds
            int tableWidth = tableElement.offsetWidth + 4; // extra padding for mouse handling at right edge
            Rectangle elementBounds = new Rectangle(-1, -1, tableWidth, tableElement.offsetHeight + 1);
            bool mouseInElement = elementBounds.Contains(localMouseLocation.x, localMouseLocation.y);

            if (mouseInElement || _sizingOperation.InProgress)
            {
                // create args
                TableColumnMouseEventArgs mouseEventArgs = new TableColumnMouseEventArgs(
                    new Point(clientMouseLocation.x, clientMouseLocation.y),
                    new Point(localMouseLocation.x, localMouseLocation.y));

                // fire the event
                switch (inEvtDispId)
                {
                    case DISPID_HTMLELEMENTEVENTS2.ONMOUSEMOVE:
                        OnMouseMove(mouseEventArgs);
                        break;
                    case DISPID_HTMLELEMENTEVENTS2.ONMOUSEDOWN:
                        OnMouseDown(mouseEventArgs);
                        break;
                    case DISPID_HTMLELEMENTEVENTS2.ONMOUSEUP:
                        OnMouseUp(mouseEventArgs);
                        break;
                    default:
                        Trace.Fail("unexpected event id");
                        break;
                }

                // indicate whether we should mask the event from the editor
                return mouseEventArgs.Handled ? HRESULT.S_OK : HRESULT.S_FALSE;

            }
            else
            {
                // if the mouse is not inside the element the end sizing
                _sizingOperation.EndSizing();
            }

            // event not handled
            return HRESULT.S_FALSE;
        }
Beispiel #4
0
        public static System.Drawing.Point UpperLeftCornerOfWindow(IntPtr hWnd)
        {
            Interop.POINT p = new POINT(0, 0);
            ScreenToClient(hWnd, ref p);

            // Make these positive
            return new Point(p.X * -1, p.Y * -1);
        }
        public static IntPtr WindowFormPoint(System.Drawing.Point point)
        {
            var p = new POINT();
            p.x = point.X;
            p.y = point.Y;

            return WindowFromPoint(p);
        }
Beispiel #6
0
        public static string GetWindowTextUnderCursor()
        {
            POINT pointCursor = new POINT();

            if (!(GetCursorPos(out pointCursor))) return string.Empty;

            return GetWindowText(pointCursor);
        }
 public static IntPtr GetCurrentMonitor()
 {
     POINT point = new POINT();
     if (!GetCursorPos(out point))
     {
         throw new Win32Exception(Marshal.GetLastWin32Error());
     }
     return MonitorFromPoint(point, MONITOR_DEFAULTTONEAREST);
 }
 /// <summary>
 /// Clients to screen.
 /// </summary>
 /// <param name="handle">A handle.</param>
 /// <param name="point">A point.</param>
 /// <returns></returns>
 public static POINT ClientToScreen(WindowHandle handle, POINT point)
 {
     POINT point1 = point;
     if (!ClientToScreen(handle, ref point1))
     {
         throw new Win32Exception();
     }
     return point1;
 }
 public Point TransformGlobalToLocal(Point ptGlobal)
 {
     POINT pointLocal = new POINT();
     POINT pointGlobal = new POINT();
     pointGlobal.x = ptGlobal.X;
     pointGlobal.y = ptGlobal.Y;
     HTMLPaintSite.TransformGlobalToLocal(pointGlobal, ref pointLocal);
     return new Point(pointLocal.x, pointLocal.y);
 }
Beispiel #10
0
 public static extern int UpdateLayeredWindow(IntPtr hWnd, 
     IntPtr hdcDst,
     ref POINT pptDst, 
     ref SIZE psize,
     IntPtr hdcSrc, 
     ref POINT pptSrc, 
     uint crKey, 
     ref BLENDFUNCTION pblend, 
     uint dwFlags);
		//********************************
		//using DllImports from DLL_User32
		//********************************
		public static Point NativeScreenToClient(IntPtr window, Point originalPoint)
		{
			POINT pOINT = new POINT(originalPoint.X, originalPoint.Y);
			if (ScreenToClient(window, ref pOINT))
			{
				return new Point(pOINT.x, pOINT.y);
			}
			return Point.Empty;
		}	
Beispiel #12
0
 /// <summary>
 /// Функция находит дочернее окно в данной точке.
 /// </summary>
 /// <param name="pt">Точка в абсолютных координатах</param>
 /// <returns>Возвращает дескриптор окна</returns>
 public IntPtr FindWindowAtPos(System.Drawing.Point pt)
 {
     FindedHandle = IntPtr.Zero;
       POINT APIpt = new POINT();
       APIpt.X = pt.X;
       APIpt.Y = pt.Y;
       GCHandle GCPoint = GCHandle.Alloc(APIpt);
       EnumWindowsProc cbFinder = new EnumWindowsProc(FindNextLevelWindowAtPos);
       EnumChildWindows(ParentHandle,FindNextLevelWindowAtPos, GCHandle.ToIntPtr(GCPoint));
       return FindedHandle;
 }
Beispiel #13
0
        public MouseUpEventArgs(MouseButtons button, POINT pt, IntPtr hWnd)
        {
            Button = button;
            ScreenPoint = new Point(pt.x, pt.y);

            if (hWnd == IntPtr.Zero)
                return;

            WindowHandle = hWnd;
            PInvoke.ScreenToClient(hWnd, ref pt);
            WindowPoint = new Point(pt.x, pt.y);
        }
        /// <summary>
        ///     Transform a point from "screen" coordinate space into the
        ///     "client" coordinate space of the window.
        /// </summary>
        public static Point TransformScreenToClient(this HwndSource hwndSource, Point point)
        {
            HWND hwnd = new HWND(hwndSource.Handle);

            POINT pt = new POINT();
            pt.x = (int)point.X;
            pt.y = (int)point.Y;

            NativeMethods.ScreenToClient(hwnd, ref pt);

            return new Point(pt.x, pt.y);
        }
Beispiel #15
0
        public static void SetPosition(int x, int y)
        {
            POINT pt = new POINT(x, y);

            if (m_windowHandle != IntPtr.Zero)
            {
                unsafe
                {
                    ClientToScreen(m_windowHandle.ToPointer(), &pt);
                }
            }
            SetCursorPos(pt.X, pt.Y);
        }
 /// <summary>
 /// Clients to screen.
 /// </summary>
 /// <param name="window">A window.</param>
 /// <param name="point">A point.</param>
 /// <returns></returns>
 public static POINT ClientToScreen(IWin32Window window, POINT point)
 {
     if (window == null)
     {
         throw new ArgumentNullException("window");
     }
     POINT point1 = point;
     if (!ClientToScreen(new WindowHandle(window), ref point1))
     {
         throw new Win32Exception();
     }
     return point1;
 }
	void WndOnMouseDown()
	{
		var hwnd = FindWindow(null, "CooldogAssistant");

		if (hwnd != IntPtr.Zero)
		{
			POINT p;
			GetCursorPos(out p);
			p.X -= Screen.width / 2;
			p.Y -= Screen.width / 4;

			DragStart = p;
			Dragging = false;
		}
	}
Beispiel #18
0
		public void EqualityTest()
		{
			POINT p = new POINT(20, 40);
			POINT p2 = new POINT(20, 40);
			Point p3 = new Point(20, 40);

			Assert.AreEqual(p, p2);
			Assert.AreEqual(p, p3);

			Point p4 = new Point(30, 30);
			POINT p5 = new POINT(50, 60);

			Assert.AreNotEqual(p, p4);
			Assert.AreNotEqual(p, p5);
		}
Beispiel #19
0
        public void SetView(Bitmap newView, int newOpacity)
        {
            if (newView == null) return;

            if (newView.PixelFormat != PixelFormat.Format32bppArgb)
                throw new ApplicationException("The bitmap must be 32ppp with alpha-channel.");

            View = newView;
            Opacity = newOpacity%256;

            IntPtr screenDc = User.GetDC(IntPtr.Zero);
            IntPtr memDc = GDI.CreateCompatibleDC(screenDc);
            IntPtr hBitmap = IntPtr.Zero;
            IntPtr oldBitmap = IntPtr.Zero;

            try
            {
                hBitmap = newView.GetHbitmap(Color.FromArgb(0));
                oldBitmap = GDI.SelectObject(memDc, hBitmap);

                var size = new SIZE {cx = newView.Width, cy = newView.Height};
                var pointSource = new POINT {x = 0, y = 0};
                var topPos = new POINT {x = Left, y = Top};
                var blend = new User.BLENDFUNCTION
                            {
                                BlendOp = User.AC_SRC_OVER,
                                BlendFlags = 0,
                                SourceConstantAlpha = (byte) newOpacity,
                                AlphaFormat = User.AC_SRC_ALPHA
                            };

                User.UpdateLayeredWindow(Handle, screenDc, ref topPos,
                                         ref size, memDc, ref pointSource,
                                         0,
                                         ref blend, User.ULW_ALPHA);
            }
            finally
            {
                User.ReleaseDC(IntPtr.Zero, screenDc);
                if (hBitmap != IntPtr.Zero)
                {
                    GDI.SelectObject(memDc, oldBitmap);
                    GDI.DeleteObject(hBitmap);
                }
                GDI.DeleteDC(memDc);
            }
        }
		static public void MouseMoveToPointInClientRect(
			IntPtr WindowHandle,
			Vektor2DInt DestinationPointInClientRect,
			out POINT DestinationPointInScreen)
		{
			DestinationPointInScreen = DestinationPointInClientRect.AsWindowsPoint();

			// get screen coordinates
			BotEngine.WinApi.User32.ClientToScreen(WindowHandle, ref DestinationPointInScreen);

			var lParam = (IntPtr)((((int)DestinationPointInClientRect.B) << 16) | ((int)DestinationPointInClientRect.A));
			var wParam = IntPtr.Zero;

			BotEngine.WinApi.User32.SetCursorPos(DestinationPointInScreen.x, DestinationPointInScreen.y);

			BotEngine.WinApi.User32.SendMessage(WindowHandle, (uint)SictMessageTyp.WM_MOUSEMOVE, wParam, lParam);
		}
Beispiel #21
0
        public void SetIMEWindowLocation(int x, int y)
        {
            POINT p = new POINT();
            p.x = x;
            p.y = y;

            COMPOSITIONFORM lParam = new COMPOSITIONFORM();
            lParam.dwStyle = CFS_POINT;
            lParam.ptCurrentPos = p;
            lParam.rcArea = new RECT();

            int i = SendMessage(
                        hIMEWnd,
                        WM_IME_CONTROL,
                        IMC_SETCOMPOSITIONWINDOW,
                        lParam
                        );
        }
        /// <summary>
        ///     Transform a rectangle from the "client" coordinate space of the
        ///     window into the "screen" coordinate space.
        /// </summary>
        public static Rect TransformClientToScreen(this HwndSource hwndSource, Rect rect)
        {
            HWND hwnd = new HWND(hwndSource.Handle);

            POINT ptUpperLeft = new POINT();
            ptUpperLeft.x = (int)rect.Left;
            ptUpperLeft.y = (int)rect.Top;

            NativeMethods.ClientToScreen(hwnd, ref ptUpperLeft);

            POINT ptLowerRight = new POINT();
            ptLowerRight.x = (int)rect.Right;
            ptLowerRight.y = (int)rect.Bottom;

            NativeMethods.ClientToScreen(hwnd, ref ptLowerRight);

            return new Rect(ptUpperLeft.x, ptUpperLeft.y, ptLowerRight.x - ptUpperLeft.x, ptLowerRight.y - ptUpperLeft.y);
        }
        /// <summary>
        ///     Aligns the RedirectedWindow such that the specified client
        ///     coordinate is aligned with the specified screen coordinate.
        /// </summary>
        public void AlignClientAndScreen(int xClient, int yClient, int xScreen, int yScreen)
        {
            POINT pt = new POINT(xClient, yClient);
            NativeMethods.ClientToScreen(Handle, ref pt);

            int dx = xScreen - pt.x;
            int dy = yScreen - pt.y;

            RECT rcWindow = new RECT();
            NativeMethods.GetWindowRect(Handle, ref rcWindow);

            NativeMethods.SetWindowPos(
                Handle,
                HWND.NULL,
                rcWindow.left + dx,
                rcWindow.top + dy,
                0,
                0,
                SWP.NOSIZE | SWP.NOZORDER | SWP.NOACTIVATE);
        }
        /// <summary>
        /// Indicates whether a drop can be accepted, and, if so, the effect of the drop.
        /// </summary>
        /// <param name="pDataObj">A pointer to the IDataObject interface on the data object. This data object contains the data being transferred in the drag-and-drop operation. If the drop occurs, this data object will be incorporated into the target.</param>
        /// <param name="grfKeyState">The current state of the keyboard modifier keys on the keyboard. Possible values can be a combination of any of the flags MK_CONTROL, MK_SHIFT, MK_ALT, MK_BUTTON, MK_LBUTTON, MK_MBUTTON, and MK_RBUTTON.</param>
        /// <param name="pt">A POINTL structure containing the current cursor coordinates in screen coordinates.</param>
        /// <param name="pdwEffect">On input, pointer to the value of the pdwEffect parameter of the DoDragDrop function. On return, must contain one of the DROPEFFECT flags, which indicates what the result of the drop operation would be.</param>
        /// <returns>
        /// This method returns S_OK on success.
        /// </returns>
        int IDropTarget.DragEnter(IDataObject pDataObj, uint grfKeyState, POINT pt, ref uint pdwEffect)
        {
            //  DebugLog this key event.
            Log(string.Format("Drag Enter for item {0}", SelectedItemPath));

            //  Get the drag items.
            try
            {
                dragItems = pDataObj.GetFileList();
            }
            catch (Exception exception)
            {
                //  DebugLog the error.
                LogError("An exception occured when getting the file list from the data object.", exception);
                return WinError.E_UNEXPECTED;
            }

            //  Create drag event args, which store the provided parameters.
            var dragEventArgs = new DragEventArgs(null, (int) grfKeyState, pt.X, pt.Y, (DragDropEffects) pdwEffect, DragDropEffects.None);

            try
            {
                //  Call the main drag enter function.
                DragEnter(dragEventArgs);
            }
            catch (Exception exception)
            {
                //  DebugLog the exception.
                LogError("An exception occured during a drag enter event.", exception);

                //  Don't allow any drag effect.
                dragEventArgs.Effect = DragDropEffects.None;
            }

            //  Set the effect.
            pdwEffect = (uint)dragEventArgs.Effect;

            //  Return success.
            return WinError.S_OK;
        }
Beispiel #25
0
        public void Execute(IScreenParser parser)
        {
            POINT targetPoint = new POINT(parser.GetXCoord(Target.X) + 25, parser.GetYCoord(Target.Y) + 25);
            User32Api.SetCursorPos(targetPoint.X, targetPoint.Y);

            switch (Move)
            {
                case MoveTypes.DoubleClick:
                    User32Api.MouseDoubleClick(targetPoint);
                    break;
                case MoveTypes.SetFlag:
                    if (Target.State == BlockState.Flag)
                        return;
                    else if (Target.UserGuess)
                        User32Api.MouseRightClick(targetPoint);
                    User32Api.MouseRightClick(targetPoint);
                    break;
                case MoveTypes.SetClear:
                    User32Api.MouseClick(targetPoint);
                    break;
            }
        }
Beispiel #26
0
        public void SelectBitmap(Bitmap bitmap, int opacity = 255)
        {
            if (bitmap.PixelFormat != PixelFormat.Format32bppArgb)
            {
                throw new ApplicationException("The bitmap must be 32bpp with alpha-channel.");
            }

            IntPtr screenDc = NativeMethods.GetDC(IntPtr.Zero);
            IntPtr memDc = NativeMethods.CreateCompatibleDC(screenDc);
            IntPtr hBitmap = IntPtr.Zero;
            IntPtr hOldBitmap = IntPtr.Zero;

            try
            {
                hBitmap = bitmap.GetHbitmap(Color.FromArgb(0));
                hOldBitmap = NativeMethods.SelectObject(memDc, hBitmap);

                SIZE newSize = new SIZE(bitmap.Width, bitmap.Height);
                POINT sourceLocation = new POINT(0, 0);
                POINT newLocation = new POINT(Left, Top);
                BLENDFUNCTION blend = new BLENDFUNCTION();
                blend.BlendOp = NativeMethods.AC_SRC_OVER;
                blend.BlendFlags = 0;
                blend.SourceConstantAlpha = (byte)opacity;
                blend.AlphaFormat = NativeMethods.AC_SRC_ALPHA;

                NativeMethods.UpdateLayeredWindow(Handle, screenDc, ref newLocation, ref newSize, memDc, ref sourceLocation, 0, ref blend, NativeMethods.ULW_ALPHA);
            }
            finally
            {
                NativeMethods.ReleaseDC(IntPtr.Zero, screenDc);
                if (hBitmap != IntPtr.Zero)
                {
                    NativeMethods.SelectObject(memDc, hOldBitmap);
                    NativeMethods.DeleteObject(hBitmap);
                }
                NativeMethods.DeleteDC(memDc);
            }
        }
        public void DrawBitmap(Bitmap bmp, byte opacity)
        {
            IntPtr hBitmap = IntPtr.Zero;
            IntPtr oldBitmap = IntPtr.Zero;
            IntPtr screenDc = NativeMethods.GetDC(IntPtr.Zero);
            IntPtr memDc = NativeMethods.CreateCompatibleDC(screenDc);

            try
            {
                hBitmap = bmp.GetHbitmap(Color.FromArgb(0));
                oldBitmap = NativeMethods.SelectObject(memDc, hBitmap);
                SIZE size = new SIZE(bmp.Width, bmp.Height);
                POINT pointSource = new POINT(this.Left, this.Top);
                POINT topPos = new POINT(0, 0);
                BLENDFUNCTION blend;
                blend.BlendOp = 0;
                blend.BlendFlags = 0;
                blend.SourceConstantAlpha = byte.MaxValue;
                blend.AlphaFormat = 1;
                NativeMethods.UpdateLayeredWindow(this.Handle, screenDc, ref topPos, ref size, memDc, ref pointSource, 0, ref blend, 2);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                NativeMethods.ReleaseDC(IntPtr.Zero, screenDc);

                if (hBitmap != IntPtr.Zero)
                {
                    NativeMethods.SelectObject(memDc, oldBitmap);
                    NativeMethods.DeleteObject(hBitmap);
                }

                NativeMethods.DeleteDC(memDc);
            }
        }
Beispiel #28
0
 private bool PointInCellRect(POINT aPt)
 {
     return(HC.PtInRect(HC.Bounds(0, 0, Width, FCellHeight), aPt));
 }
Beispiel #29
0
 public void CopyFrom(POINT source)
 {
     X = source.X;
     Y = source.Y;
 }
Beispiel #30
0
 public static extern bool ClientToScreen(IntPtr hWnd, ref POINT point);
 public static extern bool GetCursorPos(out POINT pt);
Beispiel #32
0
 private static extern IntPtr MonitorFromPoint(POINT pt, MonitorOptions dwFlags);
Beispiel #33
0
 internal static extern IntPtr WindowFromPoint(POINT pt);
Beispiel #34
0
 public static extern bool ScreenToClient(IntPtr hWnd, ref POINT lpPoint);
Beispiel #35
0
 static extern bool ClientToScreen(IntPtr hWnd, ref POINT lpPoint);
Beispiel #36
0
 private static extern IntPtr WindowFromPoint(POINT pt);
Beispiel #37
0
        public static void CaretThreadRun()
        {
            uint processId;
            bool attachedToConsole = false;

            while (!caretThreadStop)
            {
                lock (caretMutex)
                {
                    Monitor.Wait(caretMutex); //wait for the pulse
                    try
                    {
                        if (caretThreadStop)
                        {
                            break;
                        }
                        caretPoint = Point.Empty;
                        IntPtr activeWindow  = GetForegroundWindow();
                        uint   otherThreadId = GetWindowThreadProcessId(activeWindow, out processId);
                        if (attachedToConsole && processId == consoleProcessId)
                        {
                            //give caret position from winhook
                            caretPoint.X = consoleCaretX * consoleCharWidth;
                            caretPoint.Y = consoleCaretY * consoleCharHeight;
                            POINT p = caretPoint;
                            ClientToScreen(activeWindow, ref p);
                            caretPoint = p;
                        }
                        else
                        {
                            if (attachedToConsole)
                            {
                                try
                                {
                                    //detach and unhook
                                    UnhookWinEvent(caretEventHook);
                                    //FreeConsole();
                                }
                                finally
                                {
                                    caretEventHook    = IntPtr.Zero;
                                    consoleProcessId  = 0;
                                    attachedToConsole = false;
                                }
                            }
                            //begin processing expecting standard window
                            uint myThreadId = GetCurrentThreadId();
                            if (otherThreadId != myThreadId)
                            {
                                if (AttachThreadInput(otherThreadId, myThreadId, true)) //if attach success
                                {
                                    try
                                    {
                                        POINT p;
                                        if (GetCaretPos(out p))     //if got caret
                                        {
                                            if (p.X > 0 || p.Y > 0) //if valid point
                                            {
                                                IntPtr focused = GetFocus();
                                                if (focused != IntPtr.Zero)             //if focus control found
                                                {
                                                    if (ClientToScreen(focused, ref p)) //if convert success
                                                    {
                                                        if (p.X > 0 || p.Y > 0)         //if valid point
                                                        {
                                                            caretPoint = p;
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                //attempt attach to console
                                                //if (AttachConsole(processId))
                                                {
                                                    //sweet, we got a console, lets hook into it
                                                    //and we'll get events next time...
                                                    consoleProcessId        = processId;
                                                    createWinEventProxyFlag = true;
                                                    //make the message loop thread call this...
                                                    //yucky code!
                                                    Monitor.Pulse(caretMutex);
                                                    Monitor.Wait(caretMutex);
                                                    attachedToConsole = true;
                                                }
                                            }
                                        }
                                    }
                                    finally
                                    {
                                        AttachThreadInput(otherThreadId, myThreadId, false);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
#if (DEBUG)
                        Debugger.Break();
                        //MessageBox.Show("ERROR: " + ex.Message + Environment.NewLine + ex.StackTrace);
#endif
                    }
                    finally
                    {
                        Monitor.Pulse(caretMutex); //pulse back
                    }
                }
            }
        }
Beispiel #38
0
 static extern bool GetCaretPos(out POINT lpPoint);
Beispiel #39
0
 internal static extern IntPtr MonitorFromPoint(POINT pt, int dwFlags);
 public void DragOver(MK grfKeyState, POINT pt, ref OpenLiveWriter.Interop.Com.DROPEFFECT pdwEffect)
 {
     _contentEditorSite.DragOver(grfKeyState, pt, ref pdwEffect);
 }
Beispiel #41
0
 public static extern IntPtr MonitorFromPoint(POINT pt, MONITOR dwFlags);
Beispiel #42
0
        private unsafe Bitmap GetCaptureBitmap(HWND hWnd)
        {
            Bitmap bitmap    = null;
            HWND   zero      = new HWND(0);
            HDC    desktopDC = new HDC(IntPtr.Zero);
            HDC    memoryDC  = new HDC(IntPtr.Zero);

            try
            {
                var result = PInvoke.GetClientRect(hWnd, out RECT rect);

                if (!result)
                {
                    throw new NullReferenceException($"指定したハンドルのウィンドウ({hWnd})を発見することができませんでした。");
                }

                POINT point     = new POINT();
                var   mapResult = PInvoke.MapWindowPoints(hWnd, zero, &point, 2);

                if (mapResult == 0)
                {
                    throw new NullReferenceException($"指定したハンドルのウィンドウ({hWnd})の座標空間の変換に失敗しました。");
                }

                rect.left   = point.x;
                rect.top    = point.y;
                rect.right  = rect.right + point.x;
                rect.bottom = rect.bottom + point.y;

                var tempRect = rect;

                desktopDC = PInvoke.GetWindowDC(zero); // デスクトップの HDC を取得

                var header = new BITMAPINFOHEADER()
                {
                    biSize        = (uint)Marshal.SizeOf(typeof(BITMAPINFOHEADER)),
                    biWidth       = tempRect.right - rect.left,
                    biHeight      = tempRect.bottom - rect.top,
                    biPlanes      = 1,
                    biCompression = 0, // BitmapCompressionMode.BI_RGB = 0
                    biBitCount    = 24,
                };

                var info = new BITMAPINFO
                {
                    bmiHeader = header,
                };

                void **bits = null;

                HBITMAP hBitmap = PInvoke.CreateDIBSection(desktopDC, &info, DIB_USAGE.DIB_RGB_COLORS, bits, new HANDLE(IntPtr.Zero), 0);

                memoryDC = PInvoke.CreateCompatibleDC(desktopDC);

                var phBitMap = PInvoke.SelectObject(memoryDC, new HGDIOBJ(hBitmap));

                PInvoke.BitBlt(memoryDC, 0, 0, header.biWidth, header.biHeight, desktopDC, rect.left, rect.top, ROP_CODE.SRCCOPY);
                PInvoke.SelectObject(memoryDC, phBitMap);

                bitmap = Bitmap.FromHbitmap(hBitmap, IntPtr.Zero);
            }
            finally
            {
                if (desktopDC.Value != IntPtr.Zero)
                {
                    PInvoke.ReleaseDC(zero, desktopDC);
                }

                if (memoryDC.Value != IntPtr.Zero)
                {
                    PInvoke.ReleaseDC(hWnd, memoryDC);
                }
            }

            return(bitmap);
        }
Beispiel #43
0
    void _MouseInfo()
    {
        //using var p1 = perf.local();
        if (!this.IsVisible)
        {
            return;
        }

        var p = mouse.xy;

        if (p == _prevXY && ++_prevCounter < 4)
        {
            return;
        }
        _prevCounter = 0;                                                         //use less CPU. c and wName rarely change when same p.
        var c = wnd.fromXY(p);
        //p1.Next();
        var    w     = c.Window;
        string wName = w.Name;

        if (p == _prevXY && c == _prevWnd && wName == _prevWndName)
        {
            return;
        }
        _prevXY      = p;
        _prevWnd     = c;
        _prevWndName = wName;

        //p1.Next();
        using (new StringBuilder_(out var b, 1000)) {
            var cn = w.ClassName;
            if (cn != null)
            {
                var pc = p; w.MapScreenToClient(ref pc);
                b.AppendFormat("<b>xy</b> {0,5} {1,5}  .  <b>window xy</b> {2,5} {3,5}  .  <b>program</b>  {4}",
                               p.x, p.y, pc.x, pc.y, w.ProgramName?.Escape());
                if (c.UacAccessDenied)
                {
                    b.Append(" <c red>(admin)<>");
                }
                b.Append("\r\n<b>Window   ");
                var name = wName?.Escape(200); if (!name.NE())
                {
                    b.AppendFormat("name</b>  {0}  .  <b>", name);
                }
                b.Append("cn</b>  ").Append(cn.Escape());
                if (c != w)
                {
                    b.AppendFormat("\r\n<b>Control   id</b>  {0}  .  <b>cn</b>  {1}",
                                   c.ControlId, c.ClassName?.Escape());
                    var ct = c.Name;
                    if (!ct.NE())
                    {
                        b.Append("  .  <b>name</b>  ").Append(ct.Escape(200));
                    }
                }
                else if (cn == "#32768")
                {
                    var m = MenuItemInfo.FromXY(p, w, 50);
                    if (m != null)
                    {
                        b.AppendFormat("\r\n<b>Menu   id</b>  {0}", m.ItemId);
                        if (m.IsSystem)
                        {
                            b.Append(" (system)");
                        }
                        //print.it(m.GetText(true, true));
                    }
                }

                //rejected. Makes this func 5 times slower.
                //var color = uiimage.getPixel(p);
            }
            var s = b.ToString();
            //p1.Next();
            _sci.zSetText(s);
        }
    }
Beispiel #44
0
 public static extern IntPtr WindowFromPoint(POINT Point);
Beispiel #45
0
 private static extern bool GetCursorPos(out POINT lpPoint);
 static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, POINT point);
Beispiel #47
0
        public void LeftUp()
        {
            POINT point = GetMousePosition();

            mouse_event((int)MouseEventFlags.LEFTUP, point.x, point.y, 0, 0);
        }
Beispiel #48
0
        /// <summary>
        /// 重绘方法
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="rect">矩形</param>
        /// <param name="clipRect">裁剪矩形</param>
        /// <param name="isAlternate">是否交替行</param>
        public override void OnPaint(CPaint paint, RECT rect, RECT clipRect, bool isAlternate)
        {
            int clipW = clipRect.right - clipRect.left;
            int clipH = clipRect.bottom - clipRect.top;

            if (clipW > 0 && clipH > 0)
            {
                GridA      grid   = Grid;
                GridRow    row    = Row;
                GridColumn column = Column;
                if (grid != null && row != null && column != null)
                {
                    //判断选中
                    String         text             = "-";
                    bool           selected         = false;
                    List <GridRow> selectedRows     = grid.SelectedRows;
                    int            selectedRowsSize = selectedRows.Count;
                    for (int i = 0; i < selectedRowsSize; i++)
                    {
                        if (selectedRows[i] == row)
                        {
                            selected = true;
                            break;
                        }
                    }
                    //获取颜色
                    FONT          font      = null;
                    long          foreColor = COLOR.EMPTY;
                    GridCellStyle style     = Style;
                    if (style != null)
                    {
                        foreColor = style.ForeColor;
                        if (style.Font != null)
                        {
                            font = style.Font;
                        }
                    }
                    SecurityFilterInfo info  = (row as SecurityFilterResultRow).Info;
                    double             value = GetDouble();
                    if (!double.IsNaN(value))
                    {
                        if (m_fieldName != null && m_fieldName.Length > 0)
                        {
                            if (m_fieldName == "FILTER")
                            {
                                if (value == 1)
                                {
                                    foreColor = CDraw.PCOLORS_FORECOLOR9;
                                    text      = "是";
                                }
                                else
                                {
                                    foreColor = CDraw.PCOLORS_FORECOLOR7;
                                    text      = "否";
                                }
                            }
                            else
                            {
                                foreColor = CDraw.GetPriceColor(value, 0);
                                text      = value.ToString("0.0000");
                            }
                        }
                        else
                        {
                            SecurityLatestData data       = info.LatestData;
                            String             columnName = column.Name;
                            int dataSize = data != null ? data.m_securityCode.Length : 0;
                            if (columnName == "colNo")
                            {
                                foreColor = CDraw.PCOLORS_FORECOLOR7;
                                text      = ((int)value + 1).ToString();
                            }
                            else if (columnName == "colAmount" || columnName == "colVolume")
                            {
                                if (dataSize > 0)
                                {
                                    foreColor = CDraw.PCOLORS_FORECOLOR9;
                                    text      = ((long)value).ToString();
                                }
                            }
                            else if (columnName == "colDiff")
                            {
                                if (dataSize > 0)
                                {
                                    foreColor = CDraw.GetPriceColor(value, 0);
                                    text      = value.ToString("0.00");
                                }
                            }
                            else if (columnName == "colDiffRange")
                            {
                                if (dataSize > 0)
                                {
                                    foreColor = CDraw.GetPriceColor(data.m_close, data.m_lastClose);
                                    text      = value.ToString("0.00") + "%";
                                }
                            }
                            else if (columnName == "colLastClose")
                            {
                                if (dataSize > 0)
                                {
                                    foreColor = CDraw.PCOLORS_FORECOLOR9;
                                    text      = value.ToString("0.00");
                                }
                            }
                            else
                            {
                                if (dataSize > 0)
                                {
                                    foreColor = CDraw.GetPriceColor(value, data.m_lastClose);
                                    text      = value.ToString("0.00");
                                }
                            }
                        }
                    }
                    if (info.GetValue("FILTER") != 1)
                    {
                        foreColor = CDraw.PCOLORS_FORECOLOR8;
                    }
                    SIZE  tSize  = paint.TextSize(text, font);
                    POINT tPoint = new POINT(rect.right - tSize.cx, rect.top + clipH / 2 - tSize.cy / 2);
                    RECT  tRect  = new RECT(tPoint.x, tPoint.y, tPoint.x + tSize.cx, tPoint.y + tSize.cy);
                    paint.DrawText(text, foreColor, font, tRect);
                    if (selected)
                    {
                        paint.DrawLine(CDraw.PCOLORS_LINECOLOR, 2, 0, rect.left, rect.bottom - 1, rect.right, rect.bottom - 1);
                    }
                }
            }
        }
Beispiel #49
0
 public static extern Bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref SIZE psize, IntPtr hdcSrc, ref POINT pprSrc, Int32 crKey, ref BLENDFUNCTION pblend, Int32 dwFlags);
 /// <summary>
 /// Sends a win32 message to set scrollbars position.
 /// </summary>
 /// <param name="point">a POINT
 ///        conatining H/Vscrollbar scrollpos.</param>
 private void SetScrollPos(POINT point)
 {
     SendMessage(Handle, (uint)WindowsMessages.EM_SETSCROLLPOS, IntPtr.Zero, point);
 }
Beispiel #51
0
 public COMPOSITIONFORM(uint dwStyle, POINT ptCurrentPos, RECT rcArea)
 {
     this.dwStyle      = dwStyle;
     this.ptCurrentPos = ptCurrentPos;
     this.rcArea       = rcArea;
 }
Beispiel #52
0
        public bool PopupDeItem(DeItem aDeItem, POINT aPopupPt)
        {
            FFrmtp  = "";
            FDeItem = aDeItem;
            string vDeUnit = "";
            int    vCMV    = -1;

            DataTable dt = emrMSDB.DB.GetData(string.Format("SELECT DeCode, PY, frmtp, deunit, domainid "
                                                            + "FROM Comm_DataElement WHERE DeID ={0}", FDeItem[DeProp.Index]));

            if (dt.Rows.Count > 0)
            {
                FFrmtp  = dt.Rows[0]["frmtp"].ToString();
                vDeUnit = dt.Rows[0]["deunit"].ToString();
                vCMV    = int.Parse(dt.Rows[0]["domainid"].ToString());
            }

            if (FFrmtp == DeFrmtp.Number)  // 数值
            {
                if (aDeItem[DeProp.Unit] != "")
                {
                    tbxValue.Text = aDeItem.Text.Replace(aDeItem[DeProp.Unit], "");
                }
                else
                {
                    tbxValue.Text = aDeItem.Text;
                }

                if (tbxValue.Text != "")
                {
                    tbxValue.SelectAll();
                }

                cbbUnit.Items.Clear();
                string[] vStrings = vDeUnit.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < vStrings.Length; i++)
                {
                    cbbUnit.Items.Add(vStrings[i]);
                }
                if (cbbUnit.Items.Count > 0)
                {
                    cbbUnit.SelectedIndex = cbbUnit.Items.IndexOf(aDeItem[DeProp.Unit]);
                    if (cbbUnit.SelectedIndex < 0)
                    {
                        cbbUnit.SelectedIndex = 0;
                    }
                }
                else
                {
                    cbbUnit.Text = aDeItem[DeProp.Unit];
                }

                tabPop.SelectedIndex = 1;
                this.Width           = 185;

                if (aDeItem[DeProp.Index] == "979")  // 体温
                {
                    tabQk.SelectedIndex = 0;
                    this.Height         = 300;
                }
                else
                {
                    tabQk.SelectedIndex = -1;
                    this.Height         = 215;
                }
            }
            else
            if ((FFrmtp == DeFrmtp.Date) || (FFrmtp == DeFrmtp.Time) || (FFrmtp == DeFrmtp.DateTime))  // 日期时间
            {
                tabPop.SelectedIndex = 3;
                this.Width           = 260;
                this.Height          = 170;
                btnNow_Click(null, null);
                pnlDate.Visible = FFrmtp != DeFrmtp.Time;
                pnlTime.Visible = FFrmtp != DeFrmtp.Date;
            }
            else
            if ((FFrmtp == DeFrmtp.Radio) || (FFrmtp == DeFrmtp.Multiselect))  // 单、多选
            {
                MultSelect = FFrmtp == DeFrmtp.Multiselect;
                tbxSpliter.Clear();

                if (FDBDomain.Rows.Count > 0)
                {
                    FDBDomain.Reset();
                }

                dgvDomain.RowCount   = 0;
                tabPop.SelectedIndex = 0;
                this.Width           = 290;
                this.Height          = 300;

                if (vCMV > 0)  // 有值域
                {
                    FDBDomain = emrMSDB.DB.GetData(string.Format("SELECT DE.ID, DE.Code, DE.devalue, DE.PY, DC.Content "
                                                                 + "FROM Comm_DataElementDomain DE LEFT JOIN Comm_DomainContent DC ON DE.ID = DC.DItemID "
                                                                 + "WHERE DE.domainid = {0}", vCMV));
                }

                if (FDBDomain.Rows.Count > 0)  // 有选项
                {
                    IniDomainUI();
                }
                else  // 没选项
                {
                    return(false);
                }
            }
            else
            if (FFrmtp == DeFrmtp.String)
            {
                return(false);  // 文本的不弹了,使用直接在元素上修改的方式

                tbxMemo.Clear();
                tabPop.SelectedIndex = 2;
                this.Width           = 260;
                this.Height          = 200;
            }
            else  // 不认识的类型不弹
            {
                return(false);
            }

            System.Drawing.Rectangle vRect = Screen.GetWorkingArea(this);
            if (aPopupPt.X + Width > vRect.Right)
            {
                aPopupPt.X = vRect.Right - Width;
            }

            if (aPopupPt.Y + Height > vRect.Bottom)
            {
                aPopupPt.Y = vRect.Bottom - Height;
            }

            if (aPopupPt.X < vRect.Left)
            {
                aPopupPt.X = vRect.Left;
            }

            if (aPopupPt.Y < vRect.Top)
            {
                aPopupPt.Y = vRect.Top;
            }

            this.StartPosition = FormStartPosition.Manual;
            this.Location      = new Point(aPopupPt.X, aPopupPt.Y);

            this.Show();
            //User.ShowWindow(this.Handle, User.SW_SHOWNOACTIVATE);

            if (FFrmtp == DeFrmtp.Number)
            {
                tbxValue.Focus();
            }

            return(true);
        }
Beispiel #53
0
 public static extern Boolean GetCursorPos(ref POINT lpPoint);
Beispiel #54
0
 public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, ref POINT lParam);
Beispiel #55
0
 public static extern bool GetCursorPos(out POINT lpPoint);
Beispiel #56
0
        protected void DoPaintItems(HCCanvas canvas, RECT drawRect, PaintInfo paintInfo)
        {
            POINT vPoint = new POINT();
            RECT  vItemRect;

            for (int i = 0; i <= FItems.Count - 1; i++)
            {
                vPoint.X = FItems[i].Rect.Left;
                vPoint.Y = FItems[i].Rect.Top;
                vPoint.Offset(drawRect.Left, drawRect.Top);
                vItemRect = HC.Bounds(vPoint.X, vPoint.Y, RadioButtonWidth, RadioButtonWidth);

                if (paintInfo.Print)
                {
                    if (FItems[i].Checked)
                    {
                        if (FRadioStyle == HCRadioStyle.Radio)
                        {
                            HC.HCDrawFrameControl(canvas, vItemRect, HCControlState.hcsChecked, HCControlStyle.hcyRadio);
                        }
                        else
                        {
                            HC.HCDrawFrameControl(canvas, vItemRect, HCControlState.hcsChecked, HCControlStyle.hcyCheck);
                        }
                    }
                    else
                    {
                        if (FRadioStyle == HCRadioStyle.Radio)
                        {
                            HC.HCDrawFrameControl(canvas, vItemRect, HCControlState.hcsCustom, HCControlStyle.hcyRadio);
                        }
                        else
                        {
                            HC.HCDrawFrameControl(canvas, vItemRect, HCControlState.hcsCustom, HCControlStyle.hcyCheck);
                        }
                    }

                    canvas.Brush.Style = HCBrushStyle.bsClear;
                }
                else
                {
                    if (FItems[i].Checked)
                    {
                        if (FRadioStyle == HCRadioStyle.Radio)
                        {
                            User.DrawFrameControl(canvas.Handle, ref vItemRect, Kernel.DFC_BUTTON, Kernel.DFCS_CHECKED | Kernel.DFCS_BUTTONRADIO);
                        }
                        else
                        {
                            User.DrawFrameControl(canvas.Handle, ref vItemRect, Kernel.DFC_BUTTON, Kernel.DFCS_CHECKED | Kernel.DFCS_BUTTONCHECK);
                        }
                    }
                    else
                    {
                        if (FRadioStyle == HCRadioStyle.Radio)
                        {
                            User.DrawFrameControl(canvas.Handle, ref vItemRect, Kernel.DFC_BUTTON, Kernel.DFCS_BUTTONRADIO);
                        }
                        else
                        {
                            User.DrawFrameControl(canvas.Handle, ref vItemRect, Kernel.DFC_BUTTON, Kernel.DFCS_BUTTONCHECK);
                        }
                    }
                }

                canvas.TextOut(vPoint.X + RadioButtonWidth, vPoint.Y, FItems[i].Text);
            }
        }
Beispiel #57
0
 public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, POINT lParam);
Beispiel #58
0
 internal static extern IntPtr AccessibleObjectFromPoint(POINT pt, [Out, MarshalAs(UnmanagedType.Interface)] out IAccessible accObj, [Out] out object ChildID);
 public void Drop(OpenLiveWriter.Interop.Com.IOleDataObject pDataObj, MK grfKeyState, POINT pt, ref OpenLiveWriter.Interop.Com.DROPEFFECT pdwEffect)
 {
     _contentEditorSite.Drop(pDataObj, grfKeyState, pt, ref pdwEffect);
 }
Beispiel #60
0
 internal static extern bool ClientToScreen(IntPtr hwnd, ref POINT point);