<b>在CB中举行DirectX编程(2)</b>[VC/C++编程]
本文“<b>在CB中举行DirectX编程(2)</b>[VC/C++编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
2.2.3 dx1源程序
2.2.3.1 dx1主要文件的构成为:工程文件(dx1.bpr)、窗口文件(main.cpp)、头文件(main.h).
2.2.3.2 头文件main.h
#ifndef mainH
#define mainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
(略)
private: // User declarations
LPDIRECTDRAW FAR lplpDD; /* 得到的 DirectDraw 接口指针 */
LPDIRECTDRAW2 FAR lplpDD2; /* 得到的 DirectDraw2 接口指针 */
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
2.2.3.3 程序文件main.cpp
#include <vcl.h>
#include "d:\tools\dx5sdk\sdk\inc\ddraw.h"
#pragma hdrstop
#include "main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
LPGUID FAR lpDevices[10]; /* 保存列举设备的标识指针 */
struct DisplayModes { DWORD Width,Height,Depth,Rate; } DisplayMode[100];
/* 保存显示设备支持的显示方法 */
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//设备列举回调函数---------------------------------------------------------------------------
BOOL WINAPI EnumDeviceCallBack(GUID FAR *lpGUID,LPSTR lpDevice,
LPSTR lpDeviceName,
LPVOID lpContext)
{ static char i=0;
lpDevices[i]=lpGUID;
i++;
Form1->ComboBox1->Items->Add((AnsiString)lpDevice+"--"+(AnsiString)lpDeviceName);
if(i<10)
return(DDENUMRET_OK);
else
return(DDENUMRET_CANCEL);
}
//列举设备---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ComboBox1->Clear();
if(FAILED(DirectDrawEnumerate(EnumDeviceCallBack,NULL)))
Edit1->Text="Enumerate Devices failed!";
else
Edit1->Text="Enumerate Devices OK!";
ComboBox1->ItemIndex=0;
Button1->Enabled=false;
Button2->Enabled=true;
}
//成立DirectDraw对象---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
LPGUID FAR lpD=lpDevices[ComboBox1->ItemIndex];
if(FAILED(DirectDrawCreate(lpD,&lplpDD,NULL)))
Edit1->Text="DirectDraw Create failed!";
else
{
Edit1->Text="DirectDraw Create OK!";
ComboBox1->Enabled=false;
Button2->Enabled=false;
Button3->Enabled=true;
}
}
//得到IDirectDraw2接口---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
if(FAILED(lplpDD->QueryInterface(IID_IDirectDraw2,(LPVOID *)&lplpDD2)))
Edit1->Text="Get IDriectDraw2 Interface Failed!";
else
{
Edit1->Text="Get IDriectDraw2 Interface OK!";
lplpDD->Release(); /* 释放IdirectDraw接口 */
Button3->Enabled=false;
Button4->Enabled=true;
}
}
以上是“<b>在CB中举行DirectX编程(2)</b>[VC/C++编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |