?
Solved

Handles

Posted on 2003-03-12
2
Medium Priority
?
363 Views
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...

hDCSrc=GetDC(0)
hDCMemory=CreateCompatibleDC(hDCSrc)
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.

AnitraZ
0
Comment
Question by:AnitraZ
2 Comments
 
LVL 5

Accepted Solution

by:
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.

hDCSrc=GetDC(0)

Get the device context of the desktop.

hDCMemory=CreateCompatibleDC(hDCSrc)

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
0
 

Author Comment

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

AnitraZ
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month12 days, 21 hours left to enroll

578 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