// Rebuild new region from previous one public static void BuildRegion(IntPtr hWnd) { IntPtr hRgnClip = IntPtr.Zero; ApiWin32.RECT rw = new ApiWin32.RECT(); ApiWin32.GetWindowRect(hWnd, ref rw); int RgnWidth = rw.Right - rw.Left, RgnHeight = rw.Bottom - rw.Top; // Avoid changing region when iconized ! if (RgnHeight < DockMin) { return; } if ((LastRgnWidth == RgnWidth) && (LastRgnHeight == RgnHeight)) { return; } IntPtr hRgn = ApiWin32.CreateRectRgn(0, 0, 0, 0); if (hRgn != IntPtr.Zero) { if (ApiWin32.GetWindowRgn(hWnd, hRgn)) { hRgnClip = ApiWin32.CreateRectRgn(0, 0, RgnWidth, RgnHeight); if (hRgnClip != IntPtr.Zero) { // Top left corner. int rgnX = 0; int rgnY = 0; CombineRegion(ref hRgnClip, hRgn, 0, 0, FixCaptionLeft, FixCaptionHeight, rgnX, rgnY); // Top right corner. rgnX = -LastRgnWidth + FixCaptionRight; rgnY = 0; CombineRegion(ref hRgnClip, hRgn, RgnWidth - FixCaptionRight, 0, FixCaptionRight, FixCaptionHeight, rgnX, rgnY); // Bottom left corner. rgnX = 0; rgnY = -LastRgnHeight + FixBottomHeight; CombineRegion(ref hRgnClip, hRgn, 0, RgnHeight - FixBottomHeight, FixCaptionLeft, FixBottomHeight, rgnX, rgnY); // Bottom right corner. rgnX = -LastRgnWidth + FixCaptionRight; rgnY = -LastRgnHeight + FixBottomHeight; CombineRegion(ref hRgnClip, hRgn, RgnWidth - FixCaptionRight, RgnHeight - FixBottomHeight, FixCaptionRight, FixBottomHeight, rgnX, rgnY); Form.FromHandle(hWnd).BackgroundImage = (Bitmap)SkinEngine.DrawBackGround(RgnWidth, RgnHeight); // Set the new region to the form. ApiWin32.SetWindowRgn(hWnd, hRgnClip, false); // Save the new region size LastRgnWidth = RgnWidth; LastRgnHeight = RgnHeight; } } ApiWin32.DeleteObject(hRgn); } }
// Combine child regions altogether. public static void CombineRegion(ref IntPtr hRgnClip, IntPtr hRgn, int xOffset, int yOffset, int bmW, int bmH, int rgnX, int rgnY) { IntPtr hRgnTemp = ApiWin32.CreateRectRgn(0, 0, bmW, bmH); ApiWin32.OffsetRgn(hRgnTemp, xOffset, yOffset); ApiWin32.CombineRgn(hRgnClip, hRgnClip, hRgnTemp, ApiWin32.RGN_DIFF); ApiWin32.OffsetRgn(hRgnTemp, -xOffset, -yOffset); hRgnTemp = ApiWin32.CreateRectRgn(0, 0, bmW, bmH); ApiWin32.OffsetRgn(hRgn, rgnX, rgnY); ApiWin32.CombineRgn(hRgnTemp, hRgnTemp, hRgn, ApiWin32.RGN_AND); ApiWin32.OffsetRgn(hRgn, -rgnX, -rgnY); ApiWin32.OffsetRgn(hRgnTemp, xOffset, yOffset); ApiWin32.CombineRgn(hRgnClip, hRgnClip, hRgnTemp, ApiWin32.RGN_OR); ApiWin32.DeleteObject(hRgnTemp); }