If Not (DDraw Is Nothing) Then DDraw.RestoreDisplayMode DDraw.SetCooperativeLevel MainForm.hWnd, DDSCL_NORMAL DoEvents End If MsgBox “无法对DirectDraw进行初始化 ”+Chr(13)+“也许你的显示卡不支持 640×480×8 显示模式 ” End End Sub Public Sub TerminateDX() '子程序TerminateDX回复原来的显示模式并且释放所有的DirectDraw有关对象 DDraw.RestoreDisplayMode DDraw.SetCooperativeLevel MainForm.hWnd, DDSCL_NORMAL DoEvents Set Clipper = Nothing Set DDSBack = Nothing Set DDSFront = Nothing Set DDraw = Nothing Set DX = Nothing End Sub 在工程文件中再加入一个Module,这个Module主要定义与图像保存相关的操作,在建立的Module中加入以下代码: Option Explicit Option Base 0 Private Type PALETTEENTRY peRed As Byte peGreen As Byte peBlue As Byte peFlags As Byte End Type Private Type LOGPALETTE palVersion As Integer palNumEntries As Integer palPalEntry(255) As PALETTEENTRY End Type Private Type GUID Data1 As Long Data2 As Integer Data3 As Integer Data4(7) As Byte End Type Private Const RASTERCAPS As Long = 38 Private Const RC_PALETTE As Long = &H100 Private Const SIZEPALETTE As Long = 104 Private Declare Function CreateCompatibleDC Lib “GDI32” (ByVal hDC As Long) As Long Private Declare Function CreateCompatibleBitmap Lib “GDI32” (ByVal hDC As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare Function GetDeviceCaps Lib “GDI32” (ByVal hDC As Long, ByVal iCapabilitiy As Long) As Long Private Declare Function GetSystemPaletteEntries Lib “GDI32” (ByVal hDC As Long, ByVal wStartIndex As Long, ByVal wNumEntries As Long, lpPaletteEntries As PALETTEENTRY) As Long Private Declare Function CreatePalette Lib “GDI32”(lpLogPalette As LOGPALETTE) As Long Private Declare Function SelectObject Lib “GDI32”(ByVal hDC As Long, ByVal hObject As Long) As Long Private Declare Function BitBlt Lib “GDI32”(ByVal hDCDest As Long, ByVal XDest As Long, ByVal YDest As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hdcSrc As Long, ByVal XSrc As Long, ByVal YSrc As Long, ByVal dwRop As Long) As Long Private Declare Function DeleteDC Lib “GDI32”(ByVal hDC As Long) As Long Private Declare Function GetForegroundWindow Lib “USER32” () As Long Private Declare Function SelectPalette Lib “GDI32”(ByVal hDC As Long, ByVal hPalette As Long, ByVal bForceBackground As Long) As Long Private Declare Function RealizePalette Lib “GDI32” (ByVal hDC As Long) As Long Private Declare Function GetWindowDC Lib “USER32” (ByVal hWnd As Long) As Long Private Declare Function GetDC Lib “USER32"(ByVal hWnd As Long) As Long Private Declare Function GetWindowRect Lib “USER32”(ByVal hWnd As Long, lpRect As RECT) As Long Private Declare Function ReleaseDC Lib “USER32”(ByVal hWnd As Long, ByVal hDC As Long) As Long Private Declare Function GetDesktopWindow Lib “{USER32"() As Long
用VB编写DirectX7.0游戏五 |