“君欲善其事,必先利其器”,在编写DirectDraw应用程序之前,我们先要准备好以下工具:
Windows95、Windows98、Windows Me、Windows NT 4.0、Windows 2000 或 Windows XP(其对操作系统没有特殊要求) |
DirectX 驱动程序(最好是DirectX 8.0以上版本) |
DirectX 8.0 SDK |
Visual C++ 5.0 ,Visual C++ 6.0 或 Visual C++ .NET |
Direct SDK包括开发基于DirectX应用程序所需的全部文件,全部安装需要80兆的硬盘空间。其实你只需安装必需的头文文件(.h文件)和库文件(.lib文件)就行了。
安装完DirectX SDK,需要通知Visual C++ DirectX SDK的路径。具体做法是:在VC的编译环境中,依次把Tools-Options-Directories中的Show Directories for一栏中的include files和library files中分别填入SDK的include和lib目录,如图所示。



再准备两幅bmp格式的位图,其中winXP.bmp作背景,如图;另一幅directx.bmp作为子画面,如图。还要注意一点的是子画面的背景要为黑色(RGB=(0,0,0)),因为在下面的程序中,色彩键码把黑色设为透明色。

winXP.bmp 1024×768×24

directx.bmp 32×32×8
进入VC6的编程环境,File-New-Project,选择Win32 Application,输入项目名FullScreenMode ,按下Ok,以后每一步都按其缺省值即可,这样AppWizard就会自动创建一个空项目,下面我们还需要加入一个cpp源文件,并将Win32程序的基本框架拷贝入刚刚创建的cpp源文件中。如下图1、2:


然后点击“文件”选项卡添加.CPP工程文件。如下图3:

其实我们的工程中还要用到DirectX SKD提供的四个文件:
ddutil.h |
ddutil.cpp |
dxutil.h |
dxutil.cpp |
对于头文件,我们还采用上面添加编译器默认头文件目录的方法让编译器自己去找,如图:

上面的目录是我们刚才加入的,而下面的目录是我们这次加入的。而对于 cpp源文件,我们采用将文件直接导入工程的方法,如图:


文件 ddutil.cpp dxutil.cpp 所在目录为
(9.0版本) |
C:\DXSDK\Samples\C++\Common\Src |
(8.0版本) |
C:\DXSDK \samples\multimedia\common\src |
所有的工程文件结构如图:

下面的所有程序都是 FullScreenMode.cpp 文件中的内容,其中IDB_DIRECTX和IDB_WinXP都是图片资源的ID号,向程序中添加资源的过程如图:


其它的资源文件也是这样加入的。请读者自己将图片加入到程序中。
|