|
|

楼主 |
发表于 2007-9-1 02:18:00
|
显示全部楼层
Re:关于设备丢失恢复问题
Public DX As DirectX8
Public D3D As Direct3D8
Public D3DDevice As Direct3DDevice8
Public d3dx As D3DX8
Public Sprite As D3DXSprite
Public Running As Boolean
Public DI As DirectInput8
Public DIDEV As DirectInputDevice8
Public DIDEV1 As DirectInputDevice8
Public DIState As DIKEYBOARDSTATE
Public DIMouse As DIMOUSESTATE
Public Tex As Direct3DTexture8
Public Rect1 As RECT
Public Scal As D3DVECTOR2
Public Rotation As Single
Public Center As D3DVECTOR2
Public Tran As D3DVECTOR2
Public DXFont As D3DXFont
Sub Main()
Set DX = New DirectX8
Set D3D = DX.Direct3DCreate
Dim Dpp1 As D3DPRESENT_PARAMETERS
Dpp1.SwapEffect = D3DSWAPEFFECT_DISCARD
Dpp1.BackBufferWidth = 800
Dpp1.BackBufferHeight = 600
Dpp1.BackBufferFormat = D3DFMT_A8R8G8B8
Set D3DDevice = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Form1.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, Dpp1)
Set d3dx = New D3DX8
Set Sprite = d3dx.CreateSprite(D3DDevice)
Set Tex = d3dx.CreateTextureFromFileEx(D3DDevice, App.Path & "\背景.bmp", 800, 600, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_FILTER_NONE, D3DColorARGB(255, 255, 255, 255), ByVal 0, ByVal 0)
Scal.x = 1
Scal.y = 1
Dim m_vbFont As IFont
Dim x As New StdFont
x.Name = "宋体"
x.Bold = False
x.Italic = False
x.Underline = False
x.Size = 20
Set m_vbFont = x
Set DXFont = d3dx.CreateFont(D3DDevice, m_vbFont.hFont)
Set DI = DX.DirectInputCreate()
Set DIDEV = DI.CreateDevice("GUID_SysKeyboard")
DIDEV.SetCommonDataFormat DIFORMAT_KEYBOARD
DIDEV.SetCooperativeLevel Form1.hWnd, DISCL_BACKGROUND Or DISCL_NONEXCLUSIVE
DIDEV.Acquire
Set DIDEV1 = DI.CreateDevice("GUID_SysMouse")
DIDEV1.SetCommonDataFormat DIFORMAT_MOUSE
DIDEV1.SetCooperativeLevel Form1.hWnd, DISCL_BACKGROUND Or DISCL_NONEXCLUSIVE
DIDEV1.Acquire
Running = True
Do While Running = True
If D3DDevice.TestCooperativeLevel = 0 Then
D3DDevice.Clear 0, ByVal 0, D3DCLEAR_TARGET, D3DColorARGB(255, 255, 0, 0), 0, 0
D3DDevice.BeginScene
Sprite.Begin
DIDEV.GetDeviceStateKeyboard DIState
If DIState.Key(DIK_ESCAPE) Then End
DIDEV1.GetDeviceStateMouse DIMouse
If DIMouse.Buttons(0) And DIMouse.Buttons(1) Then End
Rect1.Left = 0
Rect1.Right = 800
Rect1.Top = 0
Rect1.bottom = 600
Sprite.Draw Tex, Rect1, Scal, Center, Rotation, Tran, D3DColorARGB(255, 255, 255, 255)
Rect1.Left = 0
Rect1.Right = 70
Rect1.Top = 0
Rect1.bottom = 30
d3dx.DrawText DXFont, D3DColorRGBA(255, 255, 255, 255), "123", Rect1, 0
Sprite.End
D3DDevice.EndScene
D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0
Else
DIDEV.Unacquire
Set DIDEV = Nothing
DIDEV1.Unacquire
Set DIDEV1 = Nothing
Set DI = DX.DirectInputCreate()
Set DIDEV = DI.CreateDevice("GUID_SysKeyboard")
DIDEV.SetCommonDataFormat DIFORMAT_KEYBOARD
DIDEV.SetCooperativeLevel Form1.hWnd, DISCL_BACKGROUND Or DISCL_NONEXCLUSIVE
DIDEV.Acquire
Set DIDEV1 = DI.CreateDevice("GUID_SysMouse")
DIDEV1.SetCommonDataFormat DIFORMAT_MOUSE
DIDEV1.SetCooperativeLevel Form1.hWnd, DISCL_BACKGROUND Or DISCL_NONEXCLUSIVE
DIDEV1.Acquire
If Form1.WindowState <> 1 Then
D3DDevice.Reset Dpp1
Set Sprite = d3dx.CreateSprite(D3DDevice)
Set DXFont = d3dx.CreateFont(D3DDevice, m_vbFont.hFont)
End If
End If
DoEvents
Loop
End Sub
|
|