public static void SetPosition(int mouseEventPositionX, int mouseEventPositionY) { var point = new WinApi.POINT(mouseEventPositionX, mouseEventPositionY); Thread.Sleep(Delay); WinApi.SetCursorPos(point.X, point.Y); }
private WinApi.User32.HitTestResult GetWindowEdgeType(WinApi.RECT rect, WinApi.POINT position) { //if (!rect.Contains(position)) // return BorderlessWindow.WindowEdgeType.Client; // Normalize coordinates position.X -= rect.X; position.Y -= rect.Y; rect.X = 0; rect.Y = 0; bool nearTopEdge = position.Y < TopBorder; bool nearLeftEdge = position.X < LeftBorder; bool nearRightEdge = position.X > rect.Width - RightBorder; bool nearBottomEdge = position.Y > rect.Height - BottomBorder; if (nearTopEdge) { if (nearLeftEdge) { return(WinApi.User32.HitTestResult.HTTOPLEFT); } if (nearRightEdge) { return(WinApi.User32.HitTestResult.HTTOPRIGHT); } return(WinApi.User32.HitTestResult.HTTOP); } if (nearBottomEdge) { if (nearLeftEdge) { return(WinApi.User32.HitTestResult.HTBOTTOMLEFT); } if (nearRightEdge) { return(WinApi.User32.HitTestResult.HTBOTTOMRIGHT); } return(WinApi.User32.HitTestResult.HTBOTTOM); } if (nearLeftEdge) { return(WinApi.User32.HitTestResult.HTLEFT); } if (nearRightEdge) { return(WinApi.User32.HitTestResult.HTRIGHT); } return(WinApi.User32.HitTestResult.HTCLIENT); }
private void UpdatePos(WinApi.POINT currentPoint) { WinApi.POINT delta = new WinApi.POINT(_downMousePos.X - currentPoint.X, _downMousePos.Y - currentPoint.Y); WinApi.RECT windowRect = _downWndRect; windowRect.X = windowRect.X - delta.X; windowRect.Y = windowRect.Y - delta.Y; WinApi.User32.SetWindowPos(_ownerForm.Handle, IntPtr.Zero, windowRect.X, windowRect.Y, windowRect.Width, windowRect.Height, 0); }
public bool PreProcessMessage(ref WindowMessage message) { if (message.MessageType == WinApi.MessageType.WM_NCHITTEST) { WinApi.POINT cursorPosition = WinApi.DecodeUtility.DecodePoint((int)message.LParam); WinApi.User32.ScreenToClient(_window.Handle, ref cursorPosition); WinApi.User32.HitTestResult windowEdgeType = GetWindowEdgeType(_window.ClientRect, cursorPosition); message.Result = (IntPtr)windowEdgeType; return(true); } return(false); }
public bool PreProcessMessage(ref WindowMessage message) { //Debug.Log(message.MessageType); switch (message.MessageType) { case WinApi.MessageType.WM_NCLBUTTONDOWN: if (message.WParam != (IntPtr)WinApi.User32.HitTestResult.HTCAPTION) { return(false); } _isDragging = true; WinApi.User32.SetCapture(_ownerForm.Handle); WinApi.User32.GetWindowRect(_ownerForm.Handle, out _downWndRect); _downMousePos = WinApi.DecodeUtility.DecodePoint((int)message.LParam); message.Result = IntPtr.Zero; return(true); case WinApi.MessageType.WM_MOUSEMOVE: if (!_isDragging) { return(false); } WinApi.POINT cursorPos = WinApi.DecodeUtility.DecodePoint((int)message.LParam); WinApi.User32.ClientToScreen(_ownerForm.Handle, ref cursorPos); UpdatePos(cursorPos); message.Result = IntPtr.Zero; return(true); case WinApi.MessageType.WM_LBUTTONUP: if (_isDragging) { _isDragging = false; WinApi.User32.ReleaseCapture(); message.Result = IntPtr.Zero; return(true); } break; } return(false); }
private void SetBitmap(Bitmap bitmap, byte opacity) { if (bitmap.PixelFormat != PixelFormat.Format32bppArgb) { throw new ApplicationException("The bitmap must be 32ppp with alpha-channel."); } var screenDc = WinApi.GetDC(IntPtr.Zero); var memDc = WinApi.CreateCompatibleDC(screenDc); var hBitmap = IntPtr.Zero; var oldBitmap = IntPtr.Zero; try { hBitmap = bitmap.GetHbitmap(Color.FromArgb(0)); oldBitmap = WinApi.SelectObject(memDc, hBitmap); var size = new WinApi.SIZE(bitmap.Width, bitmap.Height); var pointSource = new WinApi.POINT(0, 0); var topPos = new WinApi.POINT(Left, Top); var blend = new WinApi.BLENDFUNCTION { BlendOp = WinApi.AC_SRC_OVER, BlendFlags = 0, SourceConstantAlpha = opacity, AlphaFormat = WinApi.AC_SRC_ALPHA }; WinApi.UpdateLayeredWindow(Handle, screenDc, ref topPos, ref size, memDc, ref pointSource, 0, ref blend, WinApi.ULW_ALPHA); } finally { WinApi.ReleaseDC(IntPtr.Zero, screenDc); if (hBitmap != IntPtr.Zero) { WinApi.SelectObject(memDc, oldBitmap); WinApi.DeleteObject(hBitmap); } WinApi.DeleteDC(memDc); } }
private void Render() { var screenDc = WinApi.GetDC(WinApi.NullHandleRef); if (screenDc == IntPtr.Zero) { return; } try { var memDc = WinApi.CreateCompatibleDC(new HandleRef(null, screenDc)); if (memDc == IntPtr.Zero) { return; } try { using (Bitmap bmp = GetWindowBitmap(Size.Width, Size.Height)) { IntPtr hBitmap = bmp.GetHbitmap(_transparent); IntPtr hOldBitmap = WinApi.SelectObject(memDc, hBitmap); WinApi.POINT newLocation = new WinApi.POINT(Location); WinApi.SIZE newSize = new WinApi.SIZE(Size); WinApi.UpdateLayeredWindow(Handle, screenDc, ref newLocation, ref newSize, memDc, ref _ptZero, 0, ref _blend, WinApi.BlendingFlags.ULW_ALPHA); if (hBitmap != IntPtr.Zero) { WinApi.SelectObject(memDc, hOldBitmap); WinApi.DeleteObject(hBitmap); } } } finally { WinApi.DeleteDC(new HandleRef(null, memDc)); } } finally { WinApi.ReleaseDC(WinApi.NullHandleRef, new HandleRef(null, screenDc)); } }
private static extern bool GetCursorPos(out WinApi.POINT lpPoint);
public static void SetPosition(WinApi.POINT point) { Thread.Sleep(Delay); WinApi.SetCursorPos(point.X, point.Y); }