We help IT Professionals succeed at work.
Get Started

Rendering a background image in C# using Win32 API - BitBlt

Last Modified: 2013-12-21
Hi All,
I am trying to render an API image to a background (image) memory location then use that image as a source for a BitBlt API call.
In my former life as a VB6 programmer I could simply render the image to a PictureBox (located off screen) with AutoRedraw = True.
I realize that this wasn't 'technically' rendering to memory but it served the purpose of giving me an 'off screen' intermediate memory location that had a HDC handle so I could use the hidden image as a source for BitBit.

I now find myself in the .NET - C# (C sharp) world trying to accomplish this same feat.
I can render from the EM_Message to an intermediate picture box but if it is not located in a visable area of the screen, it will not render.  This method acts like the old VB6 PictureBox with AutoRedrw = False.

I made a stab it it below....

1st I create a memory bitmap called intImage...
            Bitmap intImage = new Bitmap(533, 165);
then get a handle to it...
            IntPtr memHDC = intImage.GetHbitmap();

I have a feeling that maybe I am not creating a 'Graphic' but I am unsure how to do that?

Or maybe I just missing something simple that would allow me to render an API painted image in the background.

FYI - Note: I am using EM_FORMATRANGE (below) to render the initial image and it works fine when rendered to a PictureBox.
    //Render the selected RTF text into the tempPicBox hdc (from FORMATRANGE structure)
            res = SendMessage(Handle, EM_FORMATRANGE, wparam, lparam);

Thank You in advance for your time and kind assistance.
Watch Question
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE