/// <summary> /// Should a mouse down at the provided point cause an end to popup tracking. /// </summary> /// <param name="m">Original message.</param> /// <param name="pt">Client coordinates point.</param> /// <returns>True to end tracking; otherwise false.</returns> public virtual bool DoesCurrentMouseDownEndAllTracking(Message m, Point pt) { bool endTracking = !ClientRectangle.Contains(pt); // The mouse is not over our client area but the focus is if (endTracking && ContainsFocus) { // Get the window handle of the window under this screen point Point screenPt = PointToScreen(pt); PI.POINT screenPIPt = new PI.POINT { X = screenPt.X, Y = screenPt.Y }; IntPtr hWnd = PI.WindowFromPoint(screenPIPt); // Assuming we got back a valid window handle if (hWnd != IntPtr.Zero) { StringBuilder className = new StringBuilder(256); int length = PI.GetClassName(hWnd, className, className.Capacity); // If we got back a valid name if (length > 0) { // If let the message occur as it is being pressed on a combo box // drop down list and so it will process the message appropriately if (className.ToString() == "ComboLBox") { endTracking = false; } } } } return(endTracking); }
private void UpdateLayeredWindow(Rectangle rect) { // Cache the latest size and location _showRect = rect; // Must have a visible rectangle to render if ((rect.Width > 0) && (rect.Height > 0)) { // Draw onto a bitmap that is then used as the window display Bitmap memoryBitmap = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(memoryBitmap)) { // Perform actual painting onto the bitmap Rectangle area = new Rectangle(0, 0, rect.Width, rect.Height); using (RenderContext context = new RenderContext(null, g, area, _renderer)) { _renderer.RenderGlyph.DrawDragDropDockingGlyph(context, _dragData, _paletteDragDrop, PaletteDragFeedback.Rounded); } // Get hold of the screen DC IntPtr hDC = PI.GetDC(IntPtr.Zero); // Create a memory based DC compatible with the screen DC IntPtr memoryDC = PI.CreateCompatibleDC(hDC); // Get access to the bitmap handle contained in the Bitmap object IntPtr hBitmap = memoryBitmap.GetHbitmap(Color.FromArgb(0)); // Select this bitmap for updating the window presentation IntPtr oldBitmap = PI.SelectObject(memoryDC, hBitmap); // New window size PI.SIZE ulwsize; ulwsize.cx = rect.Width; ulwsize.cy = rect.Height; // New window position PI.POINT topPos = new PI.POINT(rect.Left, rect.Top); // Offset into memory bitmap is always zero PI.POINT pointSource = new PI.POINT(0, 0); // We want to make the entire bitmap opaque PI.BLENDFUNCTION blend = new PI.BLENDFUNCTION { BlendOp = PI.AC_SRC_OVER, BlendFlags = 0, SourceConstantAlpha = 255, AlphaFormat = PI.AC_SRC_ALPHA }; // Tell operating system to use our bitmap for painting PI.UpdateLayeredWindow(Handle, hDC, ref topPos, ref ulwsize, memoryDC, ref pointSource, 0, ref blend, PI.ULW_ALPHA); // Put back the old bitmap handle PI.SelectObject(memoryDC, oldBitmap); // Cleanup resources PI.ReleaseDC(IntPtr.Zero, hDC); PI.DeleteObject(hBitmap); PI.DeleteDC(memoryDC); } } }