DirectDraw problems

I'm making a program that uses direct draw.
It all works ok, with one exception. When i draw things onto the control, they don't appear where they should.

Note: I'm doing this in Windowed Mode, and using a picturebox as the target control.

Here's my initializing code...

DD = created directdraw device.
Ctrl = picturebox control
sMain = surface (primary)
sBack = surface (backbuffer)
sMainDesc = surface description
sBackDesc = surface description



DD.SetCooperativeLevel(Ctrl, CooperativeLevelFlags.Normal)
With sMainDesc
.Clear()
.SurfaceCaps.PrimarySurface =
True
EndWith
sMain =New Surface(sMainDesc, DD)
sMain.Clipper =New Clipper(DD)
sMain.Clipper.Window = Ctrl
sBackDesc.Width = sMain.SurfaceDescription.Width
sBackDesc.Height = sMain.SurfaceDescription.Height
sBackDesc.SurfaceCaps.OffScreenPlain =
True
sBack =New Surface(sBackDesc, DD)


In the MouseMove event of the Picturebox, i update the mouse X Y, and during the renderloop, i draw a box around the mouse location using...



With CurrentTarget
objDestRect = .RectangleToScreen(New Rectangle(New Point(0, 0), .Size))
End
With
sBack.ColorFill(Color.Black)
sBack.DrawBox(x, y, x+32, y+32)
sMain.Draw(objDestRect, sBack, DrawFlags.DoNotWait)



Now all this works fine, however, the output doesn't scale right.
For example, if i say x=128, y=128, and draw a box, the output will be scaled, and will show up more like 100,100.

Now, if i setup the picturebox to be the same size as my current screen resolution, then the locations match up perfectly 1:1. The smaller the picturebox is compared to the screen resolution, the more 'scaled' it is.

In effect, to be clear, if my screen rez is 800x600, and the picturebox size is 400,300; then if i say drawbox (200,300,232,232) would actually render the box at 100,150. (since the picturebox is half the screen rez, then the xy coords are also halved).

Also, visually, it appears scaled. The text, sprites, and other stuff that's drawn on using .DrawFast() is scaled. Text appears smaller, and my rectangle around my mouse will apear smaller then it should.
I've taken other people's simple how-to code, and modified 1 line that draws a bouncing box around the window. All i changed was from .DrawFast() to .DrawBox() and fed the same xy-coords. And the result was the same.

It works OK with .DrawFast, but appears 'scaled' when using .DrawBox() or .DrawLine() and other functions.

[4007 byte] By [Dustin_H] at [2007-12-16]
# 1
Problem solved.

Issue was in the backbuffer creation.

sBackDesc.Width = sMain.SurfaceDescription.Width
sBackDesc.Height = sMain.SurfaceDescription.Height

Should be...

sBackDesc.Width = Ctrl.Width
sBackDesc.Height = Ctrl.Height
Apparently the Front Surface size is created at your monitor resolution, regardless of the window/picturebox's size. If you pass that into the back buffer, then the back buffer size is also too big for your control, and you get scaling errors.

Dustin_H at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...