void IRenderWebBrowser.SetCursor(IntPtr handle, CefCursorType type) { UiThreadRunAsync(() => { Cursor = CursorInteropHelper.Create(new SafeFileHandle(handle, ownsHandle: false)); }); }
void IRenderWebBrowser.SetCursor(IntPtr handle) { DoInUi(() => { Cursor = CursorInteropHelper.Create(new SafeFileHandle(handle, ownsHandle: false)); }); }
public static Cursor InternalCreateCursor(System.Drawing.Bitmap bmp, int xHotSpot, int yHotSpot) { //IconInfo tmp = new IconInfo(); //GetIconInfo(bmp.GetHicon(), ref tmp); //tmp.xHotspot = xHotSpot; //tmp.yHotspot = yHotSpot; //tmp.fIcon = false; //IntPtr ptr = CreateIconIndirect(ref tmp); //SafeFileHandle handle = new SafeFileHandle(ptr, true); //return CursorInteropHelper.Create(handle); var iconInfo = new IconInfo(); GetIconInfo(bmp.GetHicon(), ref iconInfo); iconInfo.xHotspot = xHotSpot; iconInfo.yHotspot = yHotSpot; iconInfo.fIcon = false; SafeIconHandle cursorHandle = CreateIconIndirect(ref iconInfo); return(CursorInteropHelper.Create(cursorHandle)); }
private void CreateCursor(int width, int height, BitmapHandle dibSectionHandle) { BitmapHandle monoBitmapHandle = null; try { monoBitmapHandle = new BitmapHandle(CreateBitmap(width, height, 1, 1, IntPtr.Zero)); ICONINFO icon = new ICONINFO(); icon.IsIcon = false; icon.xHotspot = 0; icon.yHotspot = 0; icon.ColorBitmap = dibSectionHandle; icon.MaskBitmap = monoBitmapHandle; _iconHandle = CreateIconIndirect(ref icon); if (!_iconHandle.IsInvalid) { _ghostCursor = CursorInteropHelper.Create(_iconHandle); } } finally { // destroy the temporary mono bitmap now ... if (monoBitmapHandle != null) { monoBitmapHandle.Dispose(); } } }
protected override void OnCursorChange(CefBrowser browser, IntPtr cursorHandle) { _uiHelper.PerformInUiThread(() => { Cursor cursor = CursorInteropHelper.Create(new SafeFileHandle(cursorHandle, false)); _owner.Cursor = cursor; }); }
public static Cursor CreateCursorFromBitmap(Bitmap bitmap, byte alphaLevel, Point hotSpot) { Bitmap cursorBitmap = null; External.ICONINFO iconInfo = new External.ICONINFO(); Rectangle rectangle = new Rectangle(0, 0, bitmap.Width, bitmap.Height); try { // Here, the premultiplied alpha channel is specified cursorBitmap = new Bitmap(bitmap.Width, bitmap.Height, PixelFormat.Format32bppPArgb); // I'm assuming the source bitmap can be locked in a 24 bits per pixel format BitmapData bitmapData = bitmap.LockBits(rectangle, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); BitmapData cursorBitmapData = cursorBitmap.LockBits(rectangle, ImageLockMode.WriteOnly, cursorBitmap.PixelFormat); // Use either SafeCopy() or UnsafeCopy() to set the bitmap contents SafeCopy(bitmapData, cursorBitmapData, alphaLevel); //UnsafeCopy(bitmapData, cursorBitmapData, alphaLevel); cursorBitmap.UnlockBits(cursorBitmapData); bitmap.UnlockBits(bitmapData); if (!External.GetIconInfo(bitmap.GetHicon(), out iconInfo)) { throw new Exception("GetIconInfo() failed."); } iconInfo.xHotspot = hotSpot.X; iconInfo.yHotspot = hotSpot.Y; iconInfo.IsIcon = false; //IntPtr cursorPtr = External.CreateIconIndirect(ref iconInfo); SafeIconHandle cursorPtr = External.CreateIconIndirect1(ref iconInfo); //if (cursorPtr == IntPtr.Zero) // throw new Exception("CreateIconIndirect() failed."); return(CursorInteropHelper.Create(cursorPtr)); //return (new Cursor(cursorPtr)); } finally { if (cursorBitmap != null) { cursorBitmap.Dispose(); } if (iconInfo.ColorBitmap != IntPtr.Zero) { External.DeleteObject(iconInfo.ColorBitmap); } if (iconInfo.MaskBitmap != IntPtr.Zero) { External.DeleteObject(iconInfo.MaskBitmap); } } }
public void SetCursor(IntPtr handle) { if (!Dispatcher.CheckAccess()) { Dispatcher.BeginInvoke((Action <IntPtr>)SetCursor, handle); return; } Cursor = CursorInteropHelper.Create(new SafeFileHandle(handle, ownsHandle: false)); }
private static Cursor InternalCreateCursor(Bitmap bitmap, int xHotSpot, int yHotSpot) { NativeMethods.IconInfo icon = default(NativeMethods.IconInfo); NativeMethods.GetIconInfo(bitmap.GetHicon(), ref icon); icon.xHotspot = xHotSpot; icon.yHotspot = yHotSpot; icon.fIcon = false; SafeIconHandle cursorHandle = NativeMethods.CreateIconIndirect(ref icon); return(CursorInteropHelper.Create(cursorHandle)); }
private static Cursor createCursor(Bitmap bmp, int xHotSpot, int yHotSpot) { User32.IconInfo iconInfo = new User32.IconInfo(); User32.GetIconInfo(bmp.GetHicon(), ref iconInfo); iconInfo.xHotspot = xHotSpot; iconInfo.yHotspot = yHotSpot; iconInfo.fIcon = false; SafeIconHandle cursorHandle = User32.CreateIconIndirect(ref iconInfo); return(CursorInteropHelper.Create(cursorHandle)); }
public static Cursor CreatCursor(Bitmap b, int x, int y) { IconInfo piconinfo = default(IconInfo); GetIconInfo(b.GetHicon(), ref piconinfo); piconinfo.xHotspot = x; piconinfo.yHotspot = y; piconinfo.fIcon = false; IntPtr preexistingHandle = CreateIconIndirect(ref piconinfo); return(CursorInteropHelper.Create(new SafeFileHandle(preexistingHandle, true))); }
private static Cursor InternalCreateCursor(System.Drawing.Bitmap bmp) { NativeMethods.IconInfo iconInfo = new(); NativeMethods.GetIconInfo(bmp.GetHicon(), ref iconInfo); iconInfo.xHotspot = 0; iconInfo.yHotspot = 0; iconInfo.fIcon = false; SafeIconHandle cursorHandle = NativeMethods.CreateIconIndirect(ref iconInfo); return(CursorInteropHelper.Create(cursorHandle)); }
public static Cursor CreateCursor(System.Drawing.Bitmap bmp, int xHotSpot, int yHotSpot) { IconInfo tmp = new IconInfo(); GetIconInfo(bmp.GetHicon(), ref tmp); tmp.xHotspot = xHotSpot; tmp.yHotspot = yHotSpot; tmp.fIcon = false; IntPtr ptr = CreateIconIndirect(ref tmp); SafeFileHandle handle = new SafeFileHandle(ptr, true); return(CursorInteropHelper.Create(handle)); }
//保护: /// <summary> /// 创建鼠标(本方法不允许public,避免内存泄漏) /// </summary> /// <param name="bitmap"></param> /// <param name="xHotSpot"></param> /// <param name="yHotSpot"></param> /// <returns></returns> protected static Cursor InternalCreateCursor(Bitmap bitmap, uint xHotSpot, uint yHotSpot) { var iconInfo = new NativeMethods.IconInfo(); NativeMethods.GetIconInfo(bitmap.GetHicon(), ref iconInfo); iconInfo.xHotspot = xHotSpot; //焦点x轴坐标 iconInfo.yHotspot = yHotSpot; //焦点y轴坐标 iconInfo.fIcon = false; //设置鼠标 SafeIconHandle cursorHandle = NativeMethods.CreateIconIndirect(ref iconInfo); return(CursorInteropHelper.Create(cursorHandle)); }
/// <summary> /// 透過Bitmap建立圖形游標 /// </summary> /// <param name="bitmap">要當成游標的Bitmap</param> /// <param name="xHotSpot">游標頂點的X軸位移</param> /// <param name="yHotSpot">游標頂點的Y軸位移</param> /// <returns>自訂的游標物件</returns> private static Cursor InternalCreateCursor(System.Drawing.Bitmap bitmap, int xHotSpot, int yHotSpot) { var iconInfo = new NativeMethods.IconInfo(); NativeMethods.GetIconInfo(bitmap.GetHicon(), ref iconInfo); iconInfo.xHotspot = xHotSpot; iconInfo.yHotspot = yHotSpot; iconInfo.fIcon = false; SafeIconHandle cursorHandle = NativeMethods.CreateIconIndirect(ref iconInfo); return(CursorInteropHelper.Create(cursorHandle)); }
public static Cursor CreateBmpCursor(Bitmap bmp, UInt32 xHotSpot, UInt32 yHotSpot) { if (!NativeMethods.GetIconInfo(bmp.GetHicon(), out IconInfo iconInfo)) { return(Cursors.Arrow); } iconInfo.xHotspot = xHotSpot; // 焦点x轴坐标 iconInfo.yHotspot = yHotSpot; // 焦点y轴坐标 iconInfo.fIcon = false; // 设置鼠标 var cursorHandle = NativeMethods.CreateIconIndirect(ref iconInfo); return(CursorInteropHelper.Create(cursorHandle)); }
private static Cursor InternalCreateCursor(System.Drawing.Bitmap bmp, int xHotSpot, int yHotSpot) { var tmp = new IconInfo(); GetIconInfo(bmp.GetHicon(), ref tmp); tmp.XHotspot = xHotSpot; tmp.YHotspot = yHotSpot; tmp.FIcon = false; IntPtr ptr = CreateIconIndirect(ref tmp); var handle = new SafeFileHandle(ptr, true); return(CursorInteropHelper.Create(handle)); }
static Cursor InternalCreateCursor(Bitmap bitmap, int xHotSpot, int yHotSpot) { var iconInfo = new NativeMethods.IconInfo { xHotspot = xHotSpot, yHotspot = yHotSpot, fIcon = false }; NativeMethods.GetIconInfo(bitmap.GetHicon(), ref iconInfo); var cursorHandle = NativeMethods.CreateIconIndirect(ref iconInfo); return(CursorInteropHelper.Create(cursorHandle)); }
private static Cursor InternalCreateCursor(System.Drawing.Bitmap bmp, int xHotspot = 0, int yHotspot = 0) { var iconInfo = new NativeMethods.IconInfo(); var handler = bmp.GetHicon(); NativeMethods.GetIconInfo(handler, ref iconInfo); NativeMethods.DestroyIcon(handler); iconInfo.xHotspot = xHotspot; iconInfo.yHotspot = yHotspot; iconInfo.fIcon = false; var cursorHandle = NativeMethods.CreateIconIndirect(ref iconInfo); return(CursorInteropHelper.Create(cursorHandle)); }
public static Cursor ToCursor(this Bitmap bitmap, PointWpf hotSpot) { /// get icon from input bitmap var ico = new IconInfo(); GetIconInfo(bitmap.GetHicon(), ref ico); /// set the hotspot ico.xHotspot = (int)(hotSpot.X * bitmap.Width); ico.yHotspot = (int)(hotSpot.Y * bitmap.Height); ico.fIcon = false; /// create a cursor from iconinfo var cursor = CreateIconIndirect(ref ico); return(CursorInteropHelper.Create(new SafeIconHandle(cursor))); }
public static Cursor CreatCursor(Bitmap b, int x, int y) { /// get icon from input bitmap IconInfo ico = new IconInfo(); GetIconInfo(b.GetHicon(), ref ico); /// set the hotspot ico.xHotspot = x; ico.yHotspot = y; ico.fIcon = false; /// create a cursor from iconinfo IntPtr cursor = CreateIconIndirect(ref ico); return(CursorInteropHelper.Create(new SafeFileHandle(cursor, true))); }
//------------------------------------------------------------------------------- // // Private Methods // //------------------------------------------------------------------------------- #region Private Methods /// <summary> /// Create a Cursor from a Drawing object /// </summary> /// <param name="drawing">Drawing</param> /// <param name="hotspot">Cursor Hotspot</param> /// <returns></returns> private static Cursor CreateCursorFromDrawing(Drawing drawing, Point hotspot) { // A default cursor. Cursor cursor = Cursors.Arrow; Rect drawingBounds = drawing.Bounds; double originalWidth = drawingBounds.Width; double originalHeight = drawingBounds.Height; // Cursors like to be multiples of 8 in dimension. int width = IconHelper.AlignToBytes(drawingBounds.Width, 1); int height = IconHelper.AlignToBytes(drawingBounds.Height, 1); // Now inflate the drawing bounds to the new dimension. drawingBounds.Inflate((width - originalWidth) / 2, (height - originalHeight) / 2); // Translate the hotspot accordingly. int xHotspot = (int)Math.Round(hotspot.X - drawingBounds.Left); int yHotspot = (int)Math.Round(hotspot.Y - drawingBounds.Top); // Create a DrawingVisual which represents the cursor drawing. DrawingVisual cursorDrawingVisual = CreateCursorDrawingVisual(drawing, width, height); // Render the cursor visual to a bitmap RenderTargetBitmap rtb = RenderVisualToBitmap(cursorDrawingVisual, width, height); // Get pixel data in Bgra32 fromat from the bitmap byte[] pixels = GetPixels(rtb, width, height); NativeMethods.IconHandle finalCursor = IconHelper.CreateIconCursor(pixels, width, height, xHotspot, yHotspot, false); if (finalCursor.IsInvalid) { // Return the default cursor if above is failed. return(Cursors.Arrow); } cursor = CursorInteropHelper.CriticalCreate(finalCursor); return(cursor); }
private Cursor CrossHairCursor(int w, int h) { Pen pen = new Pen(Color.Red, 5); Pen thinPen = new Pen(Color.Red, 1); var pic = new Bitmap(w, h); var gr = Graphics.FromImage(pic); var pathXL = new GraphicsPath(); var pathXR = new GraphicsPath(); var pathX = new GraphicsPath(); var pathYT = new GraphicsPath(); var pathYB = new GraphicsPath(); var pathY = new GraphicsPath(); pathY.AddLine(new Point(w / 2, 0), new Point(w / 2, h)); pathYT.AddLine(new Point(w / 2, h / 2 - 2 * 16), new Point(w / 2, h / 2 - 16)); pathYB.AddLine(new Point(w / 2, h / 2 + 2 * 16), new Point(w / 2, h / 2 + 16)); pathX.AddLine(new Point(0, h / 2), new Point(w, h / 2)); pathXL.AddLine(new Point(w / 2 - 2 * 16, h / 2), new Point(w / 2 - 16, h / 2)); pathXR.AddLine(new Point(w / 2 + 16, h / 2), new Point(w / 2 + 2 * 16, h / 2)); gr.DrawPath(pen, pathXL); gr.DrawPath(pen, pathXR); gr.DrawPath(pen, pathYT); gr.DrawPath(pen, pathYB); gr.DrawPath(thinPen, pathX); gr.DrawPath(thinPen, pathY); var icon = Icon.FromHandle(pic.GetHicon()); SafeIconHandle safeHandle = _safeHandle; if (safeHandle != null) { safeHandle.Dispose(); } _safeHandle = new SafeIconHandle(icon.Handle); safeHandle = _safeHandle; return(CursorInteropHelper.Create(safeHandle)); }
private static Cursor CreateCursorFromDrawing(Drawing drawing, Point hotspot) { Cursor arrow = Cursors.Arrow; Rect bounds = drawing.Bounds; double width = bounds.Width; double height = bounds.Height; int num = IconHelper.AlignToBytes(bounds.Width, 1); int num2 = IconHelper.AlignToBytes(bounds.Height, 1); bounds.Inflate(((double)num - width) / 2.0, ((double)num2 - height) / 2.0); int xHotspot = (int)Math.Round(hotspot.X - bounds.Left); int yHotspot = (int)Math.Round(hotspot.Y - bounds.Top); DrawingVisual visual = PenCursorManager.CreateCursorDrawingVisual(drawing, num, num2); RenderTargetBitmap rtb = PenCursorManager.RenderVisualToBitmap(visual, num, num2); byte[] pixels = PenCursorManager.GetPixels(rtb, num, num2); NativeMethods.IconHandle iconHandle = IconHelper.CreateIconCursor(pixels, num, num2, xHotspot, yHotspot, false); if (iconHandle.IsInvalid) { return(Cursors.Arrow); } return(CursorInteropHelper.CriticalCreate(iconHandle)); }
private void InitializeWebView(int width, int height) { try { RaiseStatus("Creating WebView"); webView = webCore.CreateWebView(width, height); webView.SetTransparent(IsTransparent); RaiseStatus("Initializign WebViewListener"); webViewListener = new WebViewListener(); webViewListener.BeginNavigation += delegate(string url, string frameName) { RaiseStatus(string.Format("BeginNavigation: {0}", url)); if (BeginNavigation != null) { BeginNavigation(this, new UrlEventArgs(url, frameName)); } if (string.IsNullOrEmpty(frameName)) { Dispatcher.BeginInvoke((Action) delegate { Source = loadedUrl = url; }, DispatcherPriority.Render); } }; webViewListener.BeginLoading += delegate(string url, string frameName, int statusCode, string mimeType) { RaiseStatus(string.Format("BeginLoading: {0}", url)); if (BeginLoading != null) { BeginLoading(this, new LoadingEventArgs(url, frameName, statusCode, mimeType)); } }; webViewListener.FinishLoading += delegate { RaiseStatus(string.Format("FinishLoading")); if (FinishLoading != null) { FinishLoading(this, EventArgs.Empty); } }; webViewListener.ReceiveTitle += delegate(string title, string frameName) { RaiseStatus(string.Format("ReceiveTitle: {0}", title)); }; webViewListener.ChangeCursor += delegate(ValueType cursorHandle) { Dispatcher.BeginInvoke((Action) delegate { Cursor = CursorInteropHelper.Create(new SafeFileHandle((IntPtr)cursorHandle, false)); }, DispatcherPriority.Render); }; webViewListener.ChangeTooltip += delegate(string text) { Dispatcher.BeginInvoke((Action) delegate { try { if (text != null && text.Trim().Length > 0 && IsFocused) { tooltip.Content = text; tooltip.IsOpen = true; } else { tooltip.IsOpen = false; } } catch { } }, DispatcherPriority.Render); }; webViewListener.ChangeKeyboardFocus += delegate(bool isFocused) { isBrowserFocused = isFocused; }; webView.SetListener(webViewListener); webView.Focus(); } catch (Exception ex) { RaiseStatus(ex.Message + ex.StackTrace); } }
public static Cursor CreateBmpCursor(Bitmap cursorBitmap) { var c = new BitmapCursor(cursorBitmap); return(CursorInteropHelper.Create(c)); }
public static Cursor CreateBmpCursor(System.Drawing.Bitmap cursorBitmap) { BitmapCursor c = new BitmapCursor(cursorBitmap); return(CursorInteropHelper.Create(c)); }
/// <summary> /// Creates a WPF cursor from a win32 bitmap /// </summary> /// <param name="cursorBitmap"></param> /// <returns></returns> public static Cursor CreateCursor(Bitmap cursorBitmap) { var csh = new WPFCursorFromBitmap(cursorBitmap); return(CursorInteropHelper.Create(csh)); }