Posted on 2003-03-12
Medium Priority
Last Modified: 2013-12-25
Hello. I'm trying to copy BMP data (32bpp) from an array to an StdPicture object. I found many examples on the net, I see that using GDI I can easily handle this, but...

hBmp=CreateCompatibleBitmap(hDCSrc, Width, Height)
hBmpPrev=SelectObject(hDCMemory, hBmp)

Call BitBlt(hDCMemory, 0, 0, Width, Height, hDCSrc, 0, 0, vbSrcCopy)
hBmp=SelectObject(hDCMemory, hBmpPrev)

This code looks very fast, but what are all those handles? I mean, I create a compatible DC, right? Then I should set the array to that DC, using SetBitmapBits(). And then I call OleCreatePictureIndirect(). But in the example above this doesn't happens. It gets a DC from 0 (???), then selects something, getting another handle... An then uses BitBlt (not SetBitmapBits), and again, SelectObject. What are all those handles? I'll be glad if you could explain me those API calls, or at least what the a handle is. Thanks.

Question by:AnitraZ
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

JohnMcCann earned 150 total points
ID: 8123327
A handle is simply a long value pointing to the memory address of an object e.g. A handle to a window or device context (hWnd, hDC).

Basically the code you have posted Creates a DC in memory and paints the screen onto it.

Code Explained.


Get the device context of the desktop.


creates a device context in memory

hBmp=CreateCompatibleBitmap(hDCSrc, Width, Height)

Creates a compatible BitMap.

hBmpPrev=SelectObject(hDCMemory, hBmp)

Select the Bitmap into the Memory DC

Call BitBlt(hDCMemory, 0, 0, Width, Height, hDCSrc, 0, 0, vbSrcCopy)

Paints (BitBlts) the Memory DC with the contents of the screen.

hBmp=SelectObject(hDCMemory, hBmpPrev)

Sets the MemoryDc with its original bitmap.  This is done to ensure the original bitmap is destroyed.

I hope that is of some help.

John McCann

Author Comment

ID: 8123771
K, thank you. Now the code looks different, I hope I'll success in moving the bitmap for array to StdPicture.


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question