Solved

Loading Picture into Memory and API

Posted on 2004-10-19
2
224 Views
Last Modified: 2010-05-02
I am currently using the TransparentBLT API call to try and make a primitive 2D game. Here is the problem I load the the picture into memory using the IPictureDisp variable type but when I use the handle from the object no graphics are drawn to the surface. I then tried using the GetDC API call and still no graphics. What am I doing wrong?
0
Comment
Question by:sk33v3
2 Comments
 
LVL 32

Accepted Solution

by:
Erick37 earned 250 total points
ID: 12350711
In order to do any drawing you need a Device Context (DC) to draw onto.  A picture object has no DC, only a handle to the bitmap.  A Picturebox or Form have hDC's which you can use in the TransparentBLT call in order to copy your picture.  You can also create a memory DC using API which requires no form or picturebox.

A quick example of using a memory DC to copy a picture to a form:

Option Explicit

Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, _
        ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, _
        ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long


Private Sub Command1_Click()

    Dim pic As StdPicture
    Dim memDC As Long
   
    'Load a picture
    Set pic = LoadPicture("c:\thumb.jpg")
   
    'Create a DC compatible with the screen
    memDC = CreateCompatibleDC(0)
   
    'Select the picture into the DC
    Call SelectObject(memDC, pic.Handle)
   
    'do something with the picture
    'In this case copy it onto the form's DC
    Call BitBlt(Me.hDC, 0, 0, 100, 100, memDC, 0, 0, vbSrcCopy)
   
    '.......
   
    'Done, Clean Up
    Call DeleteDC(memDC)

End Sub


GL!

0
 
LVL 27

Expert Comment

by:Ark
ID: 12352824
Take a look on my sample at http://freevbcode.com/ShowCode.Asp?ID=1501
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now