コード例 #1
0
        void CreateGraphicsFromNativeHdc(int width, int height)
        {
            //3. create original dc from memory dc and prepare background
            var orgHdc = MyWin32.CreateCompatibleDC(IntPtr.Zero);

            bgBmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            hbmp  = bgBmp.GetHbitmap();
            MyWin32.SelectObject(orgHdc, hbmp);
            MyWin32.PatBlt(orgHdc, 0, 0, width, height, MyWin32.WHITENESS);
            MyWin32.SetBkMode(orgHdc, MyWin32._SetBkMode_TRANSPARENT);
            //4. font
            hFont = MyWin32.SelectObject(orgHdc, hFont);
            //5. region
            hRgn = MyWin32.CreateRectRgn(0, 0, width, height);
            MyWin32.SelectObject(orgHdc, hRgn);
            //6. create graphics from hdc***

            gx = System.Drawing.Graphics.FromHdc(orgHdc);
            this.originalHdc = orgHdc;
        }