Solved

Loading Picture into Memory and API

Posted on 2004-10-19
2
233 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 28

Expert Comment

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

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Windows 10 start screen issues 9 55
passing parameter in sql procedure 9 65
Copy a row 12 64
Copy a range from 1..n excel sheets to one destination sheet 2 57
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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

828 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