home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD149932152001.psc / modDX.bas < prev    next >
Encoding:
BASIC Source File  |  2001-02-15  |  1.5 KB  |  46 lines

  1. Attribute VB_Name = "modDX"
  2. 'The Main DirectX Object
  3.  
  4. 'This sets the cooperative levels of Direct Draw and Direct Sound
  5. Sub DX_SetCoopLevel(Hdl As Long)
  6.     Call dsMain.SetCooperativeLevel(Hdl, DSSCL_PRIORITY)
  7.     Call ddMain.SetCooperativeLevel(Hdl, DDSCL_FULLSCREEN Or DDSCL_ALLOWMODEX Or DDSCL_EXCLUSIVE)
  8. End Sub
  9.  
  10. 'This sets the screens display mode
  11. Sub DX_SetDisplay(sWidth As Long, sHeight As Long, sBPP As Long)
  12.     Call ddMain.SetDisplayMode(sWidth, sHeight, sBPP, 0, DDSDM_DEFAULT)
  13. End Sub
  14.  
  15. 'This is the main DirectX Initialization
  16. Sub DX_Init()
  17.  
  18.     'If already in directx mode, why go in it again
  19.     If InDirectXMode Then Exit Sub
  20.  
  21.     On Error GoTo errInit
  22.  
  23.     'Creates Direct Draw and Direct Sound
  24.     Set ddMain = dxMain.DirectDrawCreate("")
  25.     Set dsMain = dxMain.DirectSoundCreate("")
  26.     'Sets Their Cooperative levels
  27.     Call DX_SetCoopLevel(frmMain.hWnd)
  28.     'Sets the screen's display to 640x480x16
  29.     Call DX_SetDisplay(640, 480, 16)
  30.  
  31.     'Puts computer in directx mode
  32.     InDirectXMode = True
  33.     'Hides the cursor
  34.     Call ShowCursor(0)
  35.     Exit Sub
  36.  
  37. errInit:
  38.     MsgBox "DirectX couldn't be initialized! Please check to see if it has been installed correctly!", vbExclamation, "Error!"
  39. End Sub
  40.  
  41. 'Restores Cooperative levels of Direct Draw and Direct Sound at programs end
  42. Sub DX_RestoreCoopLevel(Hdl As Long)
  43.     Call dsMain.SetCooperativeLevel(Hdl, DSSCL_NORMAL)
  44.     Call ddMain.SetCooperativeLevel(Hdl, DDSCL_NORMAL)
  45. End Sub
  46.