Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Problem with VB6 + DirectX 7..


DopeyBiach
 Share

Recommended Posts

This is REALLY grating on me. I can't for the life of me figure out what I'm missing here. It's a simple program where a picture is blitted into a picturebox with the black background removed.

When I remove:

```

Or DDBLT_KEYSRC

```

from:

```
DDRVAL = DDS_Primary.Blt(r1, DDS_Buffer, r2, DDBLT_WAIT Or DDBLT_KEYSRC)
```

It then works fine, but that defeats the object as ALL I want to do is simply blit a bmp, to a picturebox, with the background removed.

Here is the source, PLEASE HELP. ![:(](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/sad.png)

```

Option Explicit

Dim DX As New DirectX7

Dim DD As DirectDraw7

Dim DDS_Primary As DirectDrawSurface7

Dim DDS_Buffer As DirectDrawSurface7

Dim DDSD_Primary As DDSURFACEDESC2

Dim DDSD_Buffer As DDSURFACEDESC2

Dim DD_Clipper As DirectDrawClipper

Dim ColorKey As Integer

Dim CKey As DDCOLORKEY

Dim PixelFormat As DDPIXELFORMAT

Dim bInit As Boolean

Private Sub cmdProcess_Click()

Call Blt

End Sub

Private Sub Form_Load()

Init

End Sub

Private Sub Init()

Set DD = DX.DirectDrawCreate("")

Call DD.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL)

DDSD_Primary.lFlags = DDSD_CAPS

DDSD_Primary.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE

Set DDS_Primary = DD.CreateSurface(DDSD_Primary)

DDSD_Buffer.lFlags = DDSD_CAPS

DDSD_Buffer.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN

Set DDS_Buffer = DD.CreateSurfaceFromFile(App.Path & "image.bmp", DDSD_Buffer)

ColorKey = vbBlack

CKey.high = ColorKey

CKey.low = ColorKey

Call DDS_Buffer.SetColorKey(DDCKEY_SRCBLT, CKey)

Set DD_Clipper = DD.CreateClipper(0)

Call DD_Clipper.SetHWnd(picScreen.hWnd)

Call DDS_Primary.SetClipper(DD_Clipper)

bInit = True

End Sub

Private Sub Blt()

If bInit = False Then

Call MsgBox("DirectDraw has not been initialized yet!", vbInformation, "Application Error")

Exit Sub

End If

picScreen.Cls

Dim DDRVAL As Long

Dim r1 As RECT ' Screen

Dim r2 As RECT ' Buffer

Call DX.GetWindowRect(picScreen.hWnd, r1)

With r2

.Bottom = DDSD_Buffer.lHeight

.Right = DDSD_Buffer.lWidth

End With

DDRVAL = DDS_Primary.Blt(r1, DDS_Buffer, r2, DDBLT_WAIT Or DDBLT_KEYSRC)

End Sub

Private Sub picScreen_Paint()

DD.RestoreAllSurfaces

Init

End Sub

```
Link to comment
Share on other sites

I've been there many times already. I've also been to countless forums and other resources.

I'm relatively new to DX7, most of the examples use full screen - which is difficult for me to set back to window in order to get the code to work.

Simple all I want to do. Is with DX7 draw a bitmap to a picture box and remove the background, in a window.

No fullscreen applications or dodgy masking techniques and such, it should be such a simple procedure, yet I really seem to be missing something?

Thank you for the reply, urgh. D:
Link to comment
Share on other sites

I have done. I'm having no luck though, I can't seem to understand why either. If I was getting an error then I would be happy as I'd know where I was going wrong, but I get get nothing.

With DDBLT_KEYSRC there nothing renders at all, yet without DDBLT_KEYSRC it renders fine, but I want transparency. =/

I've been developing at a wicked pace recently, yet something so simple seems to stump me lol.
Link to comment
Share on other sites

Thank you for trying to help, it should be simple, incredibly simple.

As they say though - "It's always the simple things.." ![<_<](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/dry.png)

I've tried so many different ways to do this it's unreal.
Link to comment
Share on other sites

Your color key seems set up fine. Have you tried replacing "DDRVAL =" with "Call"? I think otherwise it should only return a variable with a value of DD_OK or the error code… Really not sure, just tossing an idea.
Link to comment
Share on other sites

Okay the Blt code without DDBLT_KEYSRC:

![](http://freemmorpgmaker.com/uploadfiles/796b6baa05708a264600932fe48c5d0c.png)

There is a simple little button, it's only use is to Blt, when pressed without DDBLT_KEYSRC, it goes from this:

![](http://freemmorpgmaker.com/uploadfiles/8c569011532c4f12a76188ca279677d8.png)

To this - as it should:

![](http://freemmorpgmaker.com/uploadfiles/0ea67468dc1a8daa466dcb615ff58cad.png)

Now when I add DDBLT_KEYSRC (the key is set earlier in the code as you can see, check the original post to see how and where) the Blt code looks like this:

![](http://freemmorpgmaker.com/uploadfiles/d810cec2f079610ddccdfb6f8fd3fa4f.png)

Now - when I press the process button it goes from this:

![](http://freemmorpgmaker.com/uploadfiles/8c569011532c4f12a76188ca279677d8.png)

To this:

![](http://freemmorpgmaker.com/uploadfiles/8c569011532c4f12a76188ca279677d8.png)

Without returning a single error or anything.

I can't for the life of me figure out what exactly I'm doing wrong.

Unless anyone can find a solution maybe a last resort is someone to write a code to od the exact same thing and if it works - provide me with it. Then I should be able to see exactly where I'm going wrong, as it may be small and difficult to find without writing it yourself.

It's going to be something so small and silly, isn't it? ![:(](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/sad.png)

Thanks to all for helping once again.
Link to comment
Share on other sites

doesnt know if this will help but what hapends when you use this instead

```

DDRVAL = DDS_Primary.Blt(r1, DDS_Buffer, r2, DDBLT_KEYSRC Or DDBLT_WAIT)

```

or this

```

DDRVAL = DDS_Primary.Blt(r1, DDS_Buffer, r2, DDBLT_KEYSRC)

```
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...