internal Size GetPartSize(IDeviceContext dc, ThemeSizeType type, IntPtr hWnd) { if (dc == null) { throw new ArgumentNullException(nameof(dc)); } // valid values are 0x0 to 0x2 if (!ClientUtils.IsEnumValid(type, (int)type, (int)ThemeSizeType.Minimum, (int)ThemeSizeType.Draw)) { throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(ThemeSizeType)); } NativeMethods.SIZE size = new NativeMethods.SIZE(); using (WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper(dc, AllGraphicsProperties)) { HandleRef hdc = new HandleRef(wgr, wgr.WindowsGraphics.DeviceContext.Hdc); if (DpiHelper.IsPerMonitorV2Awareness && (IntPtr.Zero != hWnd)) { using (ThemeHandle hTheme = ThemeHandle.Create(_class, true, new HandleRef(null, hWnd))) { lastHResult = SafeNativeMethods.GetThemePartSize(new HandleRef(this, hTheme.NativeHandle), hdc, part, state, null, type, size); } } else { lastHResult = SafeNativeMethods.GetThemePartSize(new HandleRef(this, Handle), hdc, part, state, null, type, size); } } return(new Size(size.cx, size.cy)); }
private NativeMethods.SIZE SetExtent(int width, int height) { NativeMethods.SIZE size = new NativeMethods.SIZE(); size.cx = width; size.cy = height; bool flag = false; try { this._axOleObject.SetExtent(1, size); } catch (COMException) { flag = true; } if (flag) { this._axOleObject.GetExtent(1, size); try { this._axOleObject.SetExtent(1, size); } catch (COMException ex) { } } return(this.GetExtent()); }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods // Gets the bounding rectangle for this element internal static NativeMethods.Win32Rect GetBoundingRectangle(IntPtr hwnd) { if (!HasGrip(hwnd)) { return(NativeMethods.Win32Rect.Empty); } NativeMethods.Win32Rect client = new NativeMethods.Win32Rect(); if (!Misc.GetClientRectInScreenCoordinates(hwnd, ref client)) { return(NativeMethods.Win32Rect.Empty); } // Get the Size for the Gripper // The size can change at any time so the value cannot be cached NativeMethods.SIZE sizeGrip = WindowsGrip.GetGripSize(hwnd, true); if (Misc.IsLayoutRTL(hwnd)) { // Right to left mirroring style return(new NativeMethods.Win32Rect(client.left, client.bottom - sizeGrip.cy, client.left + sizeGrip.cx, client.bottom)); } else { return(new NativeMethods.Win32Rect(client.right - sizeGrip.cx, client.bottom - sizeGrip.cy, client.right, client.bottom)); } }
private NativeMethods.SIZE SetExtent(int width, int height) { NativeMethods.SIZE sz = new NativeMethods.SIZE(); sz.cx = width; sz.cy = height; bool resetExtents = false; try { _axOleObject.SetExtent(NativeMethods.DVASPECT_CONTENT, sz); } catch (COMException) { resetExtents = true; } if (resetExtents) { _axOleObject.GetExtent(NativeMethods.DVASPECT_CONTENT, sz); try { _axOleObject.SetExtent(NativeMethods.DVASPECT_CONTENT, sz); } catch (COMException e) { Debug.Fail(e.ToString()); } } return(GetExtent()); }
// ------------------------------------------------------ // // Private Methods // // ------------------------------------------------------ #region Private methods private int GetTextExtentPoint32(string text, out NativeMethods.SIZE size) { size.cx = 0; size.cy = 0; // add the width of the character at that position. // note: if any of these can throw an exception then we should use a finally clause // to ensure the DC is released. IntPtr hdc = Misc.GetDC(_hwnd); if (hdc == IntPtr.Zero) { return(0); } IntPtr oldFont = IntPtr.Zero; try { IntPtr hfont = GetFont(); oldFont = Misc.SelectObject(hdc, hfont); return(Misc.GetTextExtentPoint32(hdc, text, text.Length, out size)); } finally { if (oldFont != IntPtr.Zero) { Misc.SelectObject(hdc, oldFont); } Misc.ReleaseDC(_hwnd, hdc); } }
public static extern int GetThemePartSize( IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, IntPtr rect, ThemeSizeType eSize, [Out] NativeMethods.SIZE psz);
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods // Retreive the dimension of of UI element internal NativeMethods.SIZE Size(int iPartId, int iStateId) { bool fSuccess = false; // Default is (0, 0) NativeMethods.SIZE size = new NativeMethods.SIZE(0, 0); if (!_hTheme.IsInvalid) { unsafe { fSuccess = GetThemePartSize(_hTheme, IntPtr.Zero, iPartId, iStateId, IntPtr.Zero, (int)THEMESIZE.TS_TRUE, &size) == IntPtr.Zero; } } // Falls back uses GetSystemMetrics if (!fSuccess) { // dangerous construct, the iPartId might collide. // When entering an entry, make sure that the ID is not previously used. // If it is the case, then an extra parameter needs to be added to this method switch (iPartId) { case (int)STATUSPARTS.SP_GRIPPER: size.cx = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXSIZE); size.cy = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXSIZE); break; case (int)SCROLLBARPARTS.SBP_SIZEBOX: size.cx = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXVSCROLL); size.cy = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYHSCROLL); break; case (int)SCROLLBARPARTS.SBP_ARROWBTN: size.cx = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXHSCROLL); size.cy = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CYVSCROLL); break; case (int)WINDOWPARTS.WP_MINBUTTON: case (int)WINDOWPARTS.WP_MAXBUTTON: case (int)WINDOWPARTS.WP_CLOSEBUTTON: case (int)WINDOWPARTS.WP_HELPBUTTON: size.cx = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXSIZE); size.cy = UnsafeNativeMethods.GetSystemMetrics(NativeMethods.SM_CXSIZE); break; default: System.Diagnostics.Debug.Assert(false, "Unsupport Type"); break; } } return(size); }
public Size GetPartPreferredSize(Graphics g, Rectangle bounds, ThemeSizeType type) { if (this.currentElement == null || this.currentHTheme == IntPtr.Zero) { return(Size.Empty); } RadHdcWrapper radHdcWrapper = new RadHdcWrapper(g, false); IntPtr hdc = radHdcWrapper.GetHdc(); NativeMethods.SIZE psz = new NativeMethods.SIZE(); UXTheme.GetThemePartSize(this.currentHTheme, hdc, this.currentElement.Part, this.currentElement.State, IntPtr.Zero, type, psz); radHdcWrapper.Dispose(); return(new Size(psz.cx, psz.cy)); }
private void PaintNative(Bitmap bitmap, byte opacity) { IntPtr hdcDestination = NativeMethods.GetDC(IntPtr.Zero); IntPtr hdcSource = NativeMethods.CreateCompatibleDC(hdcDestination); IntPtr hdcBitmap = IntPtr.Zero; IntPtr previousBitmap = IntPtr.Zero; try { hdcBitmap = bitmap.GetHbitmap(Color.FromArgb(0)); previousBitmap = NativeMethods.SelectObject(hdcSource, hdcBitmap); NativeMethods.SIZE size = new NativeMethods.SIZE(bitmap.Width, bitmap.Height); NativeMethods.POINT source = new NativeMethods.POINT(0, 0); NativeMethods.POINT destination = new NativeMethods.POINT(Left, Top); NativeMethods.BLENDFUNCTION blend = new NativeMethods.BLENDFUNCTION(); blend.BlendOp = NativeMethods.AC_SRC_OVER; blend.BlendFlags = 0; blend.SourceConstantAlpha = opacity; blend.AlphaFormat = NativeMethods.AC_SRC_ALPHA; NativeMethods.UpdateLayeredWindow( Handle, hdcDestination, ref destination, ref size, hdcSource, ref source, 0, ref blend, 2); } catch (Exception) { return; } finally { NativeMethods.ReleaseDC(IntPtr.Zero, hdcDestination); if (hdcBitmap != IntPtr.Zero) { NativeMethods.SelectObject(hdcSource, previousBitmap); NativeMethods.DeleteObject(hdcBitmap); } NativeMethods.DeleteDC(hdcSource); } }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods static internal bool IsGripPresent(IntPtr hwnd, bool onStatusBar) { NativeMethods.Win32Rect client = new NativeMethods.Win32Rect(); if (!Misc.GetClientRectInScreenCoordinates(hwnd, ref client)) { return(false); } // According to the documentation of GetClientRect, the left and top members are zero. So if // they are negitive the control must be minimized, therefore the grip is not present. if (client.left < 0 && client.top < 0) { return(false); } NativeMethods.SIZE sizeGrip = GetGripSize(hwnd, onStatusBar); if (!onStatusBar) { // When not on a status bar the grip should be out side of the client area. sizeGrip.cx *= -1; sizeGrip.cy *= -1; } if (Misc.IsLayoutRTL(hwnd)) { int x = client.left + (int)(sizeGrip.cx / 2); int y = client.bottom - (int)(sizeGrip.cy / 2); int hit = Misc.ProxySendMessageInt(hwnd, NativeMethods.WM_NCHITTEST, IntPtr.Zero, NativeMethods.Util.MAKELPARAM(x, y)); return(hit == NativeMethods.HTBOTTOMLEFT); } else { int x = client.right - (int)(sizeGrip.cx / 2); int y = client.bottom - (int)(sizeGrip.cy / 2); int hit = Misc.ProxySendMessageInt(hwnd, NativeMethods.WM_NCHITTEST, IntPtr.Zero, NativeMethods.Util.MAKELPARAM(x, y)); return(hit == NativeMethods.HTBOTTOMRIGHT); } }
/// <summary> /// <para> /// [See win32 equivalent.] /// </para> /// </summary> public Size GetPartSize(IDeviceContext dc, Rectangle bounds, ThemeSizeType type) { if (dc == null) { throw new ArgumentNullException(nameof(dc)); } //valid values are 0x0 to 0x2 if (!ClientUtils.IsEnumValid(type, (int)type, (int)ThemeSizeType.Minimum, (int)ThemeSizeType.Draw)) { throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(ThemeSizeType)); } NativeMethods.SIZE size = new NativeMethods.SIZE(); using (WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper(dc, AllGraphicsProperties)) { HandleRef hdc = new HandleRef(wgr, wgr.WindowsGraphics.DeviceContext.Hdc); lastHResult = SafeNativeMethods.GetThemePartSize(new HandleRef(this, Handle), hdc, part, state, new NativeMethods.COMRECT(bounds), type, size); } return(new Size(size.cx, size.cy)); }
protected override void OnPaint(PaintEventArgs e) { var outerBounds = new Rectangle(0, 0, Width, Height); using (var target = new Bitmap(outerBounds.Width, outerBounds.Height, PixelFormat.Format32bppArgb)) { using (var targetGraphics = Graphics.FromImage(target)) { // The top and bottom borders extend over the sides of the window. // The left and right borders do no. This means that we need to // update the bounds to make it seem like the left and right // borders do extend outside of the window. if (Border == DropShadowBorder.Left || Border == DropShadowBorder.Right) { outerBounds = new Rectangle( outerBounds.Left, outerBounds.Top - _borderWidth, outerBounds.Width, outerBounds.Height + _borderWidth * 2 ); } if (Border == DropShadowBorder.Left || Border == DropShadowBorder.Top) { DrawImage( targetGraphics, _imageCache.CornerNW, new Point( outerBounds.Left, outerBounds.Top ) ); } if (Border == DropShadowBorder.Right || Border == DropShadowBorder.Top) { DrawImage( targetGraphics, _imageCache.CornerNE, new Point( outerBounds.Right - _cornerSize, outerBounds.Top ) ); } if (Border == DropShadowBorder.Bottom || Border == DropShadowBorder.Left) { DrawImage( targetGraphics, _imageCache.CornerSW, new Point( outerBounds.Left, outerBounds.Bottom - _cornerSize ) ); } if (Border == DropShadowBorder.Bottom || Border == DropShadowBorder.Right) { DrawImage( targetGraphics, _imageCache.CornerSE, new Point( outerBounds.Right - _cornerSize, outerBounds.Bottom - _cornerSize ) ); } if (Border == DropShadowBorder.Top) { DrawBorder( targetGraphics, _imageCache.BorderN, new Rectangle( outerBounds.Left + _cornerSize, outerBounds.Top, outerBounds.Width - _cornerSize * 2, _borderWidth ) ); } if (Border == DropShadowBorder.Bottom) { DrawBorder( targetGraphics, _imageCache.BorderS, new Rectangle( outerBounds.Left + _cornerSize, outerBounds.Bottom - _borderWidth, outerBounds.Width - _cornerSize * 2, _borderWidth ) ); } if (Border == DropShadowBorder.Left) { DrawBorder( targetGraphics, _imageCache.BorderW, new Rectangle( outerBounds.Left, outerBounds.Top + _cornerSize, _borderWidth, outerBounds.Height - _cornerSize * 2 ) ); } if (Border == DropShadowBorder.Right) { DrawBorder( targetGraphics, _imageCache.BorderE, new Rectangle( outerBounds.Right - _borderWidth, outerBounds.Top + _cornerSize, _borderWidth, outerBounds.Height - _cornerSize * 2 ) ); } } // Get device contexts var screenDc = NativeMethods.GetDC(IntPtr.Zero); var memDc = NativeMethods.CreateCompatibleDC(screenDc); var hBitmap = IntPtr.Zero; var hOldBitmap = IntPtr.Zero; try { // Get handle to the new bitmap and select it into the current device context hBitmap = target.GetHbitmap(Color.FromArgb(0)); hOldBitmap = NativeMethods.SelectObject(memDc, hBitmap); // Set parameters for layered window update var newSize = new NativeMethods.SIZE(target.Size); // Size window to match bitmap var sourceLocation = new NativeMethods.POINT(Point.Empty); var newLocation = new NativeMethods.POINT(Location); // Same as this window var blend = new NativeMethods.BLENDFUNCTION { BlendOp = NativeMethods.AC_SRC_OVER, // Only works with a 32bpp bitmap BlendFlags = 0, // Always 0 SourceConstantAlpha = 255, // Set to 255 for per-pixel alpha values AlphaFormat = NativeMethods.AC_SRC_ALPHA // Only works when the bitmap contains an alpha channel }; // Update the window NativeMethods.UpdateLayeredWindow( Handle, screenDc, ref newLocation, ref newSize, memDc, ref sourceLocation, 0, ref blend, NativeMethods.ULW_ALPHA ); } finally { // Release device context NativeMethods.ReleaseDC(IntPtr.Zero, screenDc); if (hBitmap != IntPtr.Zero) { NativeMethods.SelectObject(memDc, hOldBitmap); NativeMethods.DeleteObject(hBitmap); // Remove bitmap resources } NativeMethods.DeleteDC(memDc); } } }
public static extern int GetThemePartSize(HandleRef hTheme, HandleRef hdc, int iPartId, int iStateId, [In] NativeMethods.COMRECT prc, System.Windows.Forms.VisualStyles.ThemeSizeType eSize, [Out] NativeMethods.SIZE psz);
public static extern bool SetViewportExtEx(HandleRef hDC, int x, int y, NativeMethods.SIZE size);
public static extern bool SetWindowExtEx(HandleRef hDC, int x, int y, [In, Out] NativeMethods.SIZE size);
/// <include file='doc\VisualStyleRenderer.uex' path='docs/doc[@for="VisualStyleRenderer.GetPartSize1"]/*' /> /// <devdoc> /// <para> /// [See win32 equivalent.] /// </para> /// </devdoc> public Size GetPartSize(IDeviceContext dc, Rectangle bounds, ThemeSizeType type) { if( dc == null ){ throw new ArgumentNullException("dc"); } //valid values are 0x0 to 0x2 if (!ClientUtils.IsEnumValid(type, (int)type, (int)ThemeSizeType.Minimum, (int)ThemeSizeType.Draw)) { throw new InvalidEnumArgumentException("type", (int)type, typeof(ThemeSizeType)); } NativeMethods.SIZE size = new NativeMethods.SIZE(); using( WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper( dc, AllGraphicsProperties ) ) { HandleRef hdc = new HandleRef( wgr, wgr.WindowsGraphics.DeviceContext.Hdc ); lastHResult = SafeNativeMethods.GetThemePartSize( new HandleRef( this, Handle ), hdc, part, state, new NativeMethods.COMRECT( bounds ), type, size ); } return new Size(size.cx, size.cy); }
private NativeMethods.SIZE GetExtent() { NativeMethods.SIZE sz = new NativeMethods.SIZE(); _axOleObject.GetExtent(NativeMethods.DVASPECT_CONTENT, sz); return(sz); }
private NativeMethods.SIZE GetExtent() { NativeMethods.SIZE size = new NativeMethods.SIZE(); this._axOleObject.GetExtent(1, size); return(size); }
private void DrawTreeItem(string itemText, int imageIndex, IntPtr dc, NativeMethods.RECT rc, int state, int backColor, int textColor) { NativeMethods.SIZE size = new NativeMethods.SIZE(); NativeMethods.RECT rc2 = new NativeMethods.RECT(); ImageList imagelist = this.ImageList; IntPtr hfontOld = IntPtr.Zero; // Select the font of the dialog, so we don't get the underlined font // when the item is being tracked if ((state & STATE_HOT) != 0) { hfontOld = SafeNativeMethods.SelectObject(new HandleRef(null, dc), new HandleRef(Parent, ((Control)Parent).FontHandle)); } // Fill the background if (((state & STATE_SELECTED) != 0) && (hbrushDither != IntPtr.Zero)) { FillRectDither(dc, rc); SafeNativeMethods.SetBkMode(new HandleRef(null, dc), NativeMethods.TRANSPARENT); } else { SafeNativeMethods.SetBkColor(new HandleRef(null, dc), backColor); SafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_CLIPPED | NativeMethods.ETO_OPAQUE, ref rc, null, 0, null); } // Get the height of the font SafeNativeMethods.GetTextExtentPoint32(new HandleRef(null, dc), itemText, itemText.Length, size); // Draw the caption rc2.left = rc.left + SIZE_ICON_X + 2 * PADDING_HORZ; rc2.top = rc.top + (((rc.bottom - rc.top) - size.cy) >> 1); rc2.bottom = rc2.top + size.cy; rc2.right = rc.right; SafeNativeMethods.SetTextColor(new HandleRef(null, dc), textColor); SafeNativeMethods.DrawText(new HandleRef(null, dc), itemText, itemText.Length, ref rc2, NativeMethods.DT_LEFT | NativeMethods.DT_VCENTER | NativeMethods.DT_END_ELLIPSIS | NativeMethods.DT_NOPREFIX); SafeNativeMethods.ImageList_Draw(new HandleRef(imagelist, imagelist.Handle), imageIndex, new HandleRef(null, dc), PADDING_HORZ, rc.top + (((rc.bottom - rc.top) - SIZE_ICON_Y) >> 1), NativeMethods.ILD_TRANSPARENT); // Draw the hot-tracking border if needed if ((state & STATE_HOT) != 0) { int savedColor; // top left savedColor = SafeNativeMethods.SetBkColor(new HandleRef(null, dc), ColorTranslator.ToWin32(SystemColors.ControlLightLight)); rc2.left = rc.left; rc2.top = rc.top; rc2.bottom = rc.top + 1; rc2.right = rc.right; SafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_OPAQUE, ref rc2, null, 0, null); rc2.bottom = rc.bottom; rc2.right = rc.left + 1; SafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_OPAQUE, ref rc2, null, 0, null); // bottom right SafeNativeMethods.SetBkColor(new HandleRef(null, dc), ColorTranslator.ToWin32(SystemColors.ControlDark)); rc2.left = rc.left; rc2.right = rc.right; rc2.top = rc.bottom - 1; rc2.bottom = rc.bottom; SafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_OPAQUE, ref rc2, null, 0, null); rc2.left = rc.right - 1; rc2.top = rc.top; SafeNativeMethods.ExtTextOut(new HandleRef(null, dc), 0, 0, NativeMethods.ETO_OPAQUE, ref rc2, null, 0, null); SafeNativeMethods.SetBkColor(new HandleRef(null, dc), savedColor); } if (hfontOld != IntPtr.Zero) { SafeNativeMethods.SelectObject(new HandleRef(null, dc), new HandleRef(null, hfontOld)); } }
private static Bitmap GetThemedButtonGlyph( IntPtr themeHandle, int themePartId, int themeStateId, Color backgroundColor, int buttonExtent) { Bitmap bitmap = null; var hScreenDC = IntPtr.Zero; var hBmpDC = IntPtr.Zero; var hBmp = IntPtr.Zero; var hBrush = IntPtr.Zero; try { // get screen device context hScreenDC = NativeMethods.GetDC(IntPtr.Zero); // get the size of the glyph var size = new NativeMethods.SIZE(); var hr = NativeMethods.GetThemePartSize( themeHandle, hScreenDC, themePartId, themeStateId, IntPtr.Zero, NativeMethods.THEME_SIZE.TS_DRAW, ref size); if (hr != NativeMethods.S_OK) { // use default size size.cx = buttonExtent * 2; size.cy = buttonExtent * 2; } // create bitmap compatible with screen hBmpDC = NativeMethods.CreateCompatibleDC(hScreenDC); hBmp = NativeMethods.CreateCompatibleBitmap(hScreenDC, size.cx, size.cy); NativeMethods.SelectObject(hBmpDC, hBmp); // get rect for entire bitmap var rect = NativeMethods.RECT.FromXYWH(0, 0, size.cx, size.cy); // fill bitmap with background color var color = NativeMethods.RGB(backgroundColor.R, backgroundColor.G, backgroundColor.B); hBrush = NativeMethods.CreateSolidBrush(color); NativeMethods.FillRect(hBmpDC, ref rect, hBrush); // draw glyph NativeMethods.DrawThemeBackground(themeHandle, hBmpDC, themePartId, themeStateId, ref rect, IntPtr.Zero); // get bitmap bitmap = Image.FromHbitmap(hBmp); } finally { if (hScreenDC != IntPtr.Zero) { NativeMethods.ReleaseDC(IntPtr.Zero, hScreenDC); } if (hBmpDC != IntPtr.Zero) { NativeMethods.DeleteDC(hBmpDC); } if (hBmp != IntPtr.Zero) { NativeMethods.DeleteObject(hBmp); } if (hBrush != IntPtr.Zero) { NativeMethods.DeleteObject(hBrush); } } return(bitmap); }
int UnsafeNativeMethods.IOleInPlaceSite.Scroll(NativeMethods.SIZE scrollExtant) { return(NativeMethods.S_FALSE); }
private void PaintNative(Bitmap bitmap, byte opacity) { Debug.WriteLine("PaintNative"); IntPtr hdcDestination = NativeMethods.GetDC(IntPtr.Zero); IntPtr hdcSource = NativeMethods.CreateCompatibleDC(hdcDestination); IntPtr hdcBitmap = IntPtr.Zero; IntPtr previousBitmap = IntPtr.Zero; try { hdcBitmap = bitmap.GetHbitmap(Color.FromArgb(0)); previousBitmap = NativeMethods.SelectObject(hdcSource, hdcBitmap); NativeMethods.SIZE size = new NativeMethods.SIZE(bitmap.Width, bitmap.Height); NativeMethods.POINT source = new NativeMethods.POINT(0, 0); NativeMethods.POINT destination = new NativeMethods.POINT(Left, Top); NativeMethods.BLENDFUNCTION blend = new NativeMethods.BLENDFUNCTION(); blend.BlendOp = NativeMethods.AC_SRC_OVER; blend.BlendFlags = 0; blend.SourceConstantAlpha = opacity; blend.AlphaFormat = NativeMethods.AC_SRC_ALPHA; NativeMethods.UpdateLayeredWindow( Handle, hdcDestination, ref destination, ref size, hdcSource, ref source, 0, ref blend, 2); } catch (Exception) { return; } finally { NativeMethods.ReleaseDC(IntPtr.Zero, hdcDestination); if (hdcBitmap != IntPtr.Zero) { NativeMethods.SelectObject(hdcSource, previousBitmap); NativeMethods.DeleteObject(hdcBitmap); } NativeMethods.DeleteDC(hdcSource); } }
public static extern int GetThemePartSize(HandleRef hTheme, HandleRef hdc, int iPartId, int iStateId, [In] NativeMethods.COMRECT prc, ThemeSizeType eSize, [Out] NativeMethods.SIZE psz);
public static extern int GetTextExtentPoint32(IntPtr hdc, [MarshalAs(UnmanagedType.LPWStr)] string lpString, int cbString, out NativeMethods.SIZE lpSize);
public NativeMethods.REBARBANDINFO GetREBARBANDINFO(int index) { NativeMethods.REBARBANDINFO bandINFO = new NativeMethods.REBARBANDINFO(); bandINFO.cbSize = Marshal.SizeOf(typeof(NativeMethods.REBARBANDINFO)); bandINFO.fMask = NativeMethods.RBBIM_STYLE | NativeMethods.RBBIM_ID; if ((bandStyle & TRBBStyle.Break) != 0) { bandINFO.fStyle |= NativeMethods.RBBS_BREAK; } if ((bandStyle & TRBBStyle.ChildEdge) != 0) { bandINFO.fStyle |= NativeMethods.RBBS_CHILDEDGE; } if ((bandStyle & TRBBStyle.FixedBitmap) != 0) { bandINFO.fStyle |= NativeMethods.RBBS_FIXEDBMP; } if ((bandStyle & TRBBStyle.FixedSize) != 0) { bandINFO.fStyle |= NativeMethods.RBBS_FIXEDSIZE; } if ((bandStyle & TRBBStyle.GripperAlways) != 0) { bandINFO.fStyle |= NativeMethods.RBBS_GRIPPERALWAYS; } if ((bandStyle & TRBBStyle.Hidden) != 0) { bandINFO.fStyle |= NativeMethods.RBBS_HIDDEN; } if ((bandStyle & TRBBStyle.VariableHeight) != 0) { bandINFO.fStyle |= NativeMethods.RBBS_VARIABLEHEIGHT; } if ((bandStyle & TRBBStyle.UseChevron) != 0) { bandINFO.fStyle |= NativeMethods.RBBS_USECHEVRON; } if ((bandStyle & TRBBStyle.NoGripper) != 0) { bandINFO.fStyle |= NativeMethods.RBBS_NOGRIPPER; } bandINFO.wID = index; if (!string.IsNullOrEmpty(text)) { bandINFO.fMask |= NativeMethods.RBBIM_TEXT; bandINFO.lpText = Marshal.StringToHGlobalAuto(text); bandINFO.cch = text.Length; } if (imageIndex != -1) { bandINFO.fMask |= NativeMethods.RBBIM_IMAGE; bandINFO.iImage = imageIndex; } if (backgroundColor != Color.Empty) { bandINFO.fMask |= NativeMethods.RBBIM_COLORS; bandINFO.clrBack = NativeMethods.RGB(backgroundColor.R, backgroundColor.G, backgroundColor.B); } if (textgroundColor != Color.Empty) { bandINFO.fMask |= NativeMethods.RBBIM_COLORS; bandINFO.clrFore = NativeMethods.RGB(textgroundColor.R, textgroundColor.G, textgroundColor.B); } if (control != null) { childWidth = control.Width; bandINFO.fMask |= NativeMethods.RBBIM_CHILD; bandINFO.hwndChild = control.Handle; if (childWidth != -1) { bandINFO.fMask |= NativeMethods.RBBIM_CHILDSIZE; bandINFO.cxMinChild = control.Width; bandINFO.cyMinChild = control.Height; if ((bandStyle & TRBBStyle.VariableHeight) != 0) { bandINFO.cyChild = control.Width; bandINFO.cyMaxChild = control.Height; bandINFO.cyIntegral = 1; } } if (control is MenuBox || control is ToolBox) { NativeMethods.SIZE size = new NativeMethods.SIZE(); UnsafeNativeMethods.SendMessage(new HandleRef(control, control.Handle), NativeMethods.TB_GETMAXSIZE, IntPtr.Zero, size); bandINFO.fMask |= NativeMethods.RBBIM_IDEALSIZE; bandINFO.cxIdeal = size.cx; idealWidth = size.cx; } } if (headerWidth != -1) { bandINFO.fMask |= NativeMethods.RBBIM_HEADERSIZE; bandINFO.cxHeader = headerWidth; } if (hbmBack != IntPtr.Zero) { bandINFO.fMask |= NativeMethods.RBBIM_BACKGROUND; bandINFO.hbmBack = hbmBack; } if (width != -1) { bandINFO.fMask |= NativeMethods.RBBIM_SIZE; bandINFO.cx = width; } return(bandINFO); }