public override bool CanClosePopup(RadPopupCloseReason reason) { RadRibbonBar ribbonBar = this.RibbonBarElement.ElementTree.Control as RadRibbonBar; Point pointInRibbon = ribbonBar.PointToClient(System.Windows.Forms.Cursor.Position); if (this.RibbonBarElement.TabStripElement.ItemContainer.ControlBoundingRectangle.Contains(pointInRibbon)) { return(false); } NativeMethods.POINTSTRUCT point = new NativeMethods.POINTSTRUCT(); point.x = Cursor.Position.X; point.y = Cursor.Position.Y; IntPtr handle = NativeMethods._WindowFromPoint(point); Control controlUnderMouse = Control.FromHandle(handle); if (controlUnderMouse is ZoomPopup) { return(false); } if (controlUnderMouse is RadDropDownMenu) { return(false); } return(base.CanClosePopup(reason)); }
protected virtual void UpdateLayeredWindow(byte alpha) { var bitmap = (Bitmap)BackgroundImage; IntPtr hdcScreen = NativeMethods.GetDC(new HandleRef(this, IntPtr.Zero)); IntPtr hdcMemory = NativeMethods.CreateCompatibleDC(new HandleRef(this, hdcScreen)); IntPtr hBitmap = bitmap.GetHbitmap(Color.FromArgb(0)); IntPtr hOldBitmap = NativeMethods.SelectObject(new HandleRef(this, hdcMemory), new HandleRef(this, hBitmap)); var size = new NativeMethods.SIZESTRUCT(bitmap.Width, bitmap.Height); var pointSource = new NativeMethods.POINTSTRUCT(0, 0); var topPos = new NativeMethods.POINTSTRUCT(Left, Top); var blend = new NativeMethods.BLENDFUNCTION(); blend.BlendOp = 0; blend.BlendFlags = 0; blend.SourceConstantAlpha = alpha; blend.AlphaFormat = 1; NativeMethods.UpdateLayeredWindow(handle, hdcScreen, ref topPos, ref size, hdcMemory, ref pointSource, 0, ref blend, 0x00000002); NativeMethods.ReleaseDC(new HandleRef(this, IntPtr.Zero), new HandleRef(this, hdcScreen)); if (hBitmap != IntPtr.Zero) { NativeMethods.SelectObject(new HandleRef(this, hdcMemory), new HandleRef(this, hOldBitmap)); NativeMethods.DeleteObject(new HandleRef(this, hBitmap)); } NativeMethods.DeleteDC(new HandleRef(this, hdcMemory)); }
/// <summary> /// Retrieves a <see cref='Screen'/> for the monitor that contains the specified point. /// </summary> public static Screen FromPoint(Point point) { if (_multiMonitorSupport) { NativeMethods.POINTSTRUCT pt = new NativeMethods.POINTSTRUCT((int)point.X, (int)point.Y); return(new Screen(NativeMethods.MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST))); } return(new Screen((IntPtr)PRIMARY_MONITOR)); }
public void SetBits() { Bitmap image = new Bitmap(this.m_HostForm.Width + (m_Config.ShadowWidth * 2), this.m_HostForm.Height + (m_Config.ShadowWidth * 2)); Graphics g = Graphics.FromImage(image); g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; this.DrawShadow(g); if (Image.IsCanonicalPixelFormat(image.PixelFormat) && Image.IsAlphaPixelFormat(image.PixelFormat)) { IntPtr zero = IntPtr.Zero; //diff //IntPtr dC = NativeMethods.GetDC(new HandleRef(null, IntPtr.Zero)); IntPtr dC = NativeMethods.GetDC(IntPtr.Zero); IntPtr hgdiobj = IntPtr.Zero; //diff //IntPtr hdc = NativeMethods.CreateCompatibleDC(new HandleRef(null, dC)); IntPtr hdc = NativeMethods.CreateCompatibleDC(dC); try { NativeMethods.POINTSTRUCT pptDst = new NativeMethods.POINTSTRUCT(base.Left, base.Top); NativeMethods.SIZESTRUCT psize = new NativeMethods.SIZESTRUCT(base.Width, base.Height); NativeMethods.BLENDFUNCTION pblend = new NativeMethods.BLENDFUNCTION(); NativeMethods.POINTSTRUCT pprSrc = new NativeMethods.POINTSTRUCT(0, 0); hgdiobj = image.GetHbitmap(Color.FromArgb(0)); zero = NativeMethods.SelectObject(hdc, hgdiobj); pblend.BlendOp = 0; pblend.SourceConstantAlpha = byte.Parse("255"); pblend.AlphaFormat = 1; pblend.BlendFlags = 0; NativeMethods.UpdateLayeredWindow(base.Handle, dC, ref pptDst, ref psize, hdc, ref pprSrc, 0, ref pblend, 2); return; } finally { if (hgdiobj != IntPtr.Zero) { NativeMethods.SelectObject(hdc, zero); NativeMethods.DeleteObject(hgdiobj); } NativeMethods.ReleaseDC(IntPtr.Zero, dC); NativeMethods.DeleteDC(hdc); } } throw new ApplicationException("图片必须是32位带Alhpa通道的图片。"); }
public HitTestCode HitTestBackground(IDeviceContext dc, Rectangle backgroundRectangle, Point pt, HitTestOptions options) { if (dc == null) { throw new ArgumentNullException(nameof(dc)); } int htCode = 0; NativeMethods.POINTSTRUCT point = new NativeMethods.POINTSTRUCT(pt.X, pt.Y); using (WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper(dc, AllGraphicsProperties)) { HandleRef hdc = new HandleRef(wgr, wgr.WindowsGraphics.DeviceContext.Hdc); lastHResult = SafeNativeMethods.HitTestThemeBackground(new HandleRef(this, Handle), hdc, part, state, (int)options, new NativeMethods.COMRECT(backgroundRectangle), NativeMethods.NullHandleRef, point, ref htCode); } return((HitTestCode)htCode); }
public static extern int HitTestThemeBackground(HandleRef hTheme, HandleRef hdc, int iPartId, int iStateId, int dwOptions, [In] NativeMethods.COMRECT pRect, HandleRef hrgn, [In] NativeMethods.POINTSTRUCT ptTest, ref int pwHitTestCode);
public static extern IntPtr MonitorFromPoint(NativeMethods.POINTSTRUCT pt, int flags);
IntPtr GetCurrentMonitorFromMousePosition() { SecurityHelper.DemandUnmanagedCode(); // center on the screen on which the mouse is on NativeMethods.POINT pt = new NativeMethods.POINT(); UnsafeNativeMethods.TryGetCursorPos(pt); NativeMethods.POINTSTRUCT ptStruct = new NativeMethods.POINTSTRUCT(pt.x, pt.y); return SafeNativeMethods.MonitorFromPoint(ptStruct, NativeMethods.MONITOR_DEFAULTTONEAREST); }
public static IntPtr MonitorFromPoint(NativeMethods.POINTSTRUCT pt, int flags) { return(SafeNativeMethodsPrivate.MonitorFromPoint(pt, flags)); }
/// <summary> /// Retrieves a Screen for the display that contains the specified point. /// </summary> /// <param name="point">A <see cref="T:System.Windows.Point" /> that specifies the location for which to retrieve a Screen.</param> /// <returns>A Screen for the display that contains the point. In multiple display environments where no display contains the point, the display closest to the specified point is returned.</returns> public static Screen FromPoint(Point point) { if (multiMonitorSupport) { var pt = new NativeMethods.POINTSTRUCT((int)point.X, (int)point.Y); return new Screen(NativeMethods.MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST)); } return new Screen((IntPtr)PRIMARY_MONITOR); }