Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Windowed DirectDraw In MDI?


Hey. My program uses an MDI environment, with each file window being a picture box and a few buttons. Previously I've been using BitBlt to draw the interface in the picture box, but I've decided to switch to DirectDraw with the hope that it will speed things up - there's noticeable lag in certain parts of my program, such as scrolling quickly or when I run a timer which checks a fairly large array.

How would I set DirectX7 to draw individually in each window? From the Windowed DirectDraw Tutorial, it seems that the clipper is the only link between the picture box and the primary surface. Another method I could think of is assembling everything from several surfaces into one and using BltToDC. I leaned towards the latter mainly because I don't like defining RECTs, and BltFast doesn't require two RECTs.

Regardless, I attempted to use the BltToDC method at least to test if I was getting DirectDraw to work, and so far nothing is happening. The only thing is that a black box of the right size is appearing on the picture box. Anyone know what my problem is? Here's the relevant code:


Code:
'Main Variables
Dim DX As New DirectX7
Dim DD As DirectDraw7

Dim rollBitmap As DirectDrawSurface7
Dim rollKeys As DirectDrawSurface7
Dim rollBG As DirectDrawSurface7

Dim descRollBitmap As DDSURFACEDESC2
Dim descRollKeys As DDSURFACEDESC2
Dim descRollBG As DDSURFACEDESC2

Code:
Private Sub MDIForm_Load()

maxWidth = Int((Screen.Width / Screen.TwipsPerPixelX) / 256)
maxHeight = Int((Screen.Height / Screen.TwipsPerPixelY) / 144)

Set DD = DX.DirectDrawCreate("") 'Create DirectDraw
Call DD.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL) 'Set Windowed

descRollBitmap.lFlags = DDSD_CAPS
descRollBitmap.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
Set rollBitmap = DD.CreateSurfaceFromFile(App.Path & "pianoroll.bmp", descRollBitmap)

descRollKeys.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
descRollKeys.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
descRollKeys.lWidth = 65
descRollKeys.lHeight = 144
Set rollKeys = DD.CreateSurface(descRollKeys)

descRollBG.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
descRollBG.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
descRollBG.lWidth = (maxWidth + 1) * 256
descRollBG.lHeight = (maxHeight + 1) * 256
Set rollBG = DD.CreateSurface(descRollBG)

Dim key1Rect As RECT
key1Rect.top = 0
key1Rect.Bottom = 12
key1Rect.Left = 0
key1Rect.Right = 65
Dim key2Rect As RECT
key2Rect.top = 12
key2Rect.Bottom = 24
key2Rect.Left = 0
key2Rect.Right = 65
Dim bar1Rect As RECT
bar1Rect.top = 36
bar1Rect.Bottom = 48
bar1Rect.Left = 0
bar1Rect.Right = 256
Dim bar2Rect As RECT
bar2Rect.top = 24
bar2Rect.Bottom = 36
bar2Rect.Left = 0
bar2Rect.Right = 256

Call rollBitmap.BltFast(0, 0, rollKeys, key1Rect, DDBLTFAST_WAIT)
Call rollBitmap.BltFast(0, 12, rollKeys, key2Rect, DDBLTFAST_WAIT)
Call rollBitmap.BltFast(0, 24, rollKeys, key1Rect, DDBLTFAST_WAIT)
Call rollBitmap.BltFast(0, 36, rollKeys, key2Rect, DDBLTFAST_WAIT)
Call rollBitmap.BltFast(0, 48, rollKeys, key1Rect, DDBLTFAST_WAIT)
Call rollBitmap.BltFast(0, 60, rollKeys, key2Rect, DDBLTFAST_WAIT)
Call rollBitmap.BltFast(0, 72, rollKeys, key1Rect, DDBLTFAST_WAIT)
Call rollBitmap.BltFast(0, 84, rollKeys, key1Rect, DDBLTFAST_WAIT)
Call rollBitmap.BltFast(0, 96, rollKeys, key2Rect, DDBLTFAST_WAIT)
Call rollBitmap.BltFast(0, 108, rollKeys, key1Rect, DDBLTFAST_WAIT)
Call rollBitmap.BltFast(0, 120, rollKeys, key2Rect, DDBLTFAST_WAIT)
Call rollBitmap.BltFast(0, 132, rollKeys, key1Rect, DDBLTFAST_WAIT)

Dim temp As RECT
temp.Bottom = 144
temp.Right = 65
Call rollKeys.BltToDC(winRes.pianoKeys.hDC, temp, temp)
winRes.Show




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Windowed Directdraw
i'm learning windowed directx, having trouble:

i downloaded a little example, works fine, until i try to modify it
i want it to NOT stretch the picture over the picturebox, but only take the space it needs and leave the rest gray.
so wat i want is: the same example, but without the image being streched over the whole picturebox, but only taking the space it needs.
i tried modifying the r1 and r2 rect but that didn't work very well.

please have a look

Reinout

Better Way Of Running Directdraw Windowed?
I prefer making my games windowed, for various reasons (not the least of which is it makes it easier to develop them when I can change code on the fly).

I've always set up a front buffer, and back buffer, then used ddobj.SetCooperativeLevel to associate the front buffer with a picturebox on my form. Then, every frame, I render the backbuffer, and then blit it to the frontbuffer when its done.

I'd rather flip than blit, but since I'm running windowed, this isn't an option. Obviously, this huge blit at the end (640x480x4 = over a megabyte of memory copied, half a meg at 16bit) is a big slowdown, especially for slower computers.

I've tried drawing directly to the front buffer, but then my blitting ends up overdrawing everything else on the screen, even when my application is in the background (I've heard about clippers, but I can't seem to get them to work, ugh).

Is there anything I can do to eliminate this huge, wasteful blit from back to front buffer?

Simple Problem With DirectDraw And Windowed Screen
Hi everybody,
I've just started with DirectDraw, and have a small problem. I modified a tutorial file from www.directx4vb.com that displayed some text in fullscreen mode to operate in a windowed mode. It works, but when the window is dragged off the screen, and back onto it, it doesn't redraw the display until the window is fully back onto the screen. I have attached some screenshots so you can understand what I'm saying. Does anyone know how I can solve the problem? The source code is below. Thanks.

frmMain.frm
Option Explicit 'DirectX likes all it's variables to be predefined

Dim binit As Boolean 'A simple flag (true/false) that states whether we've
'initialised or not. If the initialisation is successful this changes to
'true, the program also checks before doing any drawing if this flag is
'true. If the initialisation failed and we try and draw things we'll get
'lots of errors...

Dim dx As New DirectX7 'This is the root object. DirectDraw is created From this
Dim dd As DirectDraw7 'This is DirectDraw, all things DirectDraw come From here
Dim Mainsurf As DirectDrawSurface7 'This holds our bitmap
Dim primary As DirectDrawSurface7 'This surface represents the screen
Dim backbuffer As DirectDrawSurface7 'this describes the primary surface
Dim ddsd1 As DDSURFACEDESC2 'this describes the primary surface
Dim ddsd3 As DDSURFACEDESC2 'this describes the size of the screen
Dim brunning As Boolean 'this is another flag that states whether or not
'the main game loop is running.
Dim CurModeActiveStatus As Boolean 'This checks that we still have the
'correct display mode
Dim bRestore As Boolean 'If we don't have the correct display mode then
'this flag states that we need to restore the display mode

Dim FillRect As RECT
Dim FillRet As Long
Dim FontInfo As New StdFont 'Note the use of "New" - This is very important.

Sub Init()
'On Local Error GoTo errOut 'If there is an error we end the program.

Set dd = dx.DirectDrawCreate("") 'the ("") means that we want the default driver
'Me.Show 'maximises the form and makes sure it's visible

'The first line links the DirectDraw object to our form, It also sets the parameters
'that are to be used - the important ones being DDSCL_FULLSCREEN and DDCSL_EXCLUSIVE. Making it
'exclusive is important, it means that while our application is running nothing else can
'use DirectDraw, and it makes windows give us more time/attention
Call dd.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL) 'DDSCL_FULLSCREEN Or DDSCL_ALLOWMODEX Or DDSCL_EXCLUSIVE) '
'This is where we actually see a change. It states that we want a display mode
'of 640x480 with 16 bit colour (65526 colours). the fourth argument ("0") is the
'refresh rate. leave this to 0 and DirectX will sort out the best refresh rate. It is advised
'that you don't mess about with this variable. the fifth variable is only used when you
'want to use the more advanced resolutions (usually the lower, older ones)...
'Call dd.SetDisplayMode(640, 480, 16, 0, DDSDM_DEFAULT)


'get the screen surface and create a back buffer too
ddsd1.lFlags = DDSD_CAPS 'Or DDSD_BACKBUFFERCOUNT
ddsd1.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE 'Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX
ddsd1.lBackBufferCount = 1
Set primary = dd.CreateSurface(ddsd1)

'Get the backbuffer
'Dim caps As DDSCAPS2

ddsd3.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
ddsd3.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Or DDSCAPS_3DDEVICE
ddsd3.lWidth = 640
ddsd3.lHeight = 480

Set backbuffer = dd.CreateSurface(ddsd3) 'FromFile(App.Path & "ackground.bmp", ddsd2)

'caps.lCaps = DDSCAPS_BACKBUFFER
'Set backbuffer = primary.GetAttachedSurface(caps)
'backbuffer.GetSurfaceDesc ddsd3

'Set up Font information

backbuffer.SetFontTransparency True
backbuffer.SetForeColor RGB(0, 0, 200)


'This is the main loop. It only runs whilst brunning=true
binit = True
'brunning = True
'Do While brunning
blt
' DoEvents 'you MUST have a doevents in the loop, otherwise you'll overflow the
'system (which is bad). All your application does is keep sending messages to DirectX
'and windows, if you dont give them time to complete the operation they'll crash.
'adding doevents allows windows to finish doing things that its doing.
'Loop

errOut: 'If there is an error we want to close the program down straight away.
'MsgBox "Error Loading", 0, 0
'EndIt
End Sub




Sub blt()
'again, this procedure looks fairly simple - it is!
'You should try and keep this procedure as short as possible, and as fast as possible
'On Local Error GoTo errOut 'If there is an error don't do anything - just skip
'the procedure
If binit = False Then Exit Sub 'If we haven't initiaised then don't try anything
'DirectDraw related.

' this will keep us from trying to blt in case we lose the surfaces (alt-tab)
'bRestore = False
'Do Until ExModeActive
' DoEvents
' bRestore = True
'Loop

' if we lost and got back the surfaces, then restore them
DoEvents
If bRestore Then
bRestore = False
dd.RestoreAllSurfaces 'this just re-allocates memory back to us. we must
End If

Dim p1 As POINTS
Dim ret As Integer

'Dim p2 As POINTS
p1.X = 0
p1.Y = 0

If p1.X < 0 Then MsgBox "Off Screen", 0, 0

ret = ClientToScreen(Form1.hWnd, p1)

'ClientToScreen Form1.hWnd, p2

'FillRect.Top = p1.Y: FillRect.Left = p1.X
'FillRect.Bottom = p2.Y: FillRect.Right = p2.X

FillRect.Bottom = 480: FillRect.Right = 640
FillRet = backbuffer.BltColorFill(FillRect, RGB(0, 0, 0))
FontInfo.Bold = True
FontInfo.Size = 20
FontInfo.Name = "Verdana"
backbuffer.SetFont FontInfo
backbuffer.SetForeColor RGB(0, 0, 225)
Call backbuffer.DrawText(10, 10, "DirectX for VB: Drawing Text example.", False)

FontInfo.Bold = False
FontInfo.Size = 20
FontInfo.Name = "Verdana"
backbuffer.SetFont FontInfo
backbuffer.SetForeColor RGB(0, 0, 150)
Call backbuffer.DrawText(10, 35, "Click Screen To Exit", False)

'flip the back buffer to the screen
Dim r2 As RECT 'The bitmap size

r2.Bottom = 480 'ddsd2.lHeight
r2.Right = 640 'ddsd2.lWidth
primary.BltFast p1.X, p1.Y, backbuffer, r2, DDBLTFAST_WAIT


'primary.Flip Nothing, DDFLIP_WAIT

errOut:
End Sub

Sub EndIt()
'This procedure is called at the end of the loop, or whenever there is an error.
'Although you can get away without these few lines it is a good idea to keep them
'as you can get unpredictable results if you leave windows to "clear-up" after you.

'This line restores you back to your default (windows) resolution.
'Call dd.RestoreDisplayMode
'This tells windows/directX that we no longer want exclusive access
'to the graphics features/directdraw
Call dd.SetCooperativeLevel(Me.hWnd, DDSCL_NORMAL)
'Stop the program:
End
End Sub

Private Sub Form_Click()
'Clicking the form will result in the program closing down.
'because the form is maximised (and therefore covers the whole screen)
'where you click is not important.
EndIt
End Sub

Private Sub Form_Load()
'Starts the whole program.
Init
End Sub

Private Sub Form_Paint()
'If windows sends a "paint" message translate this into a call
'to DirectDraw.
blt
End Sub

Function ExModeActive() As Boolean
'This is used to test if we're in the correct resolution.
Dim TestCoopRes As Long

TestCoopRes = dd.TestCooperativeLevel

If (TestCoopRes = DD_OK) Then
ExModeActive = True
Else
ExModeActive = False
End If
End Function

Private Sub Form_Resize()
Dim p1 As POINTS
Dim ret As Integer
p1.X = 0
p1.Y = 0
Dim r2 As RECT 'The bitmap size
r2.Bottom = 480 'ddsd2.lHeight
r2.Right = 640 'ddsd2.lWidth

ret = ClientToScreen(Form1.hWnd, p1)
primary.BltFast p1.X, p1.Y, backbuffer, r2, DDBLTFAST_WAIT
End Sub

Module1.bas
Declare Function ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINTS) As Long

Type POINTS
X As Long
Y As Long
End Type

Windowed DD?
ok heres my issue.

heres what im trying to accompish...

im making a map editor for a game called subspace. its old, and in the old days it only utilized a 1024x1024 array of 16x16 pixel tiles to display the map....aside from a few special tiles.

since then the games client(it is a client server MMPOG) has been recoded and renamed continuum.

conituum will let you use the regular old 190 tile 1024x1024 setup. plus it will allow you to place bitmaps anywhere in the array you want of any size basically within reason(before it starts crashing). and inlude all those in the DL for your level.

with that said....im on the right path and have the program totaly working(as far as display goes, and i have most of the routines thought out. if not implemented allready.

i first started with paintpicture routines. and when it was working like that. i found this blt thing and used that instead. now its still a little slow(and i have read a bit around the forum here and there about this 480 autoredraw. which is my issue exactly.

so i dl a bunch of DD tutorials, and just started messing with the vars and reading the comments

So heres where ive been stuck for a day or two and it agrivates me greatly. so i ask...... how can i have an image as big as picturebox. thats all black. and blt 16x16 tiles onto it THAT DONT STRETCH hehe. there must be something im missing here.

this must be a windowed application memeber, and it doesnt have to loop anthing, it only has to blt when the user moves the scoll bars. all of the images are loaded as invisible picture boxes behind the main sceen with a ID that matches the integers stored in the level file. i may have to read more about the rest of all that myself which is fine. but could someone gimmie a clue maybe? is this even possible with DD? i would certainly think so.

the extra images are all loaded up as well in the same fashion. from thier upper left pixel.

thanks much. heres my main loop for the tiles. none of the image stuff is here. gotta learn to walk before ya try and run eh?


Code:
Private Sub DrawEngine2() 'draws visible map from killer array

picMap.ScaleMode = vbPixels

Dim whereX As Integer ' for tile position on screen
Dim whereY As Integer

Dim Xcounter As Integer 'for draw for next looping
Dim Ycounter As Integer

Dim beginIndexX As Integer 'where to start looking in the array
Dim beginIndexY As Integer

Dim endIndexX As Integer 'where to stop
Dim endIndexY As Integer

beginIndexX = HorzScrollMap.Value 'get current value of scroll bars
beginIndexY = VertScrollMap.Value

endIndexX = HorzScrollMap.Value + CInt(picMap.Width / 16)
endIndexY = VertScrollMap.Value + CInt(picMap.Height / 16)

For Ycounter = beginIndexY To endIndexY

For Xcounter = beginIndexX To endIndexX

If Xcounter <= 1023 And Ycounter <= 1023 Then ' dont attemp to draw it if its off the map
If KillerArray(Xcounter, Ycounter).IsTile = True Then '.........


BitBlt picMap.hdc, whereX, whereY, 16, 16, picTileIMarray(KillerArray(Xcounter, Ycounter).TileID).hdc, 0, 0, vbSrcCopy


End If




End If
whereX = whereX + 16
Next Xcounter
whereX = 0
whereY = whereY + 16
Next Ycounter

If ParentWin.mnuShowGrid.Checked = True Then ' draw a 16x16 grid.
DrawGrid
End If

End Sub

Windowed DX7??
I draw to a picture box, but it seems to use the window coords instead of the picture box coords. Like when I blit to 0,0 it gets clipped because it uses 0,0 of the form not the picture box.

Some code:

Code:
FormLoad()
Set dd = DX.DirectDrawCreate("")
dd.SetCooperativeLevel Me.hWnd, DDSCL_NORMAL
Set CurrentMap = New CMap
CurrentMap.AttachDD dd
CurrentMap.SetupClipper Picture2.hWnd
CurrentMap.DrawMap



//in CMap.cls
Public Function SetupClipper(hwnd As Long)
Set Clipper = DD.CreateClipper(0)
Clipper.SetHWnd hwnd
Primary.SetClipper Clipper
End Function

Private Const START_X As Integer = 500
Private Const START_Y As Integer = 0
Private Function DrawGrid()
Dim layer As Integer
Dim x As Integer
Dim y As Integer
Dim src As RECT
Dim dest As RECT

src.left = 0
src.top = 0
src.right = 64
src.bottom = 31
For layer = 0 To layer_count
drawx = START_X + xoffset
drawy = START_Y + yoffset
For x = 0 To map_width
For y = 0 To map_height
dest.left = drawx
dest.top = drawy
dest.right = dest.left + TILE_W
dest.bottom = dest.top + TILE_H
Primary.Blt dest, Grid, src, DDBLT_KEYSRC Or DDBLT_WAIT
drawx = drawx - (TILE_W / 2)
drawy = drawy + (TILE_H / 2)
Next
drawx = drawx + ((map_height + 2) * (TILE_W / 2))
drawy = drawy - (map_width * (TILE_H / 2))
Next
Next
End Function

I draw in a class which CurrentMap is. Does this cause a problem? If anyone has any ideas please let me know. Thanks.

Dos To Windowed?
Hey,
Is there a way i can take a fullscreen dos game and put it into a window? There is also a windows version of this game but there is no "windowed" option. Is this possible?

Dx8 Windowed Mode
i had previously set up my 3d app to be full screen but for creating a level editor i want to make it windowed. i am using this code in the setup part (the 3d will appear in a picture box on the form)

Dim DispMode As D3DDISPLAYMODE
Dim D3DWindow As D3DPRESENT_PARAMETERS

Set DX = New DirectX8 '//Create Master Object
Set D3D = DX.Direct3DCreate() '//create the Direct3D Interface
Set D3DX = New D3DX8 '//Create helper library...

'DispMode.Format = D3DFMT_X8R8G8B8
D3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, DispMode '//Retrieve the current display Mode

D3DWindow.Windowed = 1 '//Tell it we're using Windowed Mode
D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
D3DWindow.BackBufferFormat = DispMode.Format

Set D3DDevice = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, frmMain.Picture1.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DWindow)

'//Set the vertex shader to use our vertex format
D3DDevice.SetVertexShader Unlit_FVF


D3DDevice.SetRenderState D3DRS_LIGHTING, 1
D3DDevice.SetRenderState D3DRS_AMBIENT, &H202020 (by default it removes all CCW ordered triangles)
D3DDevice.SetRenderState D3DRS_CULLMODE, D3DCULL_NONE

'// enable Z Buffer
D3DDevice.SetRenderState D3DRS_ZENABLE, 1

D3DXMatrixIdentity matWorld
D3DDevice.SetTransform D3DTS_WORLD, matWorld


D3DXMatrixLookAtLH matView, MakeVector(0, 5, 25), MakeVector(0, 0, 0), MakeVector(0, 1, 0)

D3DDevice.SetTransform D3DTS_VIEW, matView

D3DXMatrixPerspectiveFovLH matProj, pi / 4, 1, 0.1, 500
D3DDevice.SetTransform D3DTS_PROJECTION, matProj

--Anyway when i render i only see text and none of the 3d objects
(i have 2 imported .x objects and some square cubes.

Strangely i get a distorted image with this command

D3DXMatrixPerspectiveFovLH matProj, pi / 4, 0.3, 0.1, 75
D3DDevice.SetTransform D3DTS_PROJECTION, matProj

That is the only way anything appears on the screen but the image appears stratched and i dont see all of the images.

What am i doing wrong?

Windowed Mode
I seem to have forgotten how to use windowed mode. I can get the drawline and drawtext functions working, but the 3d does not show up. Does anyone see my error????

http://www.public.asu.edu/~bashc

Windowed Mode
I have a tile editor in windowed mode, and I need to start writing the code for the masked tiles. Its just tiles that overlay ontop of the ground tiles but the black RGB: 0 0 0, is hidden leaving the masked tile. It is pretty easy in fullscreen, but windowed mode seems to be giving me some trouble. Here is my extremely messy and uncommented code, this has mostly just been an experiment for me.


Code:
Option Explicit
Option Explicit



'Main Variables
Dim DX As New DirectX7
Dim DD As DirectDraw7

'The first buffer holds a bitmap. The second "Primary" surface
'represents what appears on screen.
Dim Tiles As DirectDrawSurface7
Dim picBuffer As DirectDrawSurface7
Dim Primary As DirectDrawSurface7
Dim BackBuffer As DirectDrawSurface7
Dim skyTiles As DirectDrawSurface7

'The first desciptor describes the screen
'The second describes the surface that the bitmap will go into.
Dim ddsd1 As DDSURFACEDESC2
Dim ddsd2 As DDSURFACEDESC2

'The clipper handles obscured surfaces and stops our application
'from drawing over the top of other windows.
Dim ddClipper As DirectDrawClipper

Dim tilex As Integer
Dim tiley As Integer

Dim curTileNum As Integer

Dim tilesetx As Integer
Dim tilesety As Integer

Dim map() As Byte
Dim tileset(0, 3) As Byte
Dim dsrcRect() As RECT

Dim mapSizeX As Integer
Dim mapSizeY As Integer

Dim DrawArrayX As Integer
Dim DrawArrayY As Integer

Const Tile_Width As Integer = 24
Const Tile_Height As Integer = 24

'A simple initialization flag.
Dim bInit As Boolean


Private Sub Form_Load()
'Start the ball rolling......
Dim i As Integer
Dim j As Integer

'picBox.Width = 24 * mapSizeX

mapSizeX = mapX
mapSizeY = mapY

VScroll1.Max = 0
HScroll1.Max = 0

If mapSizeX > 25 Then
DrawArrayX = 25
HScroll1.Max = mapSizeX - 25
Else
DrawArrayX = mapSizeX
End If

If mapSizeY > 19 Then
DrawArrayY = 19
VScroll1.Max = mapSizeY - 19
Else
DrawArrayY = mapSizeY
End If

ReDim map(mapSizeX, mapSizeY) As Byte
ReDim dsrcRect(mapSizeX, mapSizeY) As RECT

Randomize
For i = 0 To mapSizeX
For j = 0 To mapSizeY
map(i, j) = 33
Next j
Next i

init
End Sub

Sub init()
Dim CKey As DDCOLORKEY
'On Error GoTo ErrHandler:
'Initialization procedure

'The empty string parameter means to use the active display driver
Set DD = DX.DirectDrawCreate("")

'Indicate this app will be a normal windowed app - not fullscreen.
'with the same display depth as the current display. This can
'be very limiting - The end-user can have the desktop in anything
'from 16 colours to 16 million. To find out what the current depth is
'use:
'dim DeskTopBpp as long
'DesktopBpp = DX.SystemBpp

Call DD.SetCooperativeLevel(picBox.hWnd, DDSCL_NORMAL)




'Indicate that the ddsCaps member is valid in this type
ddsd1.lFlags = DDSD_CAPS
'This surface is the primary surface (what is visible to the user)
ddsd1.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
'You're now creating the primary surface with the surface description you just set
Set Primary = DD.CreateSurface(ddsd1)

'Now let's set the second surface description
ddsd2.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
'This is going to be a plain off-screen surface - ie, to hold a bitmap
ddsd2.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
'Now we create the off-screen surface from the pre-rendered picture
'Set picBuffer = DD.CreateSurfaceFromFile(App.Path & "ackground.bmp", ddsd2)
ddsd2.lWidth = 216
ddsd2.lHeight = 264
Set Tiles = DD.CreateSurfaceFromFile(App.Path & " ileset.bmp", ddsd2)

ddsd2.lWidth = 24
ddsd2.lHeight = 24
Set skyTiles = DD.CreateSurfaceFromFile(App.Path & " ile.bmp", ddsd2)

CKey.high = vbBlack
CKey.low = vbBlack

skyTiles.SetColorKey DDCKEY_SRCBLT, CKey
Tiles.SetColorKey DDCKEY_SRCBLT, CKey
'Creates the clipper, and attaches it to the picturebox and
'the primary surface. This is all that has to be done - the clipper
'itself handles everything else.
Set ddClipper = DD.CreateClipper(0)
ddClipper.SetHWnd picBox.hWnd
Tiles.SetClipper ddClipper
'Yes it has been initialized and is ready to blit
bInit = True

'Ok now were ready to blit this thing, call the blt procedure
'One huge advantage of Windowed mode is that you don't
'have to have a loop, you just call "blt" when you need the
'picture to be updated.

drawMask
bltTiles
calcTiles
Exit Sub
ErrHandler:
MsgBox "Unable to initialize DirectDraw - Closing program", vbInformation, "error"
End
End Sub


Private Sub Form_Unload(Cancel As Integer)
End
End Sub

Private Sub HScroll1_Change()
bltTiles
End Sub

Private Sub picBox_Click()
map(tilex + HScroll1.Value, tiley + VScroll1.Value) = curTileNum
bltTiles
End Sub

Private Sub picBox_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

X = (X / Screen.TwipsPerPixelX)
Y = (Y / Screen.TwipsPerPixelY)

X = X - 12
Y = Y - 12

tilex = X / 24
tiley = Y / 24

tilex = tilex
tiley = tiley

'MsgBox tilex
'MsgBox tiley
End Sub

Private Sub picBox_Paint()
'This procedure is called during runtime when the form
'is moved or resized.
DD.RestoreAllSurfaces
init
bltTiles
End Sub


Private Sub bltTiles()
Dim ddrval As Long
Dim blah As Long

Dim srcRect As RECT

srcRect.Bottom = 24
srcRect.Right = 24

Dim X As Long
Dim Y As Long

X = (frmMain.Left / Screen.TwipsPerPixelX) + picBox.Left + 7
Y = (frmMain.Top / Screen.TwipsPerPixelY) + picBox.Top + 26

Dim i As Integer
Dim j As Integer

Dim row As Integer
Dim tilenum As Integer

Dim fixX
Dim fixY

fixY = (frmMain.Top / Screen.TwipsPerPixelY) + picBox.Top

fixX = ((frmMain.Left / Screen.TwipsPerPixelX) + picBox.Left) + picBox.Width

'Load Map in Array According to Tileset and Make a Rect
For i = 0 To mapSizeX
For j = 0 To mapSizeY

tilenum = map(i, j)

If tilenum < 10 Then
row = 1
End If

If tilenum > 9 Then
row = 2
End If

If tilenum > 19 Then
'MsgBox tilenum
row = 3
End If

If tilenum > 29 Then
row = 4
End If

If tilenum > 39 Then
row = 5
End If

If tilenum > 49 Then
row = 6
End If

If tilenum > 59 Then
row = 7
End If

If tilenum > 69 Then
row = 8
End If

If tilenum > 79 Then
row = 9
End If

If tilenum > 89 Then
row = 10
End If

If tilenum > 99 Then
row = 11
End If

tilenum = tilenum - ((row * 10) - 10)

dsrcRect(i, j).Bottom = Tile_Height * row
dsrcRect(i, j).Top = (Tile_Height * row) - 24
dsrcRect(i, j).Right = (Tile_Width * tilenum)
dsrcRect(i, j).Left = (Tile_Width * tilenum) - 24
Next j
Next i


For i = 0 To DrawArrayX
For j = 0 To DrawArrayY
ddrval = Primary.BltFast((X + (i * Tile_Width)), (Y + (j * Tile_Height)), Tiles, dsrcRect(i + HScroll1.Value, j + VScroll1.Value), DDBLTFAST_SRCCOLORKEY And DDBLTFAST_WAIT)
Next j
Next i


End Sub

Private Sub calcTiles()
End Sub

Private Sub picTiles_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
X = (X / Screen.TwipsPerPixelX)
Y = (Y / Screen.TwipsPerPixelY)

X = X - 12
Y = Y - 12

tilesetx = X / 24
tilesety = Y / 24

tilesetx = tilesetx
tilesety = tilesety


tilesetx = tilesetx + 1
tilesety = tilesety + 1

curTileNum = ((tilesety * 10) - 10) + tilesetx

picTiles.ToolTipText = "Tile Number: " & curTileNum

End Sub

Private Sub picTiles_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim CurrentTile As Integer
Dim newX As Integer
Dim newY As Integer

X = (X / Screen.TwipsPerPixelX)
Y = (Y / Screen.TwipsPerPixelY)

X = X - 12
Y = Y - 12

newX = X / 24
newY = Y / 24

newX = newX + 1
newY = newY + 1

CurrentTile = ((newY * 10) - 10) + newX

picTiles.ToolTipText = "Tile Number: " & CurrentTile

End Sub

Private Sub VScroll1_Change()
bltTiles
End Sub

Private Sub drawMask()
Dim srcRect As RECT
Dim X As Long
Dim Y As Long

X = (frmMain.Left / Screen.TwipsPerPixelX) + picBox.Left + 7
Y = (frmMain.Top / Screen.TwipsPerPixelY) + picBox.Top + 26

srcRect.Bottom = 24
srcRect.Right = 24

Primary.BltFast (X + 50), (Y + 50), skyTiles, srcRect, DDBLTFAST_WAIT And DDBLTFAST_SRCCOLORKEY
End Sub


Thanks.

Windowed Game
Hi im trying to do a .exe emulator thingy ... that opens a vb program and then it opens the exe file so the game gets windowed ... but its not going to well ... i can open the .exe file but its get windowed

code =
on form1 load
Shell "C:SierraCounter-Strikecstrike.exe -console -game dod",
vbNormalFocus

plz can someone help me..

Fullscreen To Windowed
is it possible to run an application that normally runs in fullscreen (like a game) to windowed mode. How should I do that?

Windowed Games
can i make a MDI form..(example) open the app and open the game and the game will load in the app instead of full screen so u can minimize it and ect...how do you do it?? lol

Fullscreen Vs Windowed
directX

is fullscreen mode supposed to be faster than windowed mode?

i'm getting the exact opposite and on separate machines at that. why?

thanks,

Wayne

Backbuffer In Windowed Mode
Hello,

I've got a problem, everytime I want to use a backbuffer in windowed mode(direct draw) I get a ?"Automation error"? does enyone have a solution?

DX8 Windowed Vs. Screen Formats
Hey, is there a work-around for this?

I've got a DX8 windowed app, works fine usually.. but I've just tried it on a PC which has it's screen set to 24bit ("True Colour").. and it's been giving me INVALID CALL errors when I try to create the D3DDevice

GetAdapterDisplayMode is giving me a .Format = D3DFMT_R8G8B8 (Seems right)
I've just found the following the DX8 help

Quote:





Originally Posted by DX8 Help - CONST_D3DFORMAT


Note that render target formats are restricted to D3DFMT_X1R5G5B5, D3DFMT_R5G6B5, D3DFMT_X8R8G8B8, and D3DFMT_A8R8G8B8.




Fair enough... but when you combine it with this

Quote:





Originally Posted by DX8 Help - D3DPresent_Parameters


If Windowed is set to 1, then BackBufferFormat must be set to match the format of the current display mode.




You seem to be beggered if you're display format is NOT one of the allowed "render target" formats.

Is my ONLY option to detect that the screen is not set to an "allowed" render target format... and give the user a msgbox telling them to change it?

Or is there a way to get around it?

Cheers

Direct X 7, Help I Can't Get Windowed 2 Work
Ok as the name says yer i post a bit of Code ok to see if u understand.


Code:
Dim ddsd As DDSURFACEDESC2
Dim caps As DDSCAPS2
f_hWnd = FormHwnd
SCREEN_WIDTH = Width
SCREEN_HEIGHT = Height
SCREEN_DEPTH = Depth
SCREEN_BACKCOLOR = BackColour
'// Create DirectDraw object
Set mDDraw = mDX.DirectDrawCreate("")
'// Set Cooperative Level (fullscreen, exclusive access)
'SetFullSrceen?
If FullSrceen = True Then
mDDraw.SetCooperativeLevel f_hWnd, DDSCL_EXCLUSIVE Or DDSCL_FULLSCREEN Or DDSCL_ALLOWREBOOT
mDDraw.SetDisplayMode Width, Height, Depth, 0, DDSDM_DEFAULT
Else
mDDraw.SetCooperativeLevel f_hWnd, DDSCL_NORMAL
End If
'// Create primary surface
ddsd.lFlags = DDSD_BACKBUFFERCOUNT Or DDSD_CAPS
ddsd.ddsCaps.lCaps = DDSCAPS_COMPLEX Or DDSCAPS_FLIP Or DDSCAPS_3DDEVICE Or DDSCAPS_PRIMARYSURFACE
ddsd.lWidth = Width
ddsd.lHeight = Height

ddsd.lBackBufferCount = 1
Set msFront = mDDraw.CreateSurface(ddsd)
i don't know y

thanks, help me

by the way umm yer full screen works ok.

Gamma On WIndowed Mode
Can i use a gamma control on a windowed mode?
Becouse i cant do it

thkz

Size Of Windowed Forms
Hullo

Just a quick question, is it possible to set the size of a windowed screen at run-time with DirectX8?

My initialization code (code that many have probably seen very often in the past) is as follows:

Code:
Private Function InitialiseWindow() As Boolean
On Error GoTo ErrHandler:

Set DX = New DirectX8
Set D3D = DX.Direct3DCreate()

D3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, DispMode

D3DWindow.Windowed = 1
D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
D3DWindow.BackBufferFormat = DispMode.Format

Set D3DDevice = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, frmMain.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DWindow)

InitialiseWindow = True
Exit Function
ErrHandler:

Initialise = False
End Function

I've tried messing with DispMode. properties and D3DWindow. properties but none seem to work. I've also tried just adjusting frmMain.width and frmMain.height to specific values but, even though my ScaleMode is set to Pixels, the result is not the height and width represented by the values I set frmMain. properties equal to. (The actual display size is much smaller).

I hope it's not too confusing

Thanks

Windowed V. Fullscreen Mode
I just started looking at the directx4vb.com tutorials. When enumerated, my graphics card says that it can be run in windowed mode. However, their very first tutorial, which runs in windowed mode, will not run. Here is the initialize code (which is failing):


Code:
'// Initialise : This procedure kick starts the whole process.
'// It'll return true for success, false if there was an error.
Public Function Initialise() As Boolean
On Error GoTo ErrHandler:

Dim DispMode As D3DDISPLAYMODE '//Describes our Display Mode
Dim D3DWindow As D3DPRESENT_PARAMETERS '//Describes our Viewport

Set Dx = New DirectX8 '//Create our Master Object
Set D3D = Dx.Direct3DCreate() '//Make our Master Object create the Direct3D Interface


'######################################
'## USE THE FOLLOWING CODE FOR WINDOWED MODE ##
'######################################

D3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, DispMode '//Retrieve the current display Mode

D3DWindow.Windowed = 1 '//Tell it we're using Windowed Mode
D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC '//We'll refresh when the monitor does
D3DWindow.BackBufferFormat = DispMode.Format '//We'll use the format we just retrieved...


'###############################
'## USE THIS CODE FOR FULLSCREEN MODE ##
'###############################

'DispMode.Format = D3DFMT_R5G6B5
'DispMode.Width = 640
'DispMode.Height = 480

'D3DWindow.SwapEffect = D3DSWAPEFFECT_FLIP
'D3DWindow.BackBufferCount = 1 '//1 backbuffer only
'D3DWindow.BackBufferFormat = DispMode.Format 'What we specified earlier
'D3DWindow.BackBufferHeight = 480
'D3DWindow.BackBufferWidth = 640
'D3DWindow.hDeviceWindow = frmMain.hWnd

'//This line creates a device that uses a hardware device if possible; software vertex processing and uses the form as it's target
'//See the lesson text for more information on this line...
Set D3DDevice = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, frmMain.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, _
D3DWindow)

Initialise = True '//We succeeded
Exit Function
ErrHandler:
'//We failed; for now we wont worry about why.
Debug.Print "Error Number Returned: " & Err.Number
Initialise = False
End Function

It only fails when the windowed code is active and the full screen code is commented out. When the full screen code is active and the windowed code is commented out it brings up a blank full screen (which I assume means it worked). After setting a breakpoint on each line it is the final line (Set D3DDevice = ..........) that is triggering the error.

I am using an Intel 82815 Graphics Controller if that helps. Any tips or suggestions would be greatly appreciated. Thanks in advance.

-ZZII

Vsync In Windowed Mode?
Is it possible to enable VSync when using windowed mode (directx7)? I'm using directdraw only and am experienceing some rather annoying tearing in my game.

Help Creating Multi-windowed App.
Hey all!

I began coding up the resouce editor for a simplistic game engine of mine yesterday - and when I started working on it again this evening, I said to myself, "Huh. This could be so much better if I only knew how."

You see, right now the editor is a static window with a couple list-boxes and options on a Tab control. While this will work, I'd much rather do something more aesthetically pleasing and easier to use. I'd rather create an application with resizable frames, so it'll work just as well in 640x as 1024x.

Are there any tutorials out there that are readily available for this kinda thing?

Thankkee kindly!
-Mith

Windowed Mode Question (DirectDraw7)
Hi, I am making a game that can be displayed in both Full screen and windowed mode. I got the full screen version of it to work just fine, but I'm having problems with the windowed mode. My game is set up so that all the drawing is done on a backbuffer, and then flipped to the primary surface (For full screen mode). But I know that in windowed mode, you must blit from the backbuffer to the screen. My question is, how do you create the backbuffer in windowed mode without setting a bitmap to it (like the full screen one). All the examples I've found so far initialize the buffer, with a picture in it, but I just want a blank one that I can blit graphics to. Could anyone show me how to do this?

Having Trouble Making DX Windowed Mode
I can make it full screen, but i want it windowed. i change windowed = 1 and it just crashes.

heres code: www.po2upload.com/uploads/3dworld.rar

not very long.

Open Games In Windowed Mode
You no when you open a game its fullscreen. How would I load it into a windowed mode. Ive seen it done but im at a loss on how you would do it anyideas?

Adding Pictures Using Windowed DX7 Mode
During run-time, how do I load up bmp's and move them around?
(In windowed mode)

I looked at directx4vb.com and I understood the window section except nowhere could I find how to load new pictures DURING run-time. Also, how do I load a new bmp on TOP of a bmp already in a picture box.

The first bmp would be loaded using Blt then the second using bltfast so it doesn't cover the entire first bmp. Except, I have no clue how to load bmps and move them around.

Any help would be greatly appreciated.

PS: If this helps the visualization, I want to do this for a very basic tile-based 2d game. A backround, then a character (32x32) that can move around on the backround.

Windowed Mode: Multiple Displays
How do you set up two visible display surfaces for use in DirectX7 windowed mode? I've tried making two primary surfaces (no luck). I also tried looking through the DirectX SDK and found the DDSCAPS_FRONTBUFFER and DDSCAPS_VISIBLE options, but have had no luck with them.

What I want to do is have my large primary surface in a 800 by 600 window and have a seperate 50 by 50 surface on the side to display a single tile at a time.

I tried searching the forms but no luck there either...

DirectX8 (DirectGraphics) Windowed Mode
Is it possible to use DirectGraphics in Windowed Mode? I was searching the SDK a little bit kinda skimming over it and i didnt find anything on it. since my map editor is done cept for scrolling and saving and loading im going to start DirectX8 with 2d so i can get the built in alpha bending and stuff . but i dont know where to start with windowed mode since i prefer it over Full Screen.

Force A DX-Fullscreen App Into Windowed Mode
Can anyone tell me if that is possible? i really would like to know how...

Thanks a lot

Force DXapp FullScreen -&gt; Windowed?
Just a query, is it possible to force a fullscreen thrid party application such as a game into a window?

Feel free to post any code/tips,

Thanks.

Nb: I've tryed using Virtual PC - it works but not quite adequate.

Windowed Programs And Process Detection?
Is it possiable to run an external program in visual basic form or in an MDI child form - if yes then how?

Also on a seperate matter can you make a program perform an action depending on if annother process is running. IE when test.exe starts vbprogram.exe minimizes itself and when test.exe ends, vbprogram.exe maximizes itself?

thanks

Windowed DirectX7 With Backbuffer Trouble
Ok, i've searched and searched for how to do this, and have found lots of pages all saying pretty much the same thing. I've had a go and wrote the following code (in an init routine).


VB Code:
Set DD = dx.DirectDrawCreate("")    DD.SetCooperativeLevel ThisSurface.hWnd, DDSCL_NORMAL        ddsdPrimary.lFlags = DDSD_CAPS    ddsdPrimary.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE    Set Primary = DD.CreateSurface(ddsdPrimary)        ddsdBackBuffer.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH    ddsdBackBuffer.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN    ddsdBackBuffer.lHeight = ThisSurface.Height    ddsdBackBuffer.lWidth = ThisSurface.Width    Set BackBuffer = Nothing    Set BackBuffer = DD.CreateSurface(ddsdBackBuffer)        Set Clipper = DD.CreateClipper(0)    Clipper.SetHWnd ThisSurface.hWnd    Primary.SetClipper Clipper        'Initialize Direct3D for special surfaces    Set D3D = DD.GetDirect3D    Set Dev = D3D.CreateDevice("IID_IDirect3DHALDevice", BackBuffer)


When i run the program it hangs completely, and VB freezes. Even Ctrl-Alt-Delete doesn't work.

I don't think it's a problem with DX as i've got fullscreen to work fine.

Any ideas?

Thanks.

Launching Program In Windowed Mode?
Hi,

I would like to know whether it's possible to launch a program from within another program, so that it remains inside that external program's window. You see, I would like to prevent my monitor having to change resolution each time I launch this game called Midtown Madness 2 (it's res is 640x480). Basically, what I want to try is launch it from an external program, at 640x480, in your desktop's current res (e.g. 1024x768).

How Can I Create A Bitmap In Memory Without A Windowed Control?
My Subject says all, i need to create a bitmap in memory, without using wincontrols, like in Delphi i can do:

Code:
var
MyBitmap: TBitmap;
begin
MyBitmap := TBitmap.Create;
try
... {I work with the object in this lines}
finally
MyBitmap.Free;
end;
end;

I see some code like http://www.syix.com/wpsjr1/index.html but it uses too many code... I want to know if exists something littler!

TIA!

Need Help To Set Wiki DD Sample Code To Windowed Mode
Hi,
I am trying to use wiki sample code for starting DD, because no other tutorial really helped me (most of them not actual)... what I actually need is to switch this code to window mode, or if you can, tell me what things should I replace in that, to be actual. I saw many to ask same question (windowed mode) but it was still dx7, or no answer...
will someone help me out? I also saw dx4vb and there are also not actual codes... sdk is too big and one guy's code from here was also old...
I am using vb 2005 express .net
*you musn't advice me about content of drawing (rects, for, next) i am working at it... but if you have idea how to draw lots of boxes most effitiently, you are welcomed ;

</code deleted>



I also welcome as much links to actual tutorials and samples as possible.
But only if you know it's about DD + windowed mode

Ya, and I remember: I wanted to ask for some function to resize by flip, or simply some dd function to resize.

Temp Changing Full Screen To Windowed
Is there a way to change the following code to not switch to full screen but stay as a windowed 640x480 display? Cause I'm writing the network and if freezes allot when u make even the simplest mistake and my computer takes 8-14 mins to reboot(wont explain why, doesn't matter). In windowsed I can CTRL+ALT+DEL

Code:

On Error GoTo ErrorHandle

Log ": Creating DirectDraw7"
Set DDraw = Dx.DirectDrawCreate("")
Main.Show

Log ": Setting DirectDraw Co-op Level"
DDraw.SetCooperativeLevel Main.hWnd, DDSCL_FULLSCREEN Or DDSCL_ALLOWMODEX Or DDSCL_EXCLUSIVE
Log ": Setting DirectDraw display mode"
DDraw.SetDisplayMode ScreenWidth, ScreenHeight, 16, 0, DDSDM_DEFAULT

Log ": Creating Primary surface"
ddsdPrimary.lFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNT
ddsdPrimary.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP Or DDSCAPS_COMPLEX
ddsdPrimary.lBackBufferCount = 1

Set ddsPrimary = DDraw.CreateSurface(ddsdPrimary)

Log ": Creating BackBuffer surface"
Dim Caps As DDSCAPS2
Caps.lCaps = DDSCAPS_BACKBUFFER

Set ddsBackBuffer = ddsPrimary.GetAttachedSurface(Caps)

ddsBackBuffer.GetSurfaceDesc ddsdBackbuffer
Exit Sub

ErrorHandle:
Log "*****Error in InitDirectDraw*****"

Changing From Fullscreen To Windowed With D3D7 At Runtime
Im working on this game of mine, and I want to be able to run it in either fullscreen or windowed mode, and being able to change between the two at runtime is convenient. I had working code that "can" do it, just not very well, and the major problem with it is that I cannot seem to attatch the D3D device to an DDSCAPS_OFFSCREENPLAIN surface that I use for the windowed backbuffer. Whenever I add the DDSCAPS_3DDEVICE to the backbuffer using OFFSCREENPLAIN, VB grumbles at me when I try to Set BackBuffer = DD7.CreateSurface(ddsdBackBuffer). I really dont want to attatch D3D to the primary surface seeing as that eliminates the backbuffer (bad!) Here is the sub I use to change resolutions / display modes.


Code:
Public Sub ChangeDisplay(ByVal Width As Long, ByVal Height As Long, _
ByVal BPP As Long, ByVal Windowed As Boolean)

'make a fullscreen or windowed display
If Windowed Then
'set up the form
frmMain.Width = Width * Screen.TwipsPerPixelX
frmMain.Height = Height * Screen.TwipsPerPixelY
frmMain.Show
'set up the picturebox to draw to
picSurface.Width = frmMain.Width
picSurface.Height = frmMain.Height
picSurface.BackColor = RGB(0, 0, 0)
picSurface.Visible = True
DD7.RestoreDisplayMode
DD7.SetCooperativeLevel picSurface.hwnd, DDSCL_NORMAL
modChangeBorderStyle.ShowTitleBar Windowed, frmMain
Clipper.SetHWnd picSurface.hwnd
Else
frmMain.BorderStyle = 0
frmMain.Show
picSurface.Visible = False
DD7.SetCooperativeLevel frmMain.hwnd, DDSCL_FULLSCREEN _
Or DDSCL_EXCLUSIVE Or DDSCL_ALLOWMODEX
DD7.SetDisplayMode Width, Height, BPP, 0, DDSDM_DEFAULT
modChangeBorderStyle.ShowTitleBar Windowed, frmMain
End If

'prepare our primary surface

If Windowed Then
ddsdPrimary.lFlags = DDSD_CAPS
ddsdPrimary.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_3DDEVICE
ddsdPrimary.lBackBufferCount = 0
Else
ddsdPrimary.lFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNT
ddsdPrimary.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE Or DDSCAPS_FLIP _
Or DDSCAPS_COMPLEX Or DDSCAPS_3DDEVICE
ddsdPrimary.lBackBufferCount = lBackBufferCount
End If

Set Primary = Nothing
Set Primary = DD7.CreateSurface(ddsdPrimary)
If Windowed Then Primary.SetClipper Clipper

'primary rectangle
DX7.GetWindowRect frmMain.hwnd, rPrimary

'set up the backbuffer
If Windowed Then
ddsdBackBuffer.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
ddsdBackBuffer.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
ddsdBackBuffer.lWidth = Width
ddsdBackBuffer.lHeight = Height
Set BackBuffer = DD7.CreateSurface(ddsdBackBuffer)
Else
ddsdBackBuffer.ddsCaps.lCaps = DDSCAPS_BACKBUFFER Or DDSCAPS_3DDEVICE
Set BackBuffer = Primary.GetAttachedSurface(ddsdBackBuffer.ddsCaps)
End If

'backbuffer rectangle
rBackBuffer.Top = 0
rBackBuffer.Left = 0
rBackBuffer.Right = Width
rBackBuffer.Bottom = Height

End Sub
the "modChangeBorderStyle.ShowTitleBar" is a module to change the form.borderstyle properties at runtime to get rid of the border for fullscreen mode.

The code seems to only work once. I can start the program up in windowed mode, and then change to fullscreen mode, but changing again to either windowed or a different resolution gives me an automation error when I set the primary surface. Any ideas? And how can I make a backbuffer type surface for windowed mode work with D3D?

And please dont suggest that I use Dx8, because I want to keep DirectDraw functionality and use a Hybrid DD and D3D engine to make a groovy looking 2D game.

Direct Draw 7 Windowed Mode Flickering
Is it normal to have like.. a lot of flickering in direct draw 7 windowed mode?
I use a tile engine with 20x20 tiles, I created it rapidly to test out a pathfinding algorhytm, thus sloppy coding... but not THAT sloppy...
I have never used windowed mode before, so most probably I am doing something wrong here. Point me to the right direction please.

check it out:

PostMessage Or SendMessage To A Windowed DirectX Game?
I have some code worked up that should be sending some PostMessage or SendMessage characters (have tried both) to a DirectX game that is running in Windowed mode.

I have tried sending it to the parent as well as child class hwnd. Incidentally both have the same class name...

And it's not doing anything. Any way that I can test this? Or is there something I need to be doing a little differently for this? Any tips would be great. Thanks!

OnIdle In VB? Trying To Write A 'friendly' VB Windowed Game
I wrote a C++ DirectX ActiveX control which I'm using in VB to write a simple game... I have just one problem. I can't get the OnIdle event in VB that I can in C++ or Delphi even. Without this, I don't know how to make my game behave well in windowed mode (I resort to an infinite loop which hogs the system).

I tried using DoEvents which helps, but while my tiles are rendering, it's very slow to drag the window around... But at least I can

It isn't nearly as smooth as the C++ host application I wrote that handled OnIdle, but *ugh* I don't want to use C++ for the interface, etc, of my game/map builder.

Any ideas?

Thanks!

Get A Full-screen Game To Load Into A Windowed Form...
I currently have a game that does not have an option to run in "windowed" form. It only runs in fullscreen! I know it's possible to take external applications and load them into internal VB forms and controls (such as picturebox). I've done this many times with MS Calculator, etc. by setting the Parent Form.

My question is... how difficult would it be to successfully load a game that runs in fullscreen into a VB form that can be "windowed" (doesn't even have to be resizable). I tried the "SetParent" method that I mentioned above on it; however, only an icon of the game shows up in the VB form... and when I click on it, it launches back into a fullscreen mode!

Any suggestions!? Thanks...

Respectfully,
Eric D. Brown

TextBox, SendKeys, Force Windowed, Multiple Instances, Help PLz!?
Hi, I've a few question no one seems to wanna answere or don't know the answere tho..

------

1) How to add text to a textbox? lol?
Note: (I want to add it like in a listbox)

2) How to send keystrokes (if possible?) TO a NON active app?

(1,2)(anyone know how to do this?? done it before?? tell me??)

------

3) Is the anyway to force another app to windowed mode
(ex from full screen)

4) Is there anyway possible to start multiple instances of a program that normaly doesn't allow it.

(3,4)(source/exemple/program that does this/etc - would be nice)

-------

Share Your Knowledge!
Thx =)

Fullscreen/Windowed Swap Results In Incorrect Window Drawing
Hello

In my engine the user is allowed to swap between fullscreen mode and windowed mode(DirectX8) on the fly. Like in some games you can check a check box to render windowed. Although as soon as i come from Fullscreen to windowed the title bar disappear. Lets say it this way there is no form drawn just the rendering in some part of the screen with windows on the background. How can i make sure that the window(borders, titlebar etc) are visible again(before they were).
And how come that whenever i specify it to draw in a picture box instead of a window that it can't create a rendering device in fullscreen mode. And createing input device EXCLUSIVE OR FOREGROUND will work but keep working even whenever the window with the picture box on does not have the focus..

I hope you understand what i mean. If not i can post examples of this here. Let me know

ChoKamir

About DirectDraw
If I wana make a 2d rpg in VB with Directx do I have to use Direct Draw.

And is there any other way to make a rpg/mmorpg with out Directx?

EDIT: Can BLit Blit thing make MMORPG's?

DirectDraw
I've started making a Mario type side-scroller by BitBlting tiles from a map onto a picturebox. It works well except I'm not getting the performance I need. Obviously what I need to do is use DirectDraw but how? Where do I start? What's the easiest way for something like this?

Thanx

DirectDraw
I just switched the rendering mode from BitBlt to DirectDraw for my tile engine, but now it flickers quite badly when the map is scrolled. Can anybody help me please? I'm really new at all this DirectX programming. Also, I tried using a backbuffer... it didn't work... Still flickers... This is the code to create graphics to a picturebox ==>


Private Sub DrawSurface()
Dim Dest As Rectangle
Try
BackSurface.ColorFill(Color.Blue)
BackSurface.DrawFast(0, 0, MapSurface, Map.Rect, DrawFastFlags.Wait)
Catch ex As SurfaceLostException
InitializeSurface()
End Try

Dest = New Rectangle(PointToScreen(Me.picMain.Location), Me.picMain.Size)
FrontSurface.Draw(Dest, BackSurface, DrawFlags.DoNotWait)
End Sub

FPS In DirectDraw
Could someone post the code to get the FPS of a program? I used to just get the code off of voodoo vb but now that its gone I dont have it anymore. I guess this time I will memorize and learn the code so I dont need to ask anymore, thanks in advance

DirectDraw
I am new (about 5 minutes) into working with DirectDraw, and I have learnt the following, however i want to be able to dim rBack as a polygon. How do I define and configure it?

Thanks!

Sub DrawPic()
If bInit = False Then Exit Sub

Dim rBack As RECT

rBack.Bottom = ddsd3.lHeight
rBack.Right = ddsd3.lWidth

Call BackBuffer.BltFast(0, 0, BitSurf, rBack, DDBLTFAST_WAIT)

Primary.Flip Nothing, DDFLIP_WAIT
End Sub

FX In DirectDraw
Hello everyone, just wanted to post some FX in directdraw (in case anyone is still interested). There are some algorithms for alphablending and colorkeying, plus simple rotation. Take it as my small contribution to the forum. Thanks and happy programming!
Edit by 00100b:
Attachment Removed. Compiled programs are not permitted as or within file attachments.

Please take a moment to read the Posting Guidelines for details of our standards.

GUI For Directdraw
Is there some standards on GUI for directdraw(dx7) or something?
What I want is to have all GUI stuff in a module(modGUI).

Kimbo

Copyright © 2005-08 www.BigResource.com, All rights reserved