Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Loading Picture into Memory and API

Posted on 2004-10-19
2
Medium Priority
?
250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 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…
Suggested Courses

670 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