获取屏幕分辨率及位深

//---------------------------------------------------------------------------

#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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值