public GraphicsPlus(HDC hdc) { GpGraphics Graphics = new GpGraphics(); lastResult = NativeMethods.GdipCreateFromHDC(hdc, out Graphics); SetNativeGraphics(Graphics); }
public GraphicsPlus(HDC hdc, HANDLE hdevice) { GpGraphics Graphics = new GpGraphics(); lastResult = NativeMethods.GdipCreateFromHDC2(hdc, hdevice, out Graphics); SetNativeGraphics(Graphics); }
public static extern bool TransparentBlt(HDC hdcDest, int xDest, int yDest, int cxDest, int cyDest, HDC hdcSrc, int xSrc, int ySrc, int cxSrc, int cySrc, COLORREF crTransparent);
public static extern bool SetWorldTransform(HDC hdc, ref XFORM xf);
public static extern int SetStretchBltMode(HDC hdc, int nMode);
public static extern COLORREF SetBkColor(HDC hdc, COLORREF crBack);
public static extern bool ModifyWorldTransform(HDC hdc, ref XFORM xf, uint nMode);
public static extern bool GetTextExtentPoint32(HDC hdc, string stText, int cch, out SIZE size);
/// <summary> /// Creates a bitmap compatible with the given <see cref="HDC"/> via <see cref="CreateCompatibleBitmap"/> /// </summary> public CreateBitmapScope(HDC hdc, int cx, int cy) { HBitmap = CreateCompatibleBitmap(hdc, cx, cy); }
public static extern BOOL GetTextExtentPoint32W(HDC hdc, string lpString, int c, ref Size psizl);
public static extern CharacterSetUint GetTextCharsetInfo(HDC hdc, out FONTSIGNATURE lpSig, uint dwFlags = 0);
public static extern CharacterSetUint GetTextCharset(HDC hdc);
public static extern bool GetCharWidth(HDC hdc, uint iFirst, uint iLast, [Out] int[] lpBuffer);
public static extern BOOL PatBlt(HDC hdc, int x, int y, int w, int h, ROP rop);
public static extern BOOL GetTextMetricsW(HDC hdc, ref TEXTMETRICW lptm);
public static extern int GetDeviceCaps(HDC hDC, int nIndex);
public static extern uint GetTextAlign(HDC hdc);
public static extern void DrawStatusText(HDC hdc, in RECT lprc, string pszText, SBT uFlags);
public static extern bool GetWorldTransform(HDC hdc, out XFORM xf);
public static extern HGDIOBJ GetCurrentObject(HDC hdc, OBJ type);
public static extern bool ReleaseDC(HWND hwnd, HDC hdc);
public static extern BOOL UpdateLayeredWindow(HWND hWnd, HDC hdcDst, POINT pptDst, SIZE psize, HDC hdcSrc, POINT pptSrc, COLORREF crKey, BLENDFUNCTION pblend, DWORD dwFlags);
public static extern bool SetBrushOrgEx(HDC hdc, int xOrg, int yOrg, out POINT pt);
public static extern BOOL BitBlt(HDC hdc, int x, int y, int cx, int cy, HDC hdcSrc, int x1, int y1, DWORD rop);
public static extern int SetTextCharacterExtra(HDC hdc, int nCharExtra);
public static extern int ReleaseDC(HWND hWnd, HDC hDC);
public static bool TextOut(HDC hdc, int x, int y, string stText) { return TextOut(hdc, x, y, stText, stText.Length); }
public unsafe static extern BOOL GetViewportOrgEx(HDC hdc, out Point lppoint);
public static GraphicsPlus FromHDC(HDC hdc) { return new GraphicsPlus(hdc); }
public void GetClipRgn_NoRegion() { // Create a bitmap using the screen's stats HDC hdc = CreateCompatibleDC((HDC) default);
public HRESULT Draw([NativeTypeName("DWORD")] uint dwDrawAspect, [NativeTypeName("LONG")] int lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, [NativeTypeName("LPCRECTL")] RECTL *lprcBounds, [NativeTypeName("LPCRECTL")] RECTL *lprcWBounds, [NativeTypeName("BOOL (*)(ULONG_PTR) __attribute__((stdcall))")] delegate *unmanaged <nuint, BOOL> pfnContinue, [NativeTypeName("ULONG_PTR")] nuint dwContinue)
public unsafe static extern BOOL SetWindowOrgEx(HDC hdc, int x, int y, Point *lppt);
public static extern COLORREF GetPixel(HDC hdc, int x, int y);
public HRESULT RepaintVideo(HWND hwnd, HDC hdc) { return(((delegate * unmanaged <IVMRWindowlessControl *, HWND, HDC, int>)(lpVtbl[11]))((IVMRWindowlessControl *)Unsafe.AsPointer(ref this), hwnd, hdc)); }
public static bool GetTextExtentPoint32(HDC hdc, string stText, out SIZE size) { return GetTextExtentPoint32(hdc, stText, stText.Length, out size); }
public static extern HDC CreateCompatibleDC(HDC hDC);
public static extern bool GetTextMetrics(HDC hdc, out TEXTMETRIC lptm);
public unsafe static extern BOOL OffsetViewportOrgEx(HDC hdc, int x, int y, Point *lppt);
public static extern int IntersectClipRect(HDC hdc, int nLeft, int nTop, int nRight, int nBottom);
public static extern HBITMAP CreateDIBSection(HDC hdc, IntPtr pbmi, DIB usage, byte[] ppvBits, IntPtr hSection, uint offset);
public static extern bool Rectangle(HDC hdc, int nLeft, int nTop, int nRight, int nBottom);
public HRESULT SelectPicture(HDC hDCIn, HDC *phDCOut, HHANDLE *phBmpOut) { return(((delegate * unmanaged <IPicture2 *, HDC, HDC *, HHANDLE *, int>)(lpVtbl[11]))((IPicture2 *)Unsafe.AsPointer(ref this), hDCIn, phDCOut, phBmpOut)); }
public static extern HGDIOBJ SelectObject(HDC hdc, HGDIOBJ hobj);
public HRESULT Render(HDC hDC, [NativeTypeName("LONG")] int x, [NativeTypeName("LONG")] int y, [NativeTypeName("LONG")] int cx, [NativeTypeName("LONG")] int cy, [NativeTypeName("OLE_XPOS_HIMETRIC")] int xSrc, [NativeTypeName("OLE_YPOS_HIMETRIC")] int ySrc, [NativeTypeName("OLE_XSIZE_HIMETRIC")] int cxSrc, [NativeTypeName("OLE_YSIZE_HIMETRIC")] int cySrc, [NativeTypeName("LPCRECT")] RECT *pRcWBounds) { return(((delegate * unmanaged <IPicture2 *, HDC, int, int, int, int, int, int, int, int, RECT *, int>)(lpVtbl[8]))((IPicture2 *)Unsafe.AsPointer(ref this), hDC, x, y, cx, cy, xSrc, ySrc, cxSrc, cySrc, pRcWBounds)); }
public static extern int SetBkMode(HDC hdc, int iBkMode);
public static extern COLORREF GetTextColor(HDC hdc);
public static extern int SetGraphicsMode(HDC hdc, int nMode);
public static extern BOOL LPtoDP(HDC hdc, ref RECT lppt, int c);
public static extern uint SetTextAlign(HDC hdc, uint nMode);
public static extern HDC CreateEnhMetaFile(HDC hdc, string lpFilename, ref RECT lprc, string lpDesc);
public static extern COLORREF SetTextColor(HDC hdc, COLORREF crText);
internal bool RenderPage(Graphics gfx) { //delete m_RenderContext; //m_RenderContext = new HdcRenderContext(wdc.m_hdc); gfx.TranslateTransform(-this.posOffset.X, -this.posOffset.Y); gfx.SetClip(new Rectangle(this.virtualPage.X + 1, this.virtualPage.Y + 1, this.virtualPage.Width - 1, this.virtualPage.Height - 1)); float scaleX = virtualPage.Width / this.pageSize.Width; float scaleY = virtualPage.Height / this.pageSize.Height; //gfx.SetSmoothingMode(SmoothingModeAntiAlias); //PaintBackground(gfx); #if DRAW_BMP Matrix matrix = new Matrix(); matrix.Translate(virtualPage.X, virtualPage.Y); matrix.Translate(-this.posOffset.X, -this.posOffset.Y); //matrix.Scale(scaleX, scaleY); gfx.Transform = matrix; #if DRAW_X gfx.DrawLine(Pens.Red, 0, 0, pageSize.Width, pageSize.Height); gfx.DrawLine(Pens.Red, 0, pageSize.Height, pageSize.Width, 0); #endif if (this.renderEvent != null) { Bitmap bmp = new Bitmap(this.virtualPage.Width, this.virtualPage.Height, gfx); Graphics gfx2 = Graphics.FromImage(bmp); gfx2.Clear(this.pageColor); gfx2.ScaleTransform(scaleX, scaleY); gfx2.SmoothingMode = SmoothingMode.HighQuality; XGraphics xgfx = XGraphics.FromGraphics(gfx2, new XSize(this.pageSize.Width, this.pageSize.Height)); try { this.renderEvent(xgfx); gfx.DrawImage(bmp, 0, 0); } finally { bmp.Dispose(); } } #else Matrix matrix = new Matrix(); matrix.Translate(virtualPage.X, virtualPage.Y); matrix.Translate(-this.posOffset.X, -this.posOffset.Y); matrix.Scale(scaleX, scaleY); gfx.Transform = matrix; #if DRAW_X gfx.DrawLine(Pens.Red, 0, 0, pageSize.Width, pageSize.Height); gfx.DrawLine(Pens.Red, 0, pageSize.Height, pageSize.Width, 0); #endif if (this.renderEvent != null) { gfx.SmoothingMode = SmoothingMode.HighQuality; XGraphics xgfx = XGraphics.FromGraphics(gfx, new XSize(this.pageSize.Width, this.pageSize.Height)); try { this.renderEvent(xgfx); } catch (Exception ex) { MessageBox.Show(ex.Message, "Exception"); } } #endif // Old C++ stuff, may be useful later... #if false switch (m_mode) { case RenderModeDirect: { delete m_PreviewMetafile; m_PreviewMetafile = NULL; float cxPage = Metric::MillimetersToPoints(m_dimPage.cx / 10.0f); float cyPage = Metric::MillimetersToPoints(m_dimPage.cy / 10.0f); float scaleX = virtualPage.Width / cxPage; float scaleY = virtualPage.Height / cyPage; Graphics gfx(m_RenderContext); gfx.SetSmoothingMode(SmoothingModeAntiAlias); PaintBackground(gfx, &virtualPage); Matrix matrix; matrix.Translate((float)virtualPage.X, (float)virtualPage.Y); matrix.Translate((float)-m_posOffset.x, (float)-m_posOffset.y); matrix.Scale(scaleX, scaleY); m_RenderContext->SetDefaultViewMatrix(&matrix); gfx.ResetTransform(); if (m_PreviewRenderer && m_PreviewRenderer->CanRender()) { m_PreviewRenderer->Render(&gfx, m_Page); } } break; case RenderModeMetafile: { Graphics gfx(m_RenderContext); if (m_PreviewMetafile == NULL) { float cxPage = Metric::MillimetersToPoints(m_dimPage.cx / 10.0f); float cyPage = Metric::MillimetersToPoints(m_dimPage.cy / 10.0f); //float factor = 72.0f / 96.0f; Rect rcLogicalPage(0, 0, (int)cxPage, (int)cyPage); RectF rcFLogicalPage(0, 0, cxPage, cyPage); //DeviceName devname; //DESKTOP::QueryDefaultPrinter(devname); //HACK DRUCKER MUSS DA SEIN! //DeviceMode devmode(devname); //HDC hdc = ::CreateIC(devname.m_szDriver, devname.m_szDevice, devname.m_szOutput, devmode.m_pdm); //HDC hdc = m_Graphics->GetHDC(); //HDC hdc = ::GetDC(NULL); HDC hdc = ::CreateIC("DISPLAY", NULL, NULL, NULL); float dpiX = gfx.GetDpiX(); float dpiY = gfx.GetDpiY(); // Even Petzold would be surprised about that... // Display | LaserJet // DPI 96 : 120 | 300 // physical device size in MM --------------------------------------------- int horzSizeMM = ::GetDeviceCaps(hdc, HORZSIZE); // = 330 : 254 | 198 (not 210) int vertSizeMM = ::GetDeviceCaps(hdc, VERTSIZE); // = 254 : 203 | 288 (hot 297) // device size in pixel int horzSizePixel = ::GetDeviceCaps(hdc, HORZRES); // = 1280 : 1280 | 4676 int vertSizePixel = ::GetDeviceCaps(hdc, VERTRES); // = 1024 : 1024 | 6814 // 'logical' device resolution in DPI int logResX = ::GetDeviceCaps(hdc, LOGPIXELSX); // = 96 : 120 | 600 int logResY = ::GetDeviceCaps(hdc, LOGPIXELSY); // = 96 : 120 | 600 // physical pixel size in .01 MM units // accidentally(?) the result of GetPhysicalDimension! //float X1 = 100.0f * horzSizeMM / horzSizePixel; // = 25.781250 : 19.843750 | 4.2343884 //float Y1 = 100.0f * vertSizeMM / vertSizePixel; // = 24.804688 : 19.824219 | 4.2265925 // now we can get the 'physical' device resolution... float phyResX = horzSizePixel / (horzSizeMM / 25.4f); // = 98.521210 : 128.00000 | 599.85052 float phyResY = vertSizePixel / (vertSizeMM / 25.4f); // = 102.40000 : 128.12611 | 600.95691 // ...and rescale the size of the meta rectangle. float magicX = logResX / phyResX; // = 0.97440946 : 0.93750000 | 1.0002491 float magicY = logResY / phyResY; // = 0.93750000 : 0.93657720 | 0.99840766 // use A4 page in point // adjust size of A4 page so that meta file fits with DrawImage... RectF rcMagic(0, 0, magicX *cxPage, magicY *cyPage); m_PreviewMetafile = new Metafile(hdc, rcMagic, MetafileFrameUnitPoint, EmfTypeEmfPlusOnly, L"some description"); SizeF size; float horzRes, vertRes; float height, width; MetafileHeader metafileHeader; // GetPhysicalDimension returns physical size of a pixel in .01 MM units!! m_PreviewMetafile->GetPhysicalDimension(&size); horzRes = (float)m_PreviewMetafile->GetHorizontalResolution(); vertRes = (float)m_PreviewMetafile->GetVerticalResolution(); height = (float)m_PreviewMetafile->GetHeight(); width = (float)m_PreviewMetafile->GetWidth(); m_PreviewMetafile->GetMetafileHeader(&metafileHeader); Graphics gfxMf(m_PreviewMetafile); dpiX = gfxMf.GetDpiX(); dpiY = gfxMf.GetDpiY(); m_PreviewMetafile->GetPhysicalDimension(&size); horzRes = (float)m_PreviewMetafile->GetHorizontalResolution(); vertRes = (float)m_PreviewMetafile->GetVerticalResolution(); height = (float)m_PreviewMetafile->GetHeight(); width = (float)m_PreviewMetafile->GetWidth(); m_PreviewMetafile->GetMetafileHeader(&metafileHeader); gfxMf.SetPageUnit(UnitPoint); if (m_PreviewRenderer && m_PreviewRenderer->CanRender()) { m_PreviewRenderer->Render(&gfxMf, m_Page); } ::DeleteDC(hdc); } if (m_PreviewMetafile) { gfx.SetSmoothingMode(SmoothingModeAntiAlias); PaintBackground(gfx, &virtualPage); //Matrix matrix(1, 0, 0, 1, (float) - m_posOffset.x, (float) - m_posOffset.y); m_RenderContext->SetDefaultViewMatrix(&matrix); gfx.ResetTransform(); gfx.DrawImage(m_PreviewMetafile, virtualPage); } } break;
public static extern bool StretchBlt(HDC hdcDest, int xDest, int yDest, int cxDest, int cyDest, HDC hdcSrc, int xSrc, int ySrc, int cxSrc, int cySrc, uint nCmd);
public unsafe static extern BOOL EnumEnhMetaFile( HDC hdc, HENHMETAFILE hmf, Enhmfenumproc proc, IntPtr param, RECT *lpRect);
public static extern bool TextOut(HDC hdc, int x, int y, string stText, int cch);
public unsafe static partial BOOL SetViewportOrgEx(HDC hdc, int x, int y, Point *lppt);
public void ReleaseHDC(HDC hdc) { SetStatus(NativeMethods.GdipReleaseDC(nativeGraphics, hdc)); }
public static extern BKMODE SetBkMode(HDC hdc, BKMODE mode);
public static GraphicsPlus FromHDC(HDC hdc, HANDLE hdevice) { return new GraphicsPlus(hdc, hdevice); }
public static partial BOOL EndPath(HDC hdc);