Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Loading Picture into Memory and API

Posted on 2004-10-19
2
Medium Priority
?
255 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 1000 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 28

Expert Comment

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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

885 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