Problem with HDC (Not sure where to start)

Last post 05-22-2006 11:49 AM by danc00per. 0 replies.

Sort Posts:

  • Problem with HDC (Not sure where to start)

    05-22-2006, 11:49 AM
    • Member
      120 point Member
    • danc00per
    • Member since 04-12-2006, 6:39 AM
    • Posts 24
    Hi,

    I am trying to get Acrobat to draw a page into a System.Drawing.Image.HBitmap class, I have the following code which so far only grabs the desktop window, I need to get an HDC somehow but am not sure exactly where and how I should be doing it:

                _pdpage = (CAcroPDPage)_pddoc.AcquirePage(page);

                /// This line is the problem:
                IntPtr hDC = new IntPtr();

                AcroRect pdfRect = new AcroRect();

                pdfRect.Left = 0;
                pdfRect.right = 200;
                pdfRect.Top = 0;
                pdfRect.bottom = 200;
               
                _pdpage.DrawEx(0, hDC.ToInt32(), pdfRect, 0, 0, 100);

                IntPtr hMemDC = PlatformInvokeGDI32.CreateCompatibleDC(hDC);
                IntPtr hBitmap = PlatformInvokeGDI32.CreateCompatibleBitmap(hDC, pdfRect.right, pdfRect.bottom);

                IntPtr hOld = (IntPtr)PlatformInvokeGDI32.SelectObject(hMemDC, hBitmap);
                PlatformInvokeGDI32.BitBlt(hMemDC, 0, 0, pdfRect.right, pdfRect.bottom, hDC, 0, 0, PlatformInvokeGDI32.SRCCOPY);
                PlatformInvokeGDI32.SelectObject(hMemDC, hOld);
                PlatformInvokeGDI32.DeleteDC(hMemDC);
                Bitmap newBmp = System.Drawing.Image.FromHbitmap(hBitmap);
               
                PlatformInvokeGDI32.DeleteObject(hBitmap);
                GC.Collect();

                newBmp.Save("C:\\test.bmp");

    Now all that code does is draw the desktop window to the file, I need to know where I'm going wrong.

    Thanks in advance!
Page 1 of 1 (1 items)