//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "EnumDisplaySettings.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
#define MAX_PELS_NUM 200
#define MAX_BITSPERPEL_NUM 10
#define MIN_PELSWIDTH 799
#define MIN_BITSPERPEL 7
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
int iPelsNum = 0;
int iBitsPerPelNum = 0;
int dmPels[MAX_PELS_NUM][2];
int dmBitsPerPel[MAX_BITSPERPEL_NUM];
ZeroMemory(&dmPels, sizeof(dmPels));
ZeroMemory(&dmBitsPerPel, sizeof(dmBitsPerPel));
GetDevModeEnum(dmPels,iPelsNum,dmBitsPerPel,iBitsPerPelNum);
int m_dmDefaultPels[2],m_dmDefaultBitsPerPel;
GetDefaultDevMode(m_dmDefaultPels, m_dmDefaultBitsPerPel);
}
//---------------------------------------------------------------------------
bool TForm1::GetValueIndex(int Array2[][2],int num,int iValue[],int &index)
{
for(index = 0; index < num; index++)
{
if((Array2[index][0] == iValue[0]) && (Array2[index][1] == iValue[1]))
return true;
}
return false;
}
bool TForm1::GetValueIndex(int iArray[],int num,int iValue,int &index)
{
for(index = 0; index < num; index++)
{
if(iArray[index] == iValue)
return true;
}
return false;
}
void TForm1::GetDevModeEnum(int dmPels[][2],int &iNum,int dmBitsPerPel[],int &iBitDepthNum)
{
DEVMODE lpDevMode;
int iCurDisplayModel[2]={0};
int index = 0;
// inspect the DEVMODE structure to obtain details
// about the display settings such as
// - Orientation
// - Width and Height
// - Frequency
// - etc.
// initialize the DEVMODE structure
//ZeroMemory(&lpDevMode, sizeof(lpDevMode));
//lpDevMode.dmSize = sizeof(lpDevMode);
int m_MindmPelsWidth = MIN_PELSWIDTH;
int m_MindmBitsPerPel = MIN_BITSPERPEL;
iNum = 0;
iBitDepthNum = 0;
int iTempIndex;
while (0 != EnumDisplaySettings(NULL, index++, &lpDevMode))
{
iCurDisplayModel[0] = lpDevMode.dmPelsWidth;
iCurDisplayModel[1] = lpDevMode.dmPelsHeight;
if(lpDevMode.dmPelsWidth > m_MindmPelsWidth)
{
if(!GetValueIndex(dmPels,iNum,iCurDisplayModel,iTempIndex))
{
dmPels[iNum][0] = iCurDisplayModel[0];
dmPels[iNum][1] = iCurDisplayModel[1];
++iNum;
}
}
if(lpDevMode.dmBitsPerPel > m_MindmBitsPerPel)
{
if(!GetValueIndex(dmBitsPerPel,iBitDepthNum,lpDevMode.dmBitsPerPel,iTempIndex))
{
dmBitsPerPel[iBitDepthNum++] = lpDevMode.dmBitsPerPel;
}
}
}
if(iNum != 13)//han...
{
dmPels[0][0] = GetSystemMetrics(SM_CXSCREEN);
dmPels[0][1] = GetSystemMetrics(SM_CYSCREEN);
iNum++;
}
}
void TForm1::GetDefaultDevMode(int dmPels[],int &dmBitDepth)
{
dmPels[0] = GetSystemMetrics(SM_CXSCREEN);
dmPels[1] = GetSystemMetrics(SM_CYSCREEN);
dmBitDepth = GetDeviceCaps(GetDC(Handle), BITSPIXEL);
}