收藏 分享(赏)

用vb编写directx7.0游戏(上)(Using VB to write DirectX7.0 games (Part 1)).doc

上传人:dreamzhangning 文档编号:2789224 上传时间:2018-09-27 格式:DOC 页数:9 大小:20.79KB
下载 相关 举报
用vb编写directx7.0游戏(上)(Using VB to write DirectX7.0 games (Part 1)).doc_第1页
第1页 / 共9页
用vb编写directx7.0游戏(上)(Using VB to write DirectX7.0 games (Part 1)).doc_第2页
第2页 / 共9页
用vb编写directx7.0游戏(上)(Using VB to write DirectX7.0 games (Part 1)).doc_第3页
第3页 / 共9页
用vb编写directx7.0游戏(上)(Using VB to write DirectX7.0 games (Part 1)).doc_第4页
第4页 / 共9页
用vb编写directx7.0游戏(上)(Using VB to write DirectX7.0 games (Part 1)).doc_第5页
第5页 / 共9页
点击查看更多>>
资源描述

1、用 vb编写 directx7.0游戏(上)(Using VB to write DirectX7.0 games (Part 1))DirectX7.0 finally appeared, the same as the previous DirectX6, version 7 also brought a huge (129M) SDK development library, compared with the DirectX6 SDK library, the DirectX7 Library of SDK provides the following new functions:*

2、support for Visual Basic. Users can use class libraries to develop DirectX based programs in Visual Basic environments.* provide more API functions under DirectX3D Mode (immediate Immediate) to support new 3D effects in DirectX7, including stereo environment mapping, vertex blending, and so on.* Dir

3、ectMusic supports DownLoadable Sound Level 2 standard.* DirectInput supports joystick devices with 8 buttons, and supports Microsofts force feedback joystick. The SDK library provides a way to read the force feedback effect file. Force Editor program is also provided to build the effect.For VB enthu

4、siasts, the new SDK library finally provides a complete support for VB, and now you can finally use Visual Basic to write DirectX program.First, the installation of DirectX SDK LibraryThe SDK library provided by Microsoft is a “heavy“ 129M dx7sdk.exe self extracting file. You can download it on the

5、Internet or get it from the CD attached. Double clicking the file will pop up the Winzip self extracting dialog box. Enter the path to unzip the files in the WinZip DK7SDK.EXE SelfExtract pop-up window, then click “Unzip“ button to extract the SDK file:Its important to note that the volume after dx7

6、sdk.exe decompression is 220M, and the more hard disk readers read before you unzip them, first of all, to see if your hard disk capacity is enough.After decompression, enter the decompression directory, double-click the Setup.exe file, you can install the DirectX7.0 SDK file. The installation is us

7、ing a standard InstallShield interface, the reader should play Windows on the installation interface handy, just follow the installation step by step away. After installation, the installer adds a menu of Microsoft DirectX 7 SDK to the start menu, including DirectX 7 settings tools, VB examples and

8、SDK Help and other menu items.Now go into VB and start our DirectX VB programming. Here we use the VB6 enterprise edition. Windows98 Chinese version.Open VB, Project | References click on the menu in the Library list, Object will have a 7 For Visual Basic: DirectX Type Library list item, this is the

9、 DirectX7.0 VB library, select the item, select the “OK“ button, it can be added to the project file in the library.Two, DirectX programming preliminary1 DirectX7 objectThe DirectX7 object is the service and starting object of all other objects in the DirectX VB object, which contains methods to bui

10、ld objects such as DirectDraw, Direct3D, DirectSound, DirectInput, and so on. At the same time, the object also contains a series of three-dimensional control vertex and the operation function of the matrix, and some DirectX system functions. In VB, you can define and initialize a DirectX7 object di

11、rectly through Dim. New, for example:Dim DirectX As New DirectX7After establishing a successful DirectX7 object, you can use the objects DirectDrawCreate, Direct3DRMCreate and other methods to build DirectDraw and Direct3D objects.DirectX7 object example 1: get DirectDraw and DirectSound drivers in

12、the systemCreate a new project file, Project | References click on the menu, select the DirectX For Visual Basic Type 7 Library Object Library after press the OK button in the list (the following procedures are required for this step, the back will no longer do that).Then add a ListBox control and f

13、our CommandButton controls in Form1, add the following code in the code window of Form1:Option ExplicitDim DirectX As New DirectX7Dim DDEnum As DirectDrawEnumDim DDSound As DirectSoundEnumPrivate Sub Command1_Click ()Dim Count, I As IntegerSet DDEnum = DirectX.GetDDEnumCount = DDEnum.GetCountList1.C

14、learFor I = 1 To CountList1.AddItem DDEnum.GetDescription (I)Next ISet DDEnum = NothingEnd SubPrivate Sub Command2_Click ()Dim Count, I As IntegerSet DDEnum = DirectX.GetDDEnumCount = DDEnum.GetCountList1.ClearFor I = 1 To CountList1.AddItem DDEnum.GetName (I)Next ISet DDEnum = NothingEnd SubPrivate

15、 Sub Command3_Click ()Dim Count, I As IntegerSet DDSound = DirectX.GetDSEnumCount = DDSound.GetCountList1.ClearFor I = 1 To CountList1.AddItem DDSound.GetDescription (I)Next IEnd SubPrivate Sub Command4_Click ()Dim Count, I As IntegerSet DDSound = DirectX.GetDSEnumCount = DDSound.GetCountList1.Clear

16、For I = 1 To CountList1.AddItem DDSound.GetName (I)Next IEnd SubPrivate Sub Form_Load ()Command1.Caption = “DirectDraw driver description“Command2.Caption = “DirectDraw driver name“Command3.Caption = “DirectSound driver description“Command4.Caption = “DirectSound driver name“End SubPrivate Sub Form_

17、Unload (Cancel As Integer)Set DirectX = NothingEnd SubRun the program, click on different buttons, in the list box will appear the corresponding device driver name and description.2 DirectDraw7 objectDirectDraw is a software interface for direct operation display equipment that is compatible with th

18、e Windows graphical system interface (GDI). DirectDraw provides hardware independence while allowing direct memory operation. The program just uses some basic standard hardware conventions, such as RGB and YUV color formats and resolutions. You dont need to call a special process to use the mobile m

19、emory block (Blitter) and palette. Using DirectDraw, you can simple memory, completely using various hardware features without having to ignore differences between different hardware.2.1 building DirectDraw objectsThe DirectDraw7 object is the DirectDraw object in DirectX7. You need to first build a

20、 DirectX7 object, and then use the objects DirectDrawCreate method to build the DirectDraw7 object. For example:Dim DX As New DirectX7Dim DDraw As DirectDraw7Set DDraw = DX.DirectDrawCreate (“)2.2 establish collaboration layerWhen you create a DirectDraw object, you first set up the DirectDraw colla

21、boration layer.The way to do this is to call the SetCooperativeLevel function of the DirectDraw object. The definition of the function is:Object.SetCooperativeLevel (HDL As Long, flags As CONST_DDSCLFLAGS)The parameter HDL specifies the window handle of the program, the parameter flag determines the

22、 way the program is run, and the function callsDDraw.SetCooperativeLevel Me.hWnd, DDSCL_NORMALThe program will run under the common collaboration layer, the window mode. In this collaboration layer, you cant change the main palette or switch pages, because programs can use multiple windows. Function

23、 callDDraw.SetCooperativeLevel MainForm.hWnd, DDSCL_EXCLUSIVE Or _DDSCL_FULLSCREENThe program will run under full screen mode. In full screen collaboration, you can use all of the hardware. In this mode, you can use the definition and dynamic palette to change the display resolution and page exchange.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 大学课件

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报