Results 1 to 2 of 2

Thread: I feel so stupid asking this..

  1. #1

    Thread Starter
    Addicted Member tonyenkiducx's Avatar
    Join Date
    Oct 2000
    Location
    London England
    Posts
    147
    All I want to do is load an image into a window, then places transparent BMP's over it. I will be changing the images every 5 seconds, but there all hard coded graphics from set files. Whats the best way to do this?

    And I dont want smooth animation, it must clearly change from one graphics to the next.

  2. #2

    Thread Starter
    Addicted Member tonyenkiducx's Avatar
    Join Date
    Oct 2000
    Location
    London England
    Posts
    147
    Ok, I figured out I can do it with directdraw, can someone read this and suggest if Im doing it right, it looks good, and it all moves smoothely.

    <code>

    Option Compare Text

    'DirectX Inits
    'Registry constants
    Private Const KEY_READ = 131097
    Private Const REG_SZ = 1
    Private Const HKEY_LOCAL_MACHINE = &H80000002
    'Registry API's
    Private Declare Function RegConnectRegistry Lib "advapi32.dll" Alias "RegConnectRegistryA" (ByVal lpMachineName As String, ByVal hKey As Long, phkResult As Long) As Long
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
    Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
    'Module level variables
    Dim objDX As New DirectX7
    Dim objDD As DirectDraw7
    Dim objDDSurf As DirectDrawSurface7
    Dim objDDPrimSurf As DirectDrawSurface7
    Dim PrimaryViewSurface1 As DDSURFACEDESC2
    Dim PrimaryViewSurface2 As DDSURFACEDESC2
    Dim ddClipper As DirectDrawClipper
    Dim bInit As Boolean
    'DirectX Inits END

    Private Sub Form_Load()
    init
    End Sub

    Sub init()

    Dim sMedia As String
    'Initialization procedure

    'The empty string parameter means to use the active display driver
    Set objDD = objDX.DirectDrawCreate("")
    'Notice that the show event calls Form_Resize

    'Indicate this app will be a normal windowed app
    'with the same display depth as the current display
    Call objDD.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL)

    'Indicate that the ddsCaps member is valid in this type
    PrimaryViewSurface1.lFlags = DDSD_CAPS
    'Create a primary surface
    PrimaryViewSurface1.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
    'Now we create the primary surface, this is like a canvas for the Blt to paint on.
    Set objDDPrimSurf = objDD.CreateSurface(PrimaryViewSurface1)

    'Now we repeat the creation procedure for the second surface, that will actually contain our graphic
    PrimaryViewSurface2.lFlags = DDSD_CAPS
    PrimaryViewSurface2.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
    Set objDDSurf = objDD.CreateSurfaceFromFile("c:\LOCATION\images\PIC.bmp", PrimaryViewSurface2)

    Set ddClipper = objDD.CreateClipper(0)
    ddClipper.SetHWnd picture1.hWnd
    objDDPrimSurf.SetClipper ddClipper

    'Confirm to the blitter that everything worked OK
    bInit = True

    'Ok now were ready to blit this thing, call the blt procedure
    blt

    End Sub
    Private Sub Form_Resize()
    'The following two lines can be used to make a picture always fit a given area, taken out for testing
    ' picture1.Width = Me.ScaleWidth
    ' picture1.Height = Me.ScaleHeight
    blt
    End Sub

    Sub blt() ' blt'ing the second surface, onto the first is like sticking a stamp onto an envelope

    'Has it been initialized? If not let's get out of this procedure
    If bInit = False Then Exit Sub
    'Some local variables
    Dim ddrval As Long
    Dim r1 As RECT
    Dim r2 As RECT

    'Gets the bounding rect for the entire window handle, stores in r1
    objDX.GetWindowRect picture1.hWnd, r1

    r2.Bottom = PrimaryViewSurface2.lHeight
    r2.Right = PrimaryViewSurface2.lWidth

    ddrval = objDDPrimSurf.blt(r1, objDDSurf, r2, DDBLT_WAIT)

    End Sub
    Private Sub Picture1_Paint()
    'This procedure is called during runtime when the form
    'is moved or resized.
    objDD.RestoreAllSurfaces
    init
    End Sub
    </code>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width