Solved

Loading Picture into Memory and API

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

747 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

12 Experts available now in Live!

Get 1:1 Help Now