D *)&lplpDD2)))
Edit1->Text="Get IDriectDraw2 Interface Failed!";
else
{
Edit1->Text="Get IDriectDraw2 Interface OK!";
lplpDD->Release(); /* 释放IdirectDraw接口 */
Button3->Enabled=false;
Button4->Enabled=true;
}
}
//设置协作级别---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
DWORD dwFlags=0;
if(CheckBox1->Checked) dwFlags=dwFlags|DDSCL_ALLOWMODEX;
if(CheckBox2->Checked) dwFlags=dwFlags|DDSCL_ALLOWREBOOT;
if(CheckBox3->Checked) dwFlags=dwFlags|DDSCL_EXCLUSIVE;
if(CheckBox4->Checked) dwFlags=dwFlags|DDSCL_FULLSCREEN;
if(CheckBox5->Checked) dwFlags=dwFlags|DDSCL_NORMAL;
if(CheckBox6->Checked) dwFlags=dwFlags|DDSCL_NOWINDOWCHANGES;
if(FAILED(lplpDD2->SetCooperativeLevel(Handle,dwFlags)))
Edit1->Text="Set set cooperative level Failed!";
else
{
Edit1->Text="Set cooperative level OK!";
GroupBox2->Enabled=false;
Button4->Enabled=false;
Button5->Enabled=true;
}
}
//枚举显示模式的回调函数---------------------------------------------------------------------------
BOOL WINAPI EnumDisplayModesCallBack(LPDDSURFACEDESC lpDesc,
LPVOID lpContext)
{
static int i=0;
char buff[256];
wsprintf(buff,"%dx%dx%dx%d",
lpDesc->dwWidth,
lpDesc->dwHeight,
lpDesc->ddpfPixelFormat.dwRGBBitCount,
lpDesc->dwRefreshRate);
Form1->ComboBox2->Items->Add(buff);
DisplayMode[i].Width=lpDesc->dwWidth;
DisplayMode[i].Height=lpDesc->dwHeight;
DisplayMode[i].Depth=lpDesc->ddpfPixelFormat.dwRGBBitCount;
DisplayMode[i].Rate=lpDesc->dwRefreshRate;
i++;
if(i<100)
return(DDENUMRET_OK);
else
return(DDENUMRET_CANCEL);
}
//枚举显示模式---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
ComboBox2->Clear();
if(FAILED(lplpDD2->EnumDisplayModes(DDEDM_STANDARDVGAMODES,
NULL,
NULL,
(LPDDENUMMODESCALLBACK)EnumDisplayModesCallBack)))
Edit1->Text="Enumerate Display Modes failed!";
else
{
Edit1->Text="Enumerate Display Modes OK!";
ComboBox2->ItemIndex=0;
Button5->Enabled=false;
Button6->Enabled=true;
}
}
//设置显示模式---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender)
{
if(ComboBox2->ItemIndex<0)
{
ShowMessage("请先在DDraw2下拉框中选择一种显示方式");
return;
}
if(FAILED(lplpDD2->SetDisplayMode(
DisplayMode[ComboBox2->ItemIndex].Width,
DisplayMode[ComboBox2->ItemIndex].Height,
DisplayMode[ComboBox2->ItemIndex].Depth,
DisplayMode[ComboBox2->ItemIndex].Rate,
0)))
Edit1->Text="Set DisplayMode failed!";
}
//退出dx1---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
if(lplpDD2) lplpDD2->Release();
} |