protected void DrawPanelBorder(DrawItemEventArgs e) { if (!MxTheme.IsAppThemed) { IntPtr hdc = e.Graphics.GetHdc(); try { Interop.SelectClipRgn(hdc, IntPtr.Zero); int index = base.Parent.Panels.IndexOf(this); Interop.RECT lParam = new Interop.RECT(); Interop.SendMessage(base.Parent.Handle, 0x40a, index, ref lParam); Interop.FrameRect(hdc, ref lParam, Interop.GetSysColorBrush(0x10)); } finally { if (hdc != IntPtr.Zero) { e.Graphics.ReleaseHdc(hdc); } } } }
private void DrawFlatCombo() { if (!MxTheme.IsAppThemed || !this._alwaysShowFocusCues) { Interop.RECT rect = new Interop.RECT(); Interop.GetClientRect(base.Handle, ref rect); IntPtr dC = Interop.GetDC(base.Handle); try { int num5; int num6; bool flag = ((this._alwaysShowFocusCues || this._mouseHover) || base.ContainsFocus) && base.Enabled; int horizontalScrollBarArrowWidth = SystemInformation.HorizontalScrollBarArrowWidth; int sysColor = Interop.GetSysColor(15); int bottomRightColor = Interop.GetSysColor(0x10); int topLeftColor = Interop.GetSysColor(20); if (flag) { num5 = bottomRightColor; num6 = topLeftColor; } else { num5 = num6 = sysColor; } this.DrawRectangle(dC, rect.left, rect.top, rect.Width, rect.Height, num5, num6); if ((MxTheme.IsAppThemed && !base.Enabled) && (base.DropDownStyle == ComboBoxStyle.DropDown)) { this.DrawRectangle(dC, rect.left + 2, rect.top + 2, (rect.Width - horizontalScrollBarArrowWidth) - 4, rect.Height - 4, sysColor, sysColor); } rect.left++; rect.top++; rect.right--; rect.bottom--; if (base.Enabled) { num5 = num6 = sysColor; } else { num5 = num6 = topLeftColor; } this.DrawRectangle(dC, rect.left, rect.top, rect.Width, rect.Height, num5, num6); rect.left++; rect.top++; rect.right--; rect.bottom--; rect.left = rect.right - horizontalScrollBarArrowWidth; this.DrawRectangle(dC, rect.left, rect.top, rect.Width, rect.Height, sysColor, sysColor); rect.left++; rect.top++; rect.right--; rect.bottom--; this.DrawRectangle(dC, rect.left, rect.top, rect.Width, rect.Height, sysColor, sysColor); Interop.FillRect(dC, ref rect, (IntPtr) 0x10); this.DrawFlatComboDropDown(dC, ref rect); if (base.Enabled) { if (flag) { rect.top--; rect.bottom++; rect.right++; this.DrawRectangle(dC, rect.left, rect.top, rect.Width, rect.Height, topLeftColor, bottomRightColor); } else { rect.top--; rect.bottom++; this.DrawRectangle(dC, rect.left, rect.top, rect.Width, rect.Height, topLeftColor, topLeftColor); rect.left--; this.DrawRectangle(dC, rect.left, rect.top, rect.Width, rect.Height, topLeftColor, topLeftColor); } } } finally { Interop.ReleaseDC(base.Handle, dC); } } }
protected override void OnPaint(PaintEventArgs e) { try { if (this._paintFrozen == 0) { Rectangle clipRectangle = e.ClipRectangle; if (!this._owner.ContainsFocus) { clipRectangle = base.ClientRectangle; } IntPtr hdc = e.Graphics.GetHdc(); ColorInfo info = this.ColorTable[7]; info.SetupHdc(hdc); Interop.RECT lpRect = new Interop.RECT(0, clipRectangle.Top, this.MarginWidth - 1, clipRectangle.Bottom); Interop.ExtTextOutW(hdc, 0, 0, 2, ref lpRect, IntPtr.Zero, 0, null); lpRect.left = this.MarginWidth - 1; lpRect.right = this.MarginWidth; this.ColorTable[8].SetupHdc(hdc); Interop.ExtTextOutW(hdc, 0, 0, 2, ref lpRect, IntPtr.Zero, 0, null); ColorInfo info3 = this.ColorTable[4]; info3.SetupHdc(hdc); lpRect.left = this.MarginWidth + this._lineNumbersWidth; lpRect.right = lpRect.left + this.MarginPadding; Interop.ExtTextOutW(hdc, 0, 0, 2, ref lpRect, IntPtr.Zero, 0, null); IntPtr hObject = Interop.SelectObject(hdc, this._fontPtr); Interop.SetBkMode(hdc, 2); int num = clipRectangle.Top / this._fontHeight; int lineIndex = num + this.ViewTopLineNumber; int num3 = (clipRectangle.Height + (this._fontHeight - 1)) / this._fontHeight; TextLine next = null; using (TextBufferLocation location = this._buffer.CreateTextBufferLocation(this._location)) { location.GotoLine(lineIndex); next = location.Line; int num4 = 0; int yPos = num * this._fontHeight; for (int i = lineIndex; (num4 < num3) && (next != null); i++) { if (next.AttributesDirty) { location.GotoLine(i); this.ColorizeLine(location); } this.PaintTextLine(next, i, hdc, yPos, this.ViewLeftIndex); next = next.Next; num4++; yPos += this._fontHeight; } } info3.SetupHdc(hdc); lpRect.top = Math.Min(this.VisibleLines, this._buffer.LineCount - this.ViewTopLineNumber) * this._fontHeight; lpRect.left = this.MarginWidth; lpRect.bottom = base.Height - this.HorizontalScrollBarHeight; lpRect.right = base.Width - this.VerticalScrollBarWidth; Interop.ExtTextOutW(hdc, 0, 0, 2, ref lpRect, IntPtr.Zero, 0, null); if (this.LineNumbersVisible) { info.SetupHdc(hdc); int num7 = (this.MarginWidth + this._lineNumbersWidth) - 2; lpRect.top = clipRectangle.Top; lpRect.left = num7; lpRect.right = num7 + 1; Interop.ExtTextOutW(hdc, 0, 0, 2, ref lpRect, IntPtr.Zero, 0, null); } info.SetupHdc(hdc); int height = base.Height; int width = base.Width; lpRect.top = height - this.HorizontalScrollBarHeight; lpRect.left = width - this.VerticalScrollBarWidth; lpRect.right = width; lpRect.bottom = height; if (this.ResizeGripVisible) { Interop.DrawFrameControl(hdc, ref lpRect, 3, 8); } else { Interop.ExtTextOutW(hdc, 0, 0, 2, ref lpRect, IntPtr.Zero, 0, null); } Interop.SelectObject(hdc, hObject); e.Graphics.ReleaseHdc(hdc); if (this._updateCaretOnPaint) { this._updateCaretOnPaint = false; this.UpdateCaret(); } } } catch (Exception) { } }
private unsafe void PaintTextLine(TextLine line, int lineNum, IntPtr hdc, int yPos, int startIndex) { try { if (this.LineNumbersVisible) { this.ColorTable[4].SetupHdc(hdc); string str = (lineNum + 1).ToString(); int length = str.Length; int num2 = (5 - length) * this._fontWidth; Interop.RECT lpRect = new Interop.RECT(this.MarginWidth, yPos, this.MarginWidth + this._lineNumbersWidth, yPos + this._fontHeight); fixed (char* chRef = str.ToCharArray()) { Interop.ExtTextOutW(hdc, this.MarginWidth + num2, yPos, 2, ref lpRect, (IntPtr)chRef, length, null); } } char[] chars = null; byte[] colors = null; if (line.Length > 0) { int num3 = 0; char[] data = line.Data; byte[] attributes = line.Attributes; int capacity = line.Length * 2; StringBuilder builder = new StringBuilder(capacity); MemoryStream stream = new MemoryStream(capacity); for (int i = 0; i < line.Length; i++) { if (data[i] == '\t') { int num6 = this.TabSize - (num3 % this.TabSize); for (int j = 0; j < num6; j++) { if (this._owner.ShowWhitespace) { builder.Append('→'); } else { builder.Append(' '); } stream.WriteByte(attributes[i]); } num3 += num6; } else { if (this._owner.ShowWhitespace && (data[i] == ' ')) { builder.Append('\x00b7'); } else { builder.Append(data[i]); } stream.WriteByte(attributes[i]); num3++; } } stream.WriteByte(attributes[data.Length]); chars = builder.ToString().ToCharArray(); colors = stream.ToArray(); } else { colors = new byte[0]; chars = new char[0]; } if (this._selectionExists) { if (this._selection.IsSingleLine) { if (lineNum == this._selection.Start.LineIndex) { int endIndex = Math.Min(Math.Max(this.GetViewIndex(line, this._selection.Start.ColumnIndex), startIndex), chars.Length); int minLenght = Math.Min(Math.Max(startIndex, this.GetViewIndex(line, this._selection.End.ColumnIndex)), chars.Length); int rectLeft = (this.MarginWidth + this._lineNumbersWidth) + this.MarginPadding; //int textWidth = Math.Max(0, endIndex - startIndex) * this._fontWidth; int textWidth = this.MeasureString(hdc, chars, startIndex, endIndex - startIndex).x; this.PaintColoredText(chars, colors, hdc, rectLeft, rectLeft + textWidth, yPos, startIndex, endIndex, false); rectLeft += textWidth; //textWidth = Math.Max(0, minLenght - endIndex) * this._fontWidth; textWidth = this.MeasureString(hdc, chars, endIndex, minLenght - endIndex).x; this.PaintColoredText(chars, colors, hdc, rectLeft, rectLeft + textWidth, yPos, endIndex, minLenght, true); rectLeft += textWidth; this.PaintColoredText(chars, colors, hdc, rectLeft, base.Width - this.VerticalScrollBarWidth, yPos, minLenght, chars.Length, false); return; } } else { // 已选择文本中的第一行 if (lineNum == this._selection.Start.LineIndex) { int endIndex = Math.Min(Math.Max(this.GetViewIndex(line, this._selection.Start.ColumnIndex), startIndex), chars.Length); int rectLeft = (this.MarginWidth + this._lineNumbersWidth) + this.MarginPadding; // 先画出行前未选中的文本 int textWidth = this.MeasureString(hdc, chars, startIndex, endIndex - startIndex).x; //int textWidth = Math.Max(0, endIndex - startIndex) * this._fontWidth; this.PaintColoredText(chars, colors, hdc, rectLeft, rectLeft + textWidth, yPos, startIndex, endIndex, false); rectLeft += textWidth; // 然后画出选中的文本 textWidth = this.MeasureString(hdc, chars, endIndex, chars.Length - endIndex).x; if (startIndex <= chars.Length) { textWidth += this._fontWidth; } this.PaintColoredText(chars, colors, hdc, rectLeft, rectLeft + textWidth, yPos, endIndex, chars.Length, true); rectLeft += textWidth; this.PaintColoredText(chars, colors, hdc, rectLeft, base.Width - this.VerticalScrollBarWidth, yPos, 0, 0, false); return; } // 已选择文本中的最后一行 if (lineNum == this._selection.End.LineIndex) { int endIndex = Math.Min(Math.Max(this.GetViewIndex(line, this._selection.End.ColumnIndex), startIndex), chars.Length); int rectLeft = (this.MarginWidth + this._lineNumbersWidth) + this.MarginPadding; //int num20 = Math.Max(0, num17 - startIndex) * this._fontWidth; int textWidth = this.MeasureString(hdc, chars, startIndex, endIndex - startIndex).x; this.PaintColoredText(chars, colors, hdc, rectLeft, rectLeft + textWidth, yPos, startIndex, endIndex, true); rectLeft += textWidth; this.PaintColoredText(chars, colors, hdc, rectLeft, base.Width - this.VerticalScrollBarWidth, yPos, endIndex, chars.Length, false); return; } // 选中文本的中间行 if ((lineNum > this._selection.Start.LineIndex) && (lineNum < this._selection.End.LineIndex)) { int rectLeft = (this.MarginWidth + this._lineNumbersWidth) + this.MarginPadding; int textWidth = this.MeasureString(hdc, chars, startIndex, chars.Length - startIndex).x; if (startIndex <= chars.Length) { textWidth += this._fontWidth; } this.PaintColoredText(chars, colors, hdc, rectLeft, rectLeft + textWidth, yPos, startIndex, chars.Length, true); rectLeft += textWidth; this.PaintColoredText(chars, colors, hdc, rectLeft, base.Width - this.VerticalScrollBarWidth, yPos, 0, 0, false); return; } } } startIndex = Math.Min(startIndex, chars.Length); this.PaintColoredText(chars, colors, hdc, (this.MarginWidth + this._lineNumbersWidth) + this.MarginPadding, base.Width - this.VerticalScrollBarWidth, yPos, startIndex, chars.Length, false); } catch (Exception) { throw; } }
protected override void OnPaint(PaintEventArgs e) { int nFormat = 0x40; switch (this.TextAlign) { case ContentAlignment.TopLeft: nFormat = nFormat; goto Label_009A; case ContentAlignment.TopCenter: nFormat |= 1; goto Label_009A; case (ContentAlignment.TopCenter | ContentAlignment.TopLeft): goto Label_009A; case ContentAlignment.TopRight: nFormat |= 2; goto Label_009A; case ContentAlignment.MiddleLeft: nFormat |= 4; goto Label_009A; case ContentAlignment.MiddleCenter: nFormat |= 5; goto Label_009A; case ContentAlignment.MiddleRight: nFormat |= 6; goto Label_009A; case ContentAlignment.BottomLeft: nFormat |= 8; goto Label_009A; case ContentAlignment.BottomCenter: nFormat |= 9; break; case ContentAlignment.BottomRight: nFormat |= 10; goto Label_009A; } Label_009A: using (Brush brush = new SolidBrush(this.BackColor)) { e.Graphics.FillRectangle(brush, base.ClientRectangle); } IntPtr hdc = e.Graphics.GetHdc(); IntPtr hObject = this.Font.ToHfont(); try { IntPtr ptr3 = Interop.SelectObject(hdc, hObject); Interop.RECT lpRect = new Interop.RECT(0, 0, base.Width, base.Height); Interop.DrawText(hdc, this.Text, this.Text.Length, ref lpRect, 0x400); int num2 = lpRect.bottom - lpRect.top; int top = (base.Height - num2) / 2; lpRect = new Interop.RECT(0, top, base.Width, base.Height); Interop.SetTextColor(hdc, ColorTranslator.ToWin32(this.ForeColor)); Interop.DrawText(hdc, this.Text, this.Text.Length, ref lpRect, nFormat); Interop.SelectObject(hdc, ptr3); } finally { e.Graphics.ReleaseHdc(hdc); } }
private void DrawRectangle(IntPtr hdc, int x, int y, int cx, int cy, int topLeftColor, int bottomRightColor) { Interop.RECT lpRect = new Interop.RECT(); Interop.SetBkColor(hdc, topLeftColor); lpRect.left = x; lpRect.top = y; lpRect.right = (cx - 1) + x; lpRect.bottom = 1 + y; Interop.ExtTextOut(hdc, 0, 0, 2, ref lpRect, null, 0, null); lpRect.left = x; lpRect.top = y; lpRect.right = 1 + x; lpRect.bottom = (cy - 1) + y; Interop.ExtTextOut(hdc, 0, 0, 2, ref lpRect, null, 0, null); Interop.SetBkColor(hdc, bottomRightColor); lpRect.left = (x + cx) - 1; lpRect.top = y; lpRect.right = x + cx; lpRect.bottom = cy + y; Interop.ExtTextOut(hdc, 0, 0, 2, ref lpRect, null, 0, null); lpRect.left = x; lpRect.top = (y + cy) - 1; lpRect.right = x + cx; lpRect.bottom = cy + y; Interop.ExtTextOut(hdc, 0, 0, 2, ref lpRect, null, 0, null); }
public DCMapping(HandleRef hDC, Rectangle bounds) { if (hDC.Handle == IntPtr.Zero) { throw new ArgumentNullException(nameof(hDC)); } bool success; NativeMethods.POINT viewportOrg = new NativeMethods.POINT(); IntPtr hOriginalClippingRegion = IntPtr.Zero; _translatedBounds = bounds; _graphics = null; _dc = DeviceContext.FromHdc(hDC.Handle); _dc.SaveHdc(); // Retrieve the x-coordinates and y-coordinates of the viewport origin for the specified device context. success = SafeNativeMethods.GetViewportOrgEx(hDC, viewportOrg); Debug.Assert(success, "GetViewportOrgEx() failed."); // Create a new rectangular clipping region based off of the bounds specified, shifted over by the x & y specified in the viewport origin. IntPtr hClippingRegion = Interop.Gdi32.CreateRectRgn(viewportOrg.x + bounds.Left, viewportOrg.y + bounds.Top, viewportOrg.x + bounds.Right, viewportOrg.y + bounds.Bottom); Debug.Assert(hClippingRegion != IntPtr.Zero, "CreateRectRgn() failed."); try { // Create an empty region oriented at 0,0 so we can populate it with the original clipping region of the hDC passed in. hOriginalClippingRegion = Interop.Gdi32.CreateRectRgn(0, 0, 0, 0); Debug.Assert(hOriginalClippingRegion != IntPtr.Zero, "CreateRectRgn() failed."); // Get the clipping region from the hDC: result = {-1 = error, 0 = no region, 1 = success} per MSDN int result = Interop.Gdi32.GetClipRgn(hDC, hOriginalClippingRegion); Debug.Assert(result != -1, "GetClipRgn() failed."); // Shift the viewpoint origint by coordinates specified in "bounds". NativeMethods.POINT lastViewPort = new NativeMethods.POINT(); success = SafeNativeMethods.SetViewportOrgEx(hDC, viewportOrg.x + bounds.Left, viewportOrg.y + bounds.Top, lastViewPort); Debug.Assert(success, "SetViewportOrgEx() failed."); Interop.RegionType originalRegionType; if (result != 0) { // Get the origninal clipping region so we can determine its type (we'll check later if we've restored the region back properly.) Interop.RECT originalClipRect = new Interop.RECT(); originalRegionType = Interop.Gdi32.GetRgnBox(hOriginalClippingRegion, ref originalClipRect); Debug.Assert(originalRegionType != Interop.RegionType.ERROR, "ERROR returned from SelectClipRgn while selecting the original clipping region.."); if (originalRegionType == Interop.RegionType.SIMPLEREGION) { // Find the intersection of our clipping region and the current clipping region (our parent's) // Returns a NULLREGION, the two didn't intersect. // Returns a SIMPLEREGION, the two intersected // Resulting region (stuff that was in hOriginalClippingRegion AND hClippingRegion is placed in hClippingRegion Interop.RegionType combineResult = Interop.Gdi32.CombineRgn(hClippingRegion, hClippingRegion, hOriginalClippingRegion, Interop.Gdi32.CombineMode.RGN_AND); Debug.Assert((combineResult == Interop.RegionType.SIMPLEREGION) || (combineResult == Interop.RegionType.NULLREGION), "SIMPLEREGION or NULLREGION expected."); } } else { // If there was no clipping region, then the result is a simple region. // We don't need to keep track of the original now, since it is empty. Interop.Gdi32.DeleteObject(hOriginalClippingRegion); hOriginalClippingRegion = IntPtr.Zero; originalRegionType = Interop.RegionType.SIMPLEREGION; } // Select the new clipping region; make sure it's a SIMPLEREGION or NULLREGION Interop.RegionType selectResult = Interop.Gdi32.SelectClipRgn(hDC, hClippingRegion); Debug.Assert((selectResult == Interop.RegionType.SIMPLEREGION || selectResult == Interop.RegionType.NULLREGION), "SIMPLEREGION or NULLLREGION expected."); } catch (Exception ex) when(!ClientUtils.IsSecurityOrCriticalException(ex)) { _dc.RestoreHdc(); _dc.Dispose(); } finally { // Delete the new clipping region, as the clipping region for the HDC is now set // to this rectangle. Hold on to hOriginalClippingRegion, as we'll need to restore // it when this object is disposed. success = Interop.Gdi32.DeleteObject(hClippingRegion) != Interop.BOOL.FALSE; Debug.Assert(success, "DeleteObject(hClippingRegion) failed."); if (hOriginalClippingRegion != IntPtr.Zero) { success = Interop.Gdi32.DeleteObject(hOriginalClippingRegion) != Interop.BOOL.FALSE; Debug.Assert(success, "DeleteObject(hOriginalClippingRegion) failed."); } } }
protected override void OnPaint(PaintEventArgs e) { Graphics graphics = e.Graphics; Rectangle captionRectangle = this.CaptionRectangle; bool containsFocus = base.ContainsFocus; graphics.FillRectangle(SystemBrushes.Control, e.ClipRectangle); IntPtr hdc = graphics.GetHdc(); try { // NOTE: // ����ʹ��DC_SMALLCAP��, ��win7�µĹ��ߴ��ڱ�����������, ����Ϊ // ���������ֲ����� //int nFlags = DC_GRADIENT | DC_TEXT | DC_SMALLCAP; int nFlags = DC_GRADIENT | DC_TEXT; if (containsFocus) { nFlags |= DC_ACTIVE; } Interop.RECT rect = new Interop.RECT(captionRectangle.Left, captionRectangle.Top, captionRectangle.Right + 1, captionRectangle.Bottom); Interop.DrawCaption(base.Handle, hdc, ref rect, nFlags); } finally { if (hdc != IntPtr.Zero) { graphics.ReleaseHdc(hdc); } } }
/// <summary> /// Discover the docking location of the Windows taskbar. /// </summary> /// <returns>The screen edge where the taskbar is docked.</returns> private Dock GetDocking(out Interop.RECT bounds) { Interop.APPBARDATA data = new Interop.APPBARDATA(); data.cbSize = Marshal.SizeOf(data); using (HelperWindow window = new HelperWindow()) { data.hWnd = window.Handle; Interop.SHAppBarMessage((int)Interop.ABMessage.ABM_GETTASKBARPOS, ref data); } bounds = data.rc; return (Dock)data.uEdge; }
/// <summary> /// Determine the screen bounding rectangle of the NotifyIcon native window. /// </summary> /// <param name="handle"></param> /// <returns></returns> private Rectangle GetScreenRect(IntPtr handle) { // find the system tray by its well known name IntPtr tray = Interop.FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", 0); if (tray == IntPtr.Zero) { return Rectangle.Empty; } // the find system tray toolbar contained within the tray window traybar = IntPtr.Zero; Interop.EnumChildWindows(tray, new Interop.EnumChildProc(FilterWindows), 0); if (traybar.Equals(IntPtr.Zero)) { return Rectangle.Empty; } Interop.RECT rect = new Interop.RECT(); // get the window rectangle of the notify icon; this is local-relative coordinates // with top/left at 0,0 and right/bottom equal to width/height. if (Interop.GetWindowRect(handle, ref rect) == 0) { return Rectangle.Empty; } // translate the local-relative window rectangle to screen coordinates if (Interop.MapWindowPoints(traybar, IntPtr.Zero, ref rect, 2) == 0) { return Rectangle.Empty; } return new Rectangle( rect.left, rect.top, // x, y rect.right - rect.left, // width rect.bottom - rect.top); // height }
public void ScrollRectIntoView(IElement element, Interop.RECT rect) { Interop.IHTMLElement pIElement = element.GetBaseElement(); ds.ScrollRectIntoView(pIElement, rect); }
public Interop.RECT TransformRect(Interop.RECT pRect, Interop.COORD_SYSTEM eSource, Interop.COORD_SYSTEM eDestination, IElement element) { Interop.IHTMLElement pIElement = ((IElement)element).GetBaseElement(); ds.TransformRect(ref pRect, eSource, eDestination, pIElement); return(pRect); }
// ported form VB6 (Ctls\PortUtil\StdCtl.cpp:6176) private unsafe bool DICopy(HandleRef hdcDest, IntPtr hdcSrc, Interop.RECT rect, bool bStretch) { long i; // Get the bitmap from the DC by selecting in a 1x1 pixel temp bitmap IntPtr hNullBitmap = SafeNativeMethods.CreateBitmap(1, 1, 1, 1, IntPtr.Zero); if (hNullBitmap == IntPtr.Zero) { return(false); } try { IntPtr hBitmap = Interop.Gdi32.SelectObject(hdcSrc, hNullBitmap); if (hBitmap == IntPtr.Zero) { return(false); } // Restore original bitmap Interop.Gdi32.SelectObject(hdcSrc, hBitmap); NativeMethods.BITMAP bmp = new NativeMethods.BITMAP(); if (UnsafeNativeMethods.GetObject(new HandleRef(null, hBitmap), Marshal.SizeOf(bmp), bmp) == 0) { return(false); } NativeMethods.BITMAPINFO_FLAT lpbmi = new NativeMethods.BITMAPINFO_FLAT { bmiHeader_biSize = Marshal.SizeOf <NativeMethods.BITMAPINFOHEADER>(), bmiHeader_biWidth = bmp.bmWidth, bmiHeader_biHeight = bmp.bmHeight, bmiHeader_biPlanes = 1, bmiHeader_biBitCount = bmp.bmBitsPixel, bmiHeader_biCompression = NativeMethods.BI_RGB, bmiHeader_biSizeImage = 0, //Not needed since using BI_RGB bmiHeader_biXPelsPerMeter = 0, bmiHeader_biYPelsPerMeter = 0, bmiHeader_biClrUsed = 0, bmiHeader_biClrImportant = 0, bmiColors = new byte[NativeMethods.BITMAPINFO_MAX_COLORSIZE * 4] }; // Include the palette for 256 color bitmaps long iColors = 1 << (bmp.bmBitsPixel * bmp.bmPlanes); if (iColors <= 256) { byte[] aj = new byte[Marshal.SizeOf <NativeMethods.PALETTEENTRY>() * 256]; SafeNativeMethods.GetSystemPaletteEntries(hdcSrc, 0, (int)iColors, aj); fixed(byte *pcolors = lpbmi.bmiColors) { fixed(byte *ppal = aj) { NativeMethods.RGBQUAD * prgb = (NativeMethods.RGBQUAD *)pcolors; NativeMethods.PALETTEENTRY *lppe = (NativeMethods.PALETTEENTRY *)ppal; // Convert the palette entries to RGB quad entries for (i = 0; i < (int)iColors; i++) { prgb[i].rgbRed = lppe[i].peRed; prgb[i].rgbBlue = lppe[i].peBlue; prgb[i].rgbGreen = lppe[i].peGreen; } } } } // Allocate memory to hold the bitmap bits long bitsPerScanLine = bmp.bmBitsPixel * (long)bmp.bmWidth; long bytesPerScanLine = (bitsPerScanLine + 7) / 8; long totalBytesReqd = bytesPerScanLine * bmp.bmHeight; byte[] lpBits = new byte[totalBytesReqd]; // Get the bitmap bits int diRet = SafeNativeMethods.GetDIBits(hdcSrc, hBitmap, 0, bmp.bmHeight, lpBits, ref lpbmi, NativeMethods.DIB_RGB_COLORS); if (diRet == 0) { return(false); } // Set the destination coordiates depending on whether stretch-to-fit was chosen int xDest, yDest, cxDest, cyDest; if (bStretch) { xDest = rect.left; yDest = rect.top; cxDest = rect.right - rect.left; cyDest = rect.bottom - rect.top; } else { xDest = rect.left; yDest = rect.top; cxDest = bmp.bmWidth; cyDest = bmp.bmHeight; } // Paint the bitmap int iRet = SafeNativeMethods.StretchDIBits(hdcDest, xDest, yDest, cxDest, cyDest, 0, 0, bmp.bmWidth, bmp.bmHeight, lpBits, ref lpbmi, NativeMethods.DIB_RGB_COLORS, NativeMethods.SRCCOPY); if (iRet == NativeMethods.GDI_ERROR) { return(false); } } finally { Interop.Gdi32.DeleteObject(hNullBitmap); } return(true); }
public static extern bool DrawFrameControl(HandleRef hDC, ref Interop.RECT rect, int type, int state);
public static extern bool GetClientRect(HandleRef hWnd, ref Interop.RECT rect);
public static extern bool AdjustWindowRectEx(ref Interop.RECT lpRect, int dwStyle, bool bMenu, int dwExStyle);
public static extern bool ValidateRect(HandleRef hWnd, ref Interop.RECT rect);
protected void RenderText(ElementRenderData renderData, Color textColor) { IntPtr graphicsHandle = renderData.GraphicsHandle; IntPtr hObject = Interop.SelectObject(graphicsHandle, renderData.FontHandle); int nBkMode = Interop.SetBkMode(graphicsHandle, 1); int color = Interop.SetTextColor(graphicsHandle, ColorTranslator.ToWin32(textColor)); try { Point location = this.ContentBounds.Location; location.Offset(renderData.ScrollPosition.X, renderData.ScrollPosition.Y); Interop.RECT lpRect = new Interop.RECT(0, 0, 0, 0); Interop.ExtTextOut(graphicsHandle, location.X, location.Y, 0, ref lpRect, this.Text, this.Text.Length, null); } finally { Interop.SelectObject(graphicsHandle, hObject); Interop.SetBkMode(graphicsHandle, nBkMode); Interop.SetTextColor(graphicsHandle, color); } }
public static extern int FillRect(HandleRef hdc, ref Interop.RECT rect, HandleRef hbrush);
private void DrawFlatTextBox() { if (!MxTheme.IsAppThemed) { Interop.RECT rect = new Interop.RECT(); Interop.GetWindowRect(base.Handle, ref rect); IntPtr windowDC = Interop.GetWindowDC(base.Handle); try { int num4; int num5; bool flag = ((this._alwaysShowFocusCues || this._mouseHover) || base.ContainsFocus) && base.Enabled; int sysColor = Interop.GetSysColor(15); int num2 = Interop.GetSysColor(0x10); int num3 = Interop.GetSysColor(20); rect.bottom -= rect.top; rect.right -= rect.left; rect.left = 0; rect.top = 0; if (flag) { num4 = num2; num5 = num3; } else { num4 = num5 = sysColor; } this.DrawRectangle(windowDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, num4, num5); rect.left++; rect.top++; rect.right--; rect.bottom--; if (base.Enabled && (flag || !base.ReadOnly)) { num4 = num5 = sysColor; } else { num4 = num5 = num3; } this.DrawRectangle(windowDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, num4, num5); } finally { Interop.ReleaseDC(base.Handle, windowDC); } } }
public static extern bool LPtoDP(HandleRef hDC, ref Interop.RECT lpRect, int nCount);
private void InitializeComboBoxes() { int wParam = -1; foreach (ToolBarButton button in base.Buttons) { wParam++; ComboBoxToolBarButton button2 = button as ComboBoxToolBarButton; if ((button2 != null) && button2.Visible) { MxComboBox comboBox; Panel comboBoxHolder; Interop.RECT lParam = new Interop.RECT(); Interop.SendMessage(base.Handle, 0x41d, wParam, ref lParam); if (base.RecreatingHandle) { comboBoxHolder = button2.ComboBoxHolder; comboBox = button2.ComboBox; button2.SetParentRecreating(false); } else { comboBoxHolder = new Panel(); button2.ComboBoxHolder = comboBoxHolder; comboBox = button2.CreateComboBox(); } int height = comboBox.Height; int y = (lParam.Height - height) / 2; comboBox.SetBounds(1, y, lParam.Width - 2, height); comboBoxHolder.Controls.Add(comboBox); base.Controls.Add(comboBoxHolder); Interop.SetWindowPos(comboBoxHolder.Handle, IntPtr.Zero, lParam.left, lParam.top, lParam.Width, lParam.Height, 0x54); if ((button2.ToolTipText != null) && (button2.ToolTipText.Length != 0)) { IntPtr hWnd = Interop.SendMessage(base.Handle, 0x423, 0, 0); if (hWnd != IntPtr.Zero) { Interop.TOOLINFO toolinfo = new Interop.TOOLINFO(); toolinfo.uFlags = 0x11; toolinfo.hwnd = toolinfo.uId = comboBox.Handle; toolinfo.lpszText = button2.ToolTipText; Interop.SendMessage(hWnd, Interop.TTM_ADDTOOL, 0, toolinfo); } } this.OnComboBoxCreated(new ToolBarComboBoxButtonEventArgs(button2)); } } }
public static extern int ScrollWindowEx(HandleRef hWnd, int nXAmount, int nYAmount, NativeMethods.COMRECT rectScrollRegion, ref Interop.RECT rectClip, HandleRef hrgnUpdate, ref Interop.RECT prcUpdate, int flags);
private unsafe void PaintColoredText(char[] chars, byte[] colors, IntPtr hdc, int rectLeft, int rectRight, int yPos, int startIndex, int endIndex, bool selected) { if ((chars == null) || (chars.Length <= 0)) { this.ColorTable[0].SetupHdc(hdc); Interop.RECT lpRect = new Interop.RECT(rectLeft, yPos, rectRight, yPos + this._fontHeight); Interop.ExtTextOutW(hdc, 0, 0, 2, ref lpRect, IntPtr.Zero, 0, null); } else { // 清空行末空间颜色 if ((endIndex - startIndex) >= 0) { Interop.RECT rect = new Interop.RECT(rectLeft + ((endIndex - startIndex) * this._fontWidth), yPos, rectRight, yPos + this._fontHeight); this.ColorTable[colors[chars.Length]].SetupHdc(hdc); Interop.ExtTextOutW(hdc, 0, 0, 2, ref rect, IntPtr.Zero, 0, null); } // 开始把字符串画到控件上 Interop.RECT textRect = new Interop.RECT(rectLeft, yPos, rectLeft, yPos + this._fontHeight); int startColumnIndex = startIndex; int curColumnIndex = startColumnIndex; int count = 0; while (startColumnIndex < endIndex) { int colorIndex = colors[startColumnIndex]; while ((curColumnIndex < endIndex) && (colors[curColumnIndex] == colorIndex)) { curColumnIndex++; } IntPtr zero = IntPtr.Zero; try { ColorInfo info2 = this.ColorTable[colorIndex]; ColorInfo info3 = info2; if (selected) { if (this._owner.ContainsFocus && (this._owner.ActiveView == this)) { info2 = this.ColorTable[5]; } else { info2 = this.ColorTable[6]; } } if (info3.IsStyledFont) { zero = info2.SetupHdc(hdc, this.GetStyledFont(info3.Bold, info3.Italic)); } else { info2.SetupHdc(hdc); } count = curColumnIndex - startColumnIndex; string text = new string(chars, startColumnIndex, count); Interop.SIZE size = new Interop.SIZE(); bool ret = Interop.GetTextExtentPoint32W(hdc, text, count, ref size); textRect.left = textRect.right; textRect.right += size.x ; fixed (char* chRef = chars) { char* chPtr = chRef; chPtr += startColumnIndex; Interop.ExtTextOutW(hdc, textRect.left, yPos, 2, ref textRect, (IntPtr) chPtr, count, null); } continue; } finally { startColumnIndex = curColumnIndex; if (zero != IntPtr.Zero) { Interop.SelectObject(hdc, zero); } } } } }
public static extern bool ScrollWindow(HandleRef hWnd, int nXAmount, int nYAmount, ref Interop.RECT rectScrollRegion, ref Interop.RECT rectClip);
protected void Invalidate() { if (base.Parent.IsHandleCreated) { Interop.RECT lParam = new Interop.RECT(); int index = base.Parent.Panels.IndexOf(this); if (Interop.SendMessage(base.Parent.Handle, 0x40a, index, ref lParam) != 0) { base.Parent.Invalidate(Rectangle.FromLTRB(lParam.left, lParam.top, lParam.right, lParam.bottom)); } } }
public static extern bool DrawEdge(HandleRef hDC, ref Interop.RECT rect, int edge, int flags);
internal void RenderFocusCues(ElementRenderData renderData) { Rectangle focusBounds = this.FocusBounds; if (!focusBounds.IsEmpty) { focusBounds.Offset(renderData.ScrollPosition.X, renderData.ScrollPosition.Y); Interop.RECT r = new Interop.RECT(focusBounds.Left, focusBounds.Top, focusBounds.Right, focusBounds.Bottom); Interop.DrawFocusRect(renderData.GraphicsHandle, ref r); } }
protected override void WndProc(ref Message m) { if ((!MxTheme.IsAppThemed || !this._alwaysShowFocusCues) && this._flatAppearance) { if (m.Msg == 15) { this.DefWndProc(ref m); this.DrawFlatCombo(); return; } if ((m.Msg == 0x20) && (base.DropDownStyle != ComboBoxStyle.DropDownList)) { Interop.RECT rect = new Interop.RECT(); Interop.GetWindowRect(base.Handle, ref rect); int messagePos = Interop.GetMessagePos(); if (Interop.PtInRect(ref rect, messagePos & 0xffff, messagePos >> 0x10)) { this._mouseHover = true; this.DrawFlatCombo(); } } } if (m.Msg == 0x2111) { switch ((((int) m.WParam) >> 0x10)) { case 6: this.OnTextUpdated(EventArgs.Empty); break; case 8: this.OnCloseDropDown(EventArgs.Empty); break; } } base.WndProc(ref m); }