/// <summary> /// Show the window relative to provided screen rectangle. /// </summary> /// <param name="screenRect">Screen rectangle.</param> public void ShowRelative(Rectangle screenRect) { // Find screen middle points int yMid = screenRect.Y + (screenRect.Height / 2); int xMid = screenRect.X + (screenRect.Width / 2); // Find docking size middle points int yHalf = _dragData.DockWindowSize.Height / 2; int xHalf = _dragData.DockWindowSize.Width / 2; Point location; if (_dragData.ShowLeft && !_dragData.ShowRight && !_dragData.ShowMiddle && !_dragData.ShowTop && !_dragData.ShowBottom) { location = new Point(screenRect.Left + 10, yMid - yHalf); } else if (!_dragData.ShowLeft && _dragData.ShowRight && !_dragData.ShowMiddle && !_dragData.ShowTop && !_dragData.ShowBottom) { location = new Point(screenRect.Right - _dragData.DockWindowSize.Width - 10, yMid - yHalf); } else if (!_dragData.ShowLeft && !_dragData.ShowRight && !_dragData.ShowMiddle && _dragData.ShowTop && !_dragData.ShowBottom) { location = new Point(xMid - xHalf, screenRect.Top + 10); } else if (!_dragData.ShowLeft && !_dragData.ShowRight && !_dragData.ShowMiddle && !_dragData.ShowTop && _dragData.ShowBottom) { location = new Point(xMid - xHalf, screenRect.Bottom - _dragData.DockWindowSize.Height - 10); } else { location = new Point(xMid - xHalf, yMid - yHalf); } // Update the image for display UpdateLayeredWindow(new Rectangle(location, _showRect.Size)); // Show the window without activating it (i.e. do not take focus) PI.ShowWindow(this.Handle, (short)PI.SW_SHOWNOACTIVATE); }
/// <summary> /// Show the window without taking activation. /// </summary> public void ShowWithoutActivate() { // Show the window without activating it (i.e. do not take focus) PI.ShowWindow(this.Handle, (short)PI.SW_SHOWNOACTIVATE); }
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; topPos.x = rect.Left; topPos.y = rect.Top; // Offset into memory bitmap is always zero PI.POINT pointSource; pointSource.x = 0; pointSource.y = 0; // We want to make the entire bitmap opaque PI.BLENDFUNCTION blend = new PI.BLENDFUNCTION(); blend.BlendOp = (byte)PI.AC_SRC_OVER; blend.BlendFlags = 0; blend.SourceConstantAlpha = 255; blend.AlphaFormat = (byte)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, (int)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); } } }
/// <summary> /// Hide the window from display. /// </summary> public void Hide() { PI.ShowWindow(this.Handle, (short)PI.SW_HIDE); }