DisplayInfo.h
 #pragma once

 enum WinVerDef
{
WIN_VER_UNKNOWN = -,
WIN_VER_95 = ,
WIN_VER_98,
WIN_VER_ME,
WIN_VER_NT4,
WIN_VER_2K,
WIN_VER_XP,
WIN_VER_XP64,
WIN_VER_2K3,
WIN_VER_2K3R2,
WIN_VER_VISTA,
WIN_VER_2K8,
WIN_VER_2K8R2,
WIN_VER_WIN7,
}; class CDisplayInfo
{
private:
CDisplayInfo(void);
~CDisplayInfo(void);
public:
enum {DISPLAY_TYPE_SINGLE=,DISPLAY_TYPE_CLONE=,DISPLAY_TYPE_EXTEND=};
static int GetDisplayMode();
static int GetDisplayModeXP();
static int GetDisplayModeWin7();
static BOOL SetScreenSaver(BOOL bCancle=TRUE,UINT newTime=-);
static BOOL SetPowerSaver(BOOL bCancle=TRUE,UINT newTime=-);
static BOOL SetDisplayMode(int iType,BOOL ExChange=FALSE);
static BOOL SetDisplayModeXP(int iType,BOOL ExChange=FALSE);
static BOOL SetDisplayModeWin7(int iType,BOOL ExChange=FALSE);
static int GetDisplayCardType();
static int AnalyCardType(LPCTSTR cardStr);
static BOOL GetOSVersion( WinVerDef* winVer );
static BOOL IsOlderSystem( WinVerDef specVer, INT* iResult );
static BOOL GetPrimaryMonitorInfo(DEVMODE *dvm);
};
DisplayInfo.cpp
 #include "StdAfx.h"
#include "DisplayInfo.h" enum WinVerMajor
{
WIN_MAJOR_NT4_ME_98_95 = ,
WIN_MAJOR_2K3R2_2K3_XP_2K = ,
WIN_MAJOR_WIN7_2K8R2_2K8_VISTA = ,
}; // 定义目前存在的操作系统次版本号 enum WinVerminor
{
WIN_MINOR_2K8_VISTA_2K_NT4_95 = ,
WIN_MINOR_WIN7_2K8R2_XP = ,
WIN_MINOR_2K3R2_2K3_XP64 = ,
WIN_MINOR_98 = ,
WIN_MINOR_ME = ,
};
//typedef void (WINAPI *GetNativeSystemInfoFunc)(LPSYSTEM_INFO); #define QDC_ALL_PATHS 0x00000001
#define QDC_ONLY_ACTIVE_PATHS 0x00000002
#define QDC_DATABASE_CURRENT 0x00000004 //
// Definitions used by SetDisplayConfig.
// #define SDC_TOPOLOGY_INTERNAL 0x00000001
#define SDC_TOPOLOGY_CLONE 0x00000002
#define SDC_TOPOLOGY_EXTEND 0x00000004
#define SDC_TOPOLOGY_EXTERNAL 0x00000008
#define SDC_TOPOLOGY_SUPPLIED 0x00000010
#define SDC_USE_DATABASE_CURRENT (SDC_TOPOLOGY_INTERNAL | SDC_TOPOLOGY_CLONE | SDC_TOPOLOGY_EXTEND | SDC_TOPOLOGY_EXTERNAL) #define SDC_USE_SUPPLIED_DISPLAY_CONFIG 0x00000020
#define SDC_VALIDATE 0x00000040
#define SDC_APPLY 0x00000080
#define SDC_NO_OPTIMIZATION 0x00000100
#define SDC_SAVE_TO_DATABASE 0x00000200
#define SDC_ALLOW_CHANGES 0x00000400
#define SDC_PATH_PERSIST_IF_REQUIRED 0x00000800
#define SDC_FORCE_MODE_ENUMERATION 0x00001000
#define SDC_ALLOW_PATH_ORDER_CHANGES 0x00002000 typedef enum {
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_OTHER = -,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HD15 = ,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SVIDEO = ,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPOSITE_VIDEO = ,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPONENT_VIDEO = ,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DVI = ,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HDMI = ,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_LVDS = ,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_D_JPN = ,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDI = ,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EXTERNAL = ,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED = ,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EXTERNAL = ,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EMBEDDED = ,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDTVDONGLE = ,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL = 0x80000000,
DISPLAYCONFIG_OUTPUT_TECHNOLOGY_FORCE_UINT32 = 0xFFFFFFFF
} DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY; typedef enum {
DISPLAYCONFIG_ROTATION_IDENTITY = ,
DISPLAYCONFIG_ROTATION_ROTATE90 = ,
DISPLAYCONFIG_ROTATION_ROTATE180 = ,
DISPLAYCONFIG_ROTATION_ROTATE270 = ,
DISPLAYCONFIG_ROTATION_FORCE_UINT32 = 0xFFFFFFFF
} DISPLAYCONFIG_ROTATION; typedef enum {
DISPLAYCONFIG_SCALING_IDENTITY = ,
DISPLAYCONFIG_SCALING_CENTERED = ,
DISPLAYCONFIG_SCALING_STRETCHED = ,
DISPLAYCONFIG_SCALING_ASPECTRATIOCENTEREDMAX = ,
DISPLAYCONFIG_SCALING_CUSTOM = ,
DISPLAYCONFIG_SCALING_PREFERRED = ,
DISPLAYCONFIG_SCALING_FORCE_UINT32 = 0xFFFFFFFF
} DISPLAYCONFIG_SCALING;
typedef struct DISPLAYCONFIG_RATIONAL {
UINT32 Numerator;
UINT32 Denominator;
} DISPLAYCONFIG_RATIONAL;
typedef enum {
DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED = ,
DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE = ,
DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED = ,
DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_UPPERFIELDFIRST = DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED,
DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_LOWERFIELDFIRST = ,
DISPLAYCONFIG_SCANLINE_ORDERING_FORCE_UINT32 = 0xFFFFFFFF
} DISPLAYCONFIG_SCANLINE_ORDERING; typedef enum {
DISPLAYCONFIG_PIXELFORMAT_8BPP = ,
DISPLAYCONFIG_PIXELFORMAT_16BPP = ,
DISPLAYCONFIG_PIXELFORMAT_24BPP = ,
DISPLAYCONFIG_PIXELFORMAT_32BPP = ,
DISPLAYCONFIG_PIXELFORMAT_NONGDI = ,
DISPLAYCONFIG_PIXELFORMAT_FORCE_UINT32 = 0xffffffff
} DISPLAYCONFIG_PIXELFORMAT;
typedef enum {
DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE = ,
DISPLAYCONFIG_MODE_INFO_TYPE_TARGET = ,
DISPLAYCONFIG_MODE_INFO_TYPE_FORCE_UINT32 = 0xFFFFFFFF
} DISPLAYCONFIG_MODE_INFO_TYPE; typedef enum {
DISPLAYCONFIG_TOPOLOGY_INTERNAL = 0x00000001,
DISPLAYCONFIG_TOPOLOGY_CLONE = 0x00000002,
DISPLAYCONFIG_TOPOLOGY_EXTEND = 0x00000004,
DISPLAYCONFIG_TOPOLOGY_EXTERNAL = 0x00000008,
DISPLAYCONFIG_TOPOLOGY_FORCE_UINT32 = 0xFFFFFFFF
} DISPLAYCONFIG_TOPOLOGY_ID; typedef struct DISPLAYCONFIG_PATH_TARGET_INFO {
LUID adapterId;
UINT32 id;
UINT32 modeInfoIdx;
DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY outputTechnology;
DISPLAYCONFIG_ROTATION rotation;
DISPLAYCONFIG_SCALING scaling;
DISPLAYCONFIG_RATIONAL refreshRate;
DISPLAYCONFIG_SCANLINE_ORDERING scanLineOrdering;
BOOL targetAvailable;
UINT32 statusFlags;
} DISPLAYCONFIG_PATH_TARGET_INFO;
typedef struct DISPLAYCONFIG_PATH_SOURCE_INFO {
LUID adapterId;
UINT32 id;
UINT32 modeInfoIdx;
UINT32 statusFlags;
} DISPLAYCONFIG_PATH_SOURCE_INFO;
typedef struct DISPLAYCONFIG_PATH_INFO {
DISPLAYCONFIG_PATH_SOURCE_INFO sourceInfo;
DISPLAYCONFIG_PATH_TARGET_INFO targetInfo;
UINT32 flags;
} DISPLAYCONFIG_PATH_INFO;
typedef struct DISPLAYCONFIG_2DREGION {
UINT32 cx;
UINT32 cy;
} DISPLAYCONFIG_2DREGION;
typedef struct DISPLAYCONFIG_VIDEO_SIGNAL_INFO {
UINT64 pixelRate;
DISPLAYCONFIG_RATIONAL hSyncFreq;
DISPLAYCONFIG_RATIONAL vSyncFreq;
DISPLAYCONFIG_2DREGION activeSize;
DISPLAYCONFIG_2DREGION totalSize;
UINT32 videoStandard;
DISPLAYCONFIG_SCANLINE_ORDERING scanLineOrdering;
} DISPLAYCONFIG_VIDEO_SIGNAL_INFO; typedef struct DISPLAYCONFIG_TARGET_MODE {
DISPLAYCONFIG_VIDEO_SIGNAL_INFO targetVideoSignalInfo;
} DISPLAYCONFIG_TARGET_MODE; typedef struct DISPLAYCONFIG_SOURCE_MODE {
UINT32 width;
UINT32 height;
DISPLAYCONFIG_PIXELFORMAT pixelFormat;
POINTL position;
} DISPLAYCONFIG_SOURCE_MODE; typedef struct DISPLAYCONFIG_MODE_INFO {
DISPLAYCONFIG_MODE_INFO_TYPE infoType;
UINT32 id;
LUID adapterId;
union {
DISPLAYCONFIG_TARGET_MODE targetMode;
DISPLAYCONFIG_SOURCE_MODE sourceMode;
};
} DISPLAYCONFIG_MODE_INFO;
typedef LONG (WINAPI *SETDISPLAYCONFIGFUNC)(__in UINT32 numPathArrayElements,
__in_opt DISPLAYCONFIG_PATH_INFO *pathArray,
__in UINT32 numModeInfoArrayElements,
__in_opt DISPLAYCONFIG_MODE_INFO *modeInfoArray,
__in UINT32 Flags
);
typedef LONG (WINAPI *GETDISPLAYBUFFERSIZESFUNC)(
__in UINT32 Flags,
__out UINT32 *pNumPathArrayElements,
__out UINT32 *pNumModeInfoArrayElements
); typedef LONG (WINAPI *QUERYDISPLAYCONFIGFUNC)(
__in UINT32 Flags,
__inout UINT32 *pNumPathArrayElements,
__out DISPLAYCONFIG_PATH_INFO *pPathInfoArray,
__inout UINT32 *pNumModeInfoArrayElements,
__out DISPLAYCONFIG_MODE_INFO *pModeInfoArray,
__out_opt DISPLAYCONFIG_TOPOLOGY_ID *pCurrentTopologyId
); CDisplayInfo::CDisplayInfo(void)
{
} CDisplayInfo::~CDisplayInfo(void)
{
} //功能: 设置/取消屏保
//参数: bCancle: TRUE取消屏保,此时会自动记录原来的屏保时间.FALSE设置屏保,如果newTime为-1,则恢复原来的屏保时间.
// newTime:屏保时间,如果为-1,则被忽略.
BOOL CDisplayInfo::SetScreenSaver(BOOL bCancle/* =TRUE */,UINT newTime/* =-1 */)
{
static UINT ScrSaverTimeOut=;
if(bCancle)
{
//读取原来的屏保时间,以便恢复
::SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT,,&ScrSaverTimeOut,); //取消屏保.
::SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,FALSE,,SPIF_UPDATEINIFILE|SPIF_SENDCHANGE);
}
else
{
UINT TimeOut=ScrSaverTimeOut;
if(newTime != UINT(-))
{
TimeOut=newTime;
}
//设置原来的屏保时间
::SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT,TimeOut,NULL,SPIF_UPDATEINIFILE|SPIF_SENDCHANGE);
//激活屏保.
::SystemParametersInfo(SPI_SETSCREENSAVEACTIVE,TRUE,,SPIF_UPDATEINIFILE|SPIF_SENDCHANGE);
}
return TRUE;
} //功能: 设置/取消显示器电源自动关闭.
//参数: bCancle: TRUE取消自动关闭显示器电源,FLASE设置自动关闭显示器电源.
// newTime: 新的显示器电源自动关闭时间,如果为-1,设置时按原来显示器电源时间设置.
BOOL CDisplayInfo::SetPowerSaver(BOOL bCancle/* =TRUE */,UINT newTime/* =-1 */)
{
static UINT PowerTimeout=;
if(bCancle)
{
//获得原来电源时间.
::SystemParametersInfo(SPI_GETPOWEROFFTIMEOUT,,&PowerTimeout,);
//取消自动关闭显示器
//这里不能用SPI_SETPOWEROFFACTIVE,用这个标记不能成功.
::SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT,FALSE,,SPIF_UPDATEINIFILE|SPIF_SENDCHANGE);
}
else
{
UINT TimeOut=PowerTimeout;
if(newTime != UINT(-))
{
TimeOut=newTime;
}
//设置原来的电源时间.
::SystemParametersInfo(SPI_SETPOWEROFFTIMEOUT,TimeOut,NULL,SPIF_UPDATEINIFILE|SPIF_SENDCHANGE);
//激活自动关闭显示器.
::SystemParametersInfo(SPI_SETPOWEROFFACTIVE,TRUE,,SPIF_UPDATEINIFILE|SPIF_SENDCHANGE);
}
return TRUE;
} //功能: 获得Win7n以前OS当前多显示器的显示模式.
//返回值: DISPLAY_TYPE_SINGLE:单显示器;
// DISPLAY_TYPE_CLONE ;复制模式
// DISPLAY_TYPE_EXTEND:扩展模式;
int CDisplayInfo::GetDisplayModeXP()
{
if( != GetDisplayCardType())//是否ATI显卡
{
return ;
}
DISPLAY_DEVICE DispDev;
TCHAR szSaveDeviceName[0x60];
BOOL bRet = TRUE; DEVMODE dvm;
dvm.dmSize=sizeof(DEVMODE);
dvm.dmDriverExtra=;
dvm.dmFields=DM_POSITION; ZeroMemory(&DispDev, sizeof(DISPLAY_DEVICE));
DispDev.cb = sizeof(DISPLAY_DEVICE); DWORD d1=,d2=,d1m0=,d1m1=,d2m0=,d2m1=; CString Str,outStr;
int i=,j=;
BOOL bRet2=TRUE;
DWORD erro=;
int jDev=;
while(bRet)
{
bRet=EnumDisplayDevices(NULL,i,&DispDev,);//遍历当前设备.
if(bRet)
{
memset(szSaveDeviceName,,0x60);
lstrcpy(szSaveDeviceName, DispDev.DeviceName);
bRet2=TRUE;
j=;
OutputDebugString(szSaveDeviceName);
Str.Format(TEXT("%08X ------------------------------------"),DispDev.StateFlags);
OutputDebugString(Str);
if(i==)
{
d1=DispDev.StateFlags;
}
else if(i==)
{
d2=DispDev.StateFlags;
}
while(bRet2)
{
bRet2=EnumDisplayDevices(szSaveDeviceName,j,&DispDev,);//遍历指定设备下的其它设备参数.
if(bRet2)
{
j++;
if(_tcsstr(DispDev.DeviceName,TEXT("Default_Monitor"))!=NULL)
{
continue;
}
BOOL t=EnumDisplaySettings(DispDev.DeviceName,ENUM_CURRENT_SETTINGS,&dvm);//遍历指定设备的当前配置.
if(t==FALSE)
{
erro=GetLastError();
}
OutputDebugString(DispDev.DeviceName);
//OutputDebugString(DispDev.DeviceString);
OutputDebugString(DispDev.DeviceID);//LED
//OutputDebugString(DispDev.DeviceKey);
Str.Format(TEXT("%08X\r\n"),DispDev.StateFlags);
OutputDebugString(Str);
if(i==)
{
if(jDev==)
{
d1m0=DispDev.StateFlags;
}
else if(jDev==)
{
d1m1=DispDev.StateFlags;
}
}
else if(i==)
{
if(jDev==)
{
d2m0=DispDev.StateFlags;
}
else if(jDev==)
{
d2m1=DispDev.StateFlags;
}
}
jDev++;
} }
}
++i;
} if((d1&DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)==DISPLAY_DEVICE_ATTACHED_TO_DESKTOP &&
(d2&DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)==DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)
{
OutputDebugString(TEXT("扩展模式"));
return DISPLAY_TYPE_EXTEND;
} if( (d1m0&DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)==DISPLAY_DEVICE_ATTACHED_TO_DESKTOP &&
(d1m1&DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)==DISPLAY_DEVICE_ATTACHED_TO_DESKTOP )
{
OutputDebugString(TEXT("复制模式"));
return DISPLAY_TYPE_CLONE;
} OutputDebugString(TEXT("单显示器"));
return DISPLAY_TYPE_SINGLE;
} //功能: 获得Win7下当前多显示器的显示模式.
//返回值: DISPLAY_TYPE_SINGLE:单显示器;
// DISPLAY_TYPE_CLONE ;复制模式
// DISPLAY_TYPE_EXTEND:扩展模式;
int CDisplayInfo::GetDisplayModeWin7()
{
QUERYDISPLAYCONFIGFUNC QueryDisplayConfig=NULL;
HMODULE hMod=LoadLibrary(TEXT("user32.dll"));
if(hMod)
{
QueryDisplayConfig=(QUERYDISPLAYCONFIGFUNC)GetProcAddress(hMod,"QueryDisplayConfig");
if( QueryDisplayConfig)
{
UINT32 NumPathArrayElements = ;
UINT32 NumModeInfoArrayElements = ;
LONG returnValue=;
DISPLAYCONFIG_TOPOLOGY_ID topID=DISPLAYCONFIG_TOPOLOGY_FORCE_UINT32;
returnValue = QueryDisplayConfig(
QDC_DATABASE_CURRENT,
NULL, NULL,
NULL, NULL,
&topID);
if(returnValue == ERROR_SUCCESS)
{
int ret=;
switch(topID)
{
case DISPLAYCONFIG_TOPOLOGY_CLONE:
ret=DISPLAY_TYPE_CLONE;
break;
case DISPLAYCONFIG_TOPOLOGY_EXTEND:
ret=DISPLAY_TYPE_EXTEND;
break;
default:
ret=DISPLAY_TYPE_SINGLE;
break;
}
return ret;
}
}
}
return ;
} //功能: 获得当前多显示器的显示模式.
//返回值: DISPLAY_TYPE_SINGLE:单显示器;
// DISPLAY_TYPE_CLONE ;复制模式
// DISPLAY_TYPE_EXTEND:扩展模式;
int CDisplayInfo::GetDisplayMode()
{
WinVerDef OsVer;
int ret=;
if(GetOSVersion(&OsVer))
{
switch(OsVer)
{
case WIN_VER_WIN7:
ret=GetDisplayModeWin7();
break;
default:
ret=GetDisplayModeXP();
break;
}
}
return ret;
} BOOL CDisplayInfo::GetPrimaryMonitorInfo(DEVMODE *dvm)
{
if(dvm==NULL)
{
return FALSE;
}
dvm->dmSize=sizeof(DEVMODE); DISPLAY_DEVICE DispDev;
BOOL bRet = TRUE;
ZeroMemory(&DispDev, sizeof(DISPLAY_DEVICE));
DispDev.cb = sizeof(DISPLAY_DEVICE);
int i=;
DWORD erro=;
while(bRet)
{
bRet=EnumDisplayDevices(NULL,i,&DispDev,);
if(bRet)
{
if(DispDev.StateFlags&DISPLAY_DEVICE_PRIMARY_DEVICE)
{
bRet=EnumDisplaySettings(DispDev.DeviceName,ENUM_CURRENT_SETTINGS,dvm);
if(bRet)
{
return TRUE;
}
}
}
i++;
}
return FALSE;
} //功能:设置多显示器显示模式
//参数:iType;显示模式,可选以下三种:
// DISPLAY_TYPE_SINGLE; 单显示器
// DISPLAY_TYPE_CLONE; 复制模式
// DISPLAY_TYEP_EXTEND; 扩展模式 BOOL CDisplayInfo::SetDisplayMode(int iType,BOOL ExChange/* =FALSE */)
{
WinVerDef osVer;
if(GetOSVersion(&osVer))
{
if(osVer==WIN_VER_WIN7)
{
OutputDebugString(TEXT("Win7"));
SetDisplayModeWin7(iType,ExChange);
}
else
{
OutputDebugString(TEXT("Other OS"));
SetDisplayModeXP(iType,ExChange);
}
return TRUE;
}
return FALSE;
} //临时测试用
void OutPath(DISPLAYCONFIG_PATH_INFO *pPath)
{
CString Str;
Str=TEXT("--------------------PATH-----------------------\r\n");
OutputDebugString(Str);
Str.Format(TEXT("state:%08X\r\n"),pPath->flags);
OutputDebugString(Str);
Str.Format(TEXT("source:\r\nadapterID_H:%08X L:%08X\r\nID:%08X\r\nModeIndex:%08X\r\nFlag:%08X"),
pPath->sourceInfo.adapterId.HighPart,pPath->sourceInfo.adapterId.LowPart,
pPath->sourceInfo.id,pPath->sourceInfo.modeInfoIdx,pPath->sourceInfo.statusFlags);
OutputDebugString(Str);
Str.Format(TEXT("target:\r\nadapterId H: %08X L:%08X ID:%08X Index:%08X"),
pPath->targetInfo.adapterId.HighPart,pPath->targetInfo.adapterId.LowPart,
pPath->targetInfo.id,pPath->targetInfo.modeInfoIdx);
OutputDebugString(Str); switch(pPath->targetInfo.outputTechnology)//输出类型.
{
case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_OTHER:
OutputDebugStringA("outputTechnology: DISPLAYCONFIG_OUTPUT_TECHNOLOGY_OTHER\r\n");
break;
case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HD15:
OutputDebugStringA("outputTechnology: DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HD15\r\n");
break;
case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SVIDEO:
OutputDebugStringA("outputTechnology: DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SVIDEO\r\n");
break;
case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPOSITE_VIDEO :
OutputDebugStringA("outputTechnology: DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPOSITE_VIDEO\r\n");
break;
case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPONENT_VIDEO :
OutputDebugStringA("outputTechnology: DISPLAYCONFIG_OUTPUT_TECHNOLOGY_COMPONENT_VIDEO\r\n");
break;
case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DVI:
OutputDebugStringA("outputTechnology: DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DVI\r\n");
break;
case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HDMI:
OutputDebugStringA("outputTechnology: DISPLAYCONFIG_OUTPUT_TECHNOLOGY_HDMI\r\n");
break;
case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_LVDS:
OutputDebugStringA("outputTechnology: DISPLAYCONFIG_OUTPUT_TECHNOLOGY_LVDS\r\n");
break;
case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_D_JPN:
OutputDebugStringA("outputTechnology: outputTechnology: DISPLAYCONFIG_OUTPUT_TECHNOLOGY_D_JPN\r\n");
break;
case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDI:
OutputDebugStringA("outputTechnology: DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDI\r\n");
break;
case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EXTERNAL:
OutputDebugStringA("outputTechnology: DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EXTERNAL\r\n");
break;
case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED:
OutputDebugStringA("outputTechnology: DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED\r\n");
break;
case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EXTERNAL:
OutputDebugStringA("outputTechnology: DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EXTERNAL\r\n");
break;
case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EMBEDDED:
OutputDebugStringA("outputTechnology: DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EMBEDDED\r\n");
break;
case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDTVDONGLE:
OutputDebugStringA("outputTechnology: DISPLAYCONFIG_OUTPUT_TECHNOLOGY_SDTVDONGLE\r\n");
break;
case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL :
OutputDebugStringA("outputTechnology: DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL\r\n");
break;
/*case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_FORCE_UINT32:
OutputDebugStringA("outputTechnology: DISPLAYCONFIG_OUTPUT_TECHNOLOGY_FORCE_UINT32\r\n");
break;*/
} Str.Format(TEXT("refreshRate--Numerator:%-08X Denominator:%08X"),
pPath->targetInfo.refreshRate.Numerator,pPath->targetInfo.refreshRate.Denominator); switch(pPath->targetInfo.rotation)
{
case DISPLAYCONFIG_ROTATION_IDENTITY:
OutputDebugString(TEXT("rotation: DISPLAYCONFIG_ROTATION_IDENTITY\r\n"));
break;
case DISPLAYCONFIG_ROTATION_ROTATE90:
OutputDebugString(TEXT("rotation: DISPLAYCONFIG_ROTATION_ROTATE90\r\n"));
break;
case DISPLAYCONFIG_ROTATION_ROTATE180:
OutputDebugString(TEXT("rotation: DISPLAYCONFIG_ROTATION_ROTATE180\r\n"));
break;
case DISPLAYCONFIG_ROTATION_ROTATE270:
OutputDebugString(TEXT("rotation: DISPLAYCONFIG_ROTATION_ROTATE270\r\n"));
break;
case DISPLAYCONFIG_ROTATION_FORCE_UINT32:
OutputDebugString(TEXT("rotation: DISPLAYCONFIG_ROTATION_FORCE_UINT32\r\n"));
break;
} switch(pPath->targetInfo.scaling)
{
case DISPLAYCONFIG_SCALING_IDENTITY:
OutputDebugString(TEXT("scaling: DISPLAYCONFIG_SCALING_IDENTITY\r\n"));
break;
case DISPLAYCONFIG_SCALING_CENTERED:
OutputDebugString(TEXT("scaling: DISPLAYCONFIG_SCALING_CENTERED\r\n"));
break;
case DISPLAYCONFIG_SCALING_STRETCHED:
OutputDebugString(TEXT("scaling: DISPLAYCONFIG_SCALING_STRETCHED\r\n"));
break;
case DISPLAYCONFIG_SCALING_ASPECTRATIOCENTEREDMAX:
OutputDebugString(TEXT("scaling: DISPLAYCONFIG_SCALING_ASPECTRATIOCENTEREDMAX\r\n"));
break;
case DISPLAYCONFIG_SCALING_CUSTOM:
OutputDebugString(TEXT("scaling: DISPLAYCONFIG_SCALING_CUSTOM\r\n"));
break;
case DISPLAYCONFIG_SCALING_PREFERRED:
OutputDebugString(TEXT("scaling: DISPLAYCONFIG_SCALING_PREFERRED\r\n"));
break;
case DISPLAYCONFIG_SCALING_FORCE_UINT32:
OutputDebugString(TEXT("scaling: DISPLAYCONFIG_SCALING_FORCE_UINT32\r\n"));
break;
}
switch(pPath->targetInfo.scanLineOrdering)
{
case DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED:
OutputDebugString(TEXT("scanLineOrdering: DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED\r\n"));
break;
case DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE:
OutputDebugString(TEXT("scanLineOrdering: \r\n"));
break;
case DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED:
OutputDebugString(TEXT("scanLineOrdering: DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE\r\n"));
break;
/*case DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_UPPERFIELDFIRST:
OutputDebugString(TEXT("scanLineOrdering: DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_UPPERFIELDFIRST\r\n"));
break;*/
case DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_LOWERFIELDFIRST:
OutputDebugString(TEXT("scanLineOrdering: DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_LOWERFIELDFIRST\r\n"));
break;
case DISPLAYCONFIG_SCANLINE_ORDERING_FORCE_UINT32:
OutputDebugString(TEXT("scanLineOrdering: DISPLAYCONFIG_SCANLINE_ORDERING_FORCE_UINT32\r\n"));
break;
}
Str.Format(TEXT("state:%08X valiable:%08X"),
pPath->targetInfo.statusFlags,pPath->targetInfo.targetAvailable);
OutputDebugString(Str); }
//临时测试用
void OutMode(DISPLAYCONFIG_MODE_INFO *pMode)
{
CString Str;
OutputDebugString(TEXT("-----------------------MODE------------------------\r\n"));
Str.Format(TEXT("adpterID H:%08X L:%98X ID:%08X"),
pMode->adapterId.HighPart,pMode->adapterId.LowPart,pMode->id);
OutputDebugString(Str);
switch(pMode->infoType)
{
case DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE:
OutputDebugString(TEXT("infotype DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE\r\n"));
break;
case DISPLAYCONFIG_MODE_INFO_TYPE_TARGET:
OutputDebugString(TEXT("infotype DISPLAYCONFIG_MODE_INFO_TYPE_TARGET\r\n"));
break;
case DISPLAYCONFIG_MODE_INFO_TYPE_FORCE_UINT32:
OutputDebugString(TEXT("infotype DISPLAYCONFIG_MODE_INFO_TYPE_FORCE_UINT32\r\n"));
break;
}
switch(pMode->sourceMode.pixelFormat)
{
case DISPLAYCONFIG_PIXELFORMAT_16BPP:
OutputDebugString(TEXT("source pixelFormat: DISPLAYCONFIG_PIXELFORMAT_16BPP\r\n"));
break;
case DISPLAYCONFIG_PIXELFORMAT_8BPP:
OutputDebugString(TEXT("source pixelFormat: DISPLAYCONFIG_PIXELFORMAT_8BPP\r\n"));
break;
case DISPLAYCONFIG_PIXELFORMAT_32BPP:
OutputDebugString(TEXT("source pixelFormat: DISPLAYCONFIG_PIXELFORMAT_32BPP\r\n"));
break;
case DISPLAYCONFIG_PIXELFORMAT_24BPP:
OutputDebugString(TEXT("source pixelFormat: DISPLAYCONFIG_PIXELFORMAT_24BPP\r\n"));
break;
case DISPLAYCONFIG_PIXELFORMAT_NONGDI:
OutputDebugString(TEXT("source pixelFormat: DISPLAYCONFIG_PIXELFORMAT_NONGDI\r\n"));
break;
case DISPLAYCONFIG_PIXELFORMAT_FORCE_UINT32:
OutputDebugString(TEXT("source pixelFormat: DISPLAYCONFIG_PIXELFORMAT_FORCE_UINT32\r\n"));
break;
}
Str.Format(TEXT("source pos(%d,%d) Width:%d Height:%d\r\n"),
pMode->sourceMode.position.x,pMode->sourceMode.position.y,
pMode->sourceMode.width,pMode->sourceMode.height);
OutputDebugString(Str); Str.Format(TEXT("target activeSize(CX=%d,cy=%d)\r\n"),
pMode->targetMode.targetVideoSignalInfo.activeSize.cx,pMode->targetMode.targetVideoSignalInfo.activeSize.cy);
OutputDebugString(Str);
Str.Format(TEXT("target totalsize(cx=%d,cy=%d)"),
pMode->targetMode.targetVideoSignalInfo.totalSize.cx,
pMode->targetMode.targetVideoSignalInfo.totalSize.cy);
OutputDebugString(Str);
Str.Format(TEXT("target pixelRate:%016X videoStander:%08X\r\n"),
pMode->targetMode.targetVideoSignalInfo.pixelRate,
pMode->targetMode.targetVideoSignalInfo.videoStandard);
OutputDebugString(Str); Str.Format(TEXT("target Hfreq Numerator:%08X Denominator:%08X\r\n"),
pMode->targetMode.targetVideoSignalInfo.hSyncFreq.Numerator,
pMode->targetMode.targetVideoSignalInfo.hSyncFreq.Denominator);
OutputDebugString(Str);
Str.Format(TEXT("target Vfreq Numerator:%08X Denominator:%08X\r\n"),
pMode->targetMode.targetVideoSignalInfo.vSyncFreq.Numerator,
pMode->targetMode.targetVideoSignalInfo.vSyncFreq.Denominator);
OutputDebugString(Str);
switch(pMode->targetMode.targetVideoSignalInfo.scanLineOrdering)
{
case DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED:
OutputDebugString(TEXT("scanLineOrdering: DISPLAYCONFIG_SCANLINE_ORDERING_UNSPECIFIED\r\n"));
break;
case DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE:
OutputDebugString(TEXT("scanLineOrdering: \r\n"));
break;
case DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED:
OutputDebugString(TEXT("scanLineOrdering: DISPLAYCONFIG_SCANLINE_ORDERING_PROGRESSIVE\r\n"));
break;
/*case DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_UPPERFIELDFIRST:
OutputDebugString(TEXT("scanLineOrdering: DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_UPPERFIELDFIRST\r\n"));
break;*/
case DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_LOWERFIELDFIRST:
OutputDebugString(TEXT("scanLineOrdering: DISPLAYCONFIG_SCANLINE_ORDERING_INTERLACED_LOWERFIELDFIRST\r\n"));
break;
case DISPLAYCONFIG_SCANLINE_ORDERING_FORCE_UINT32:
OutputDebugString(TEXT("scanLineOrdering: DISPLAYCONFIG_SCANLINE_ORDERING_FORCE_UINT32\r\n"));
break;
} } BOOL CDisplayInfo::SetDisplayModeWin7(int iType,BOOL ExChange/* =FALSE */)
{
SETDISPLAYCONFIGFUNC SetDisplayConfig=NULL;
GETDISPLAYBUFFERSIZESFUNC GetDisplayConfigBufferSizes=NULL;
QUERYDISPLAYCONFIGFUNC QueryDisplayConfig=NULL;
HMODULE hMod=LoadLibrary(TEXT("user32.dll"));
if(hMod)
{
OutputDebugString(TEXT("Load OK"));
SetDisplayConfig=(SETDISPLAYCONFIGFUNC)GetProcAddress(hMod,"SetDisplayConfig");
GetDisplayConfigBufferSizes=(GETDISPLAYBUFFERSIZESFUNC)(GetProcAddress(hMod,"GetDisplayConfigBufferSizes"));
QueryDisplayConfig=(QUERYDISPLAYCONFIGFUNC)GetProcAddress(hMod,"QueryDisplayConfig");
if(SetDisplayConfig && GetDisplayConfigBufferSizes && QueryDisplayConfig)
{
UINT32 NumPathArrayElements = ;
UINT32 NumModeInfoArrayElements = ;
LONG returnValue;
returnValue = GetDisplayConfigBufferSizes(
QDC_ALL_PATHS,
&NumPathArrayElements,
&NumModeInfoArrayElements); // Returns Success
if (returnValue != ERROR_SUCCESS)
{
OutputDebugString(TEXT("GetDisplayConfigBufferSizes error"));
}
DISPLAYCONFIG_PATH_INFO *pPathInfoArray =
new DISPLAYCONFIG_PATH_INFO[NumPathArrayElements]; DISPLAYCONFIG_MODE_INFO *pModeInfoArray =
new DISPLAYCONFIG_MODE_INFO[NumModeInfoArrayElements]; DISPLAYCONFIG_TOPOLOGY_ID topID=DISPLAYCONFIG_TOPOLOGY_FORCE_UINT32;
returnValue = QueryDisplayConfig(
QDC_ALL_PATHS,
&NumPathArrayElements, pPathInfoArray,
&NumModeInfoArrayElements, pModeInfoArray,
NULL);
if(returnValue != ERROR_SUCCESS)
{
OutputDebugString(TEXT(" QueryDisplayConfig erro"));
}
CString Str;
for(int iPath=;iPath<NumPathArrayElements;++iPath)
{
OutPath(&pPathInfoArray[iPath]);
}
for(int iMode=;iMode<NumModeInfoArrayElements;++iMode)
{
OutMode(&pModeInfoArray[iMode]);
}
/*switch(topID)
{
case DISPLAYCONFIG_TOPOLOGY_CLONE:
OutputDebugString(TEXT("DISPLAYCONFIG_TOPOLOGY_CLONE"));
break;
case DISPLAYCONFIG_TOPOLOGY_INTERNAL:
OutputDebugString(TEXT("DISPLAYCONFIG_TOPOLOGY_INTERNAL"));
break;
case DISPLAYCONFIG_TOPOLOGY_EXTEND:
OutputDebugString(TEXT("DISPLAYCONFIG_TOPOLOGY_EXTEND"));
break;
case DISPLAYCONFIG_TOPOLOGY_EXTERNAL:
OutputDebugString(TEXT("DISPLAYCONFIG_TOPOLOGY_EXTERNAL"));
break;
case DISPLAYCONFIG_TOPOLOGY_FORCE_UINT32:
OutputDebugString(TEXT("DISPLAYCONFIG_TOPOLOGY_FORCE_UINT32"));
break;
default:
break;
}*/ OutputDebugString(TEXT("Get OK"));
//returnValue=SetDisplayConfig(NumPathArrayElements,pPathInfoArray,NumModeInfoArrayElements,pModeInfoArray,SDC_TOPOLOGY_CLONE|SDC_APPLY);
returnValue=SetDisplayConfig(,NULL,,NULL,iType|SDC_APPLY);//设置DC_TOPOLOGY_XXX前面4个参数must be 0;
switch(returnValue)
{
case ERROR_SUCCESS:
OutputDebugString(TEXT("ERRO_SUCESS"));
break;
case ERROR_INVALID_PARAMETER:
OutputDebugString(TEXT("ERROR_INVALID_PARAMETER"));
break;
case ERROR_NOT_SUPPORTED:
OutputDebugString(TEXT("ERROR_NOT_SUPPORTED"));
break;
case ERROR_ACCESS_DENIED:
OutputDebugString(TEXT("ERROR_ACCESS_DENIED"));
break;
case ERROR_GEN_FAILURE:
OutputDebugString(TEXT("ERROR_GEN_FAILURE"));
break;
case ERROR_INSUFFICIENT_BUFFER:
OutputDebugString(TEXT("ERROR_INSUFFICIENT_BUFFER"));
break;
default:
OutputDebugString(TEXT("unkonw"));
}
FreeLibrary(hMod);
return TRUE;
}
FreeLibrary(hMod);
}
return FALSE;
} BOOL CDisplayInfo::SetDisplayModeXP(int iType,BOOL ExChange/*=0*/)
{
DEVMODE dvm1;
memset(&dvm1, , sizeof(dvm1));
dvm1.dmSize = sizeof(dvm1);
DEVMODE dvm2;
memset(&dvm2, , sizeof(DEVMODE));
dvm2.dmSize = sizeof(DEVMODE); TCHAR PriDevName[0x100]={};
TCHAR AddDevName[0x100]={}; DISPLAY_DEVICE DispDev;
BOOL bRet = TRUE;
ZeroMemory(&DispDev, sizeof(DISPLAY_DEVICE));
DispDev.cb = sizeof(DISPLAY_DEVICE);
int i=;
int nOffset=;
BOOL bAnaly=FALSE;
while(bRet)
{
bRet=EnumDisplayDevices(NULL,i,&DispDev,);
if(bAnaly==FALSE)
{
bAnaly=TRUE;
if(==AnalyCardType(DispDev.DeviceName))//只能是API显示卡
{
return FALSE;
}
bAnaly=TRUE;
}
if(bRet)
{
if(DispDev.StateFlags&DISPLAY_DEVICE_PRIMARY_DEVICE)
{
_tcscpy_s(PriDevName,0x100,DispDev.DeviceName);
bRet=EnumDisplaySettingsEx(DispDev.DeviceName,ENUM_CURRENT_SETTINGS,&dvm1,EDS_RAWMODE);
}
else if((DispDev.StateFlags&0xFFFF)<)
{
_tcscpy_s(AddDevName,0x100,DispDev.DeviceName);
}
}
i++;
if(i==)
{
break;
}
}
if(i==)//只有一个显示器,不能进行模式设置.
{
return FALSE;
} dvm1.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_POSITION ;
dvm2.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_POSITION ;
//dvm2=dvm1;
dvm2.dmPelsHeight=dvm1.dmPelsHeight;
dvm2.dmPelsWidth=dvm1.dmPelsWidth;
switch(iType)
{
case DISPLAY_TYPE_SINGLE:
dvm2.dmPelsHeight=;//设置成单显示器.
dvm2.dmPelsWidth=;
break;
case DISPLAY_TYPE_CLONE://当两个显示器同时有效时,偏移不重叠.克隆模式就不能直接设置.
//dvm2.dmPelsHeight=0;
//dvm2.dmPelsWidth=0;
break;
case DISPLAY_TYPE_EXTEND:
nOffset=dvm1.dmPelsWidth;//强制横向向右扩展,
break;
default:
break;
}
dvm1.dmPosition.x=;
dvm1.dmPosition.y=;
dvm2.dmPosition.x=nOffset;
dvm2.dmPosition.y=; CString Str;
Str.Format(TEXT("Pri: %s (%d,%d,%d,%d)\r\n"),PriDevName,dvm1.dmPosition.x,dvm1.dmPosition.y,
dvm1.dmPelsWidth,dvm1.dmPelsHeight);
OutputDebugString(Str);
Str.Format(TEXT("Add: %s (%d,%d,%d,%d)\r\n"),AddDevName,dvm2.dmPosition.x,dvm2.dmPosition.y,
dvm2.dmPelsWidth,dvm2.dmPelsHeight);
OutputDebugString(Str); if(ExChange && (iType==DISPLAY_TYPE_EXTEND || iType==DISPLAY_TYPE_SINGLE))//如果需要交换显示,则改变主显示器
{
ChangeDisplaySettingsEx(PriDevName, &dvm2, NULL, CDS_NORESET | CDS_UPDATEREGISTRY , );
ChangeDisplaySettingsEx(AddDevName, &dvm1, NULL, CDS_SET_PRIMARY | CDS_NORESET | CDS_UPDATEREGISTRY, );
}
else
{
ChangeDisplaySettingsEx(PriDevName, &dvm1, NULL, CDS_SET_PRIMARY | CDS_NORESET | CDS_UPDATEREGISTRY, );
ChangeDisplaySettingsEx(AddDevName, &dvm2, NULL, CDS_NORESET | CDS_UPDATEREGISTRY , );
} ChangeDisplaySettingsEx(NULL, NULL, NULL, , );//使有效 return TRUE;
} int CDisplayInfo::AnalyCardType(LPCTSTR cardStr)
{
if(cardStr==NULL)
{
return ;
}
OutputDebugString(cardStr);
TCHAR buf[0x100]={};
_tcscpy_s(buf,0x100,cardStr);
_tcsupr_s(buf,);
if(_tcsstr(buf,TEXT("ATI")))
{
return ;
}
else if(_tcsstr(buf,TEXT("NVIDIA")))
{
return ;
}
else
{
return ;
}
} //功能:获得显卡类型,ATI=1,NVDIA.=2...
int CDisplayInfo::GetDisplayCardType()
{
DISPLAY_DEVICE DispDev;
TCHAR szSaveDeviceName[0x60];
BOOL bRet = TRUE; ZeroMemory(&DispDev, sizeof(DISPLAY_DEVICE));
DispDev.cb = sizeof(DISPLAY_DEVICE); CString Str,outStr;
int i=;
BOOL bRet2=TRUE;
DWORD erro=;
while(bRet)
{
bRet=EnumDisplayDevices(NULL,i,&DispDev,);
if(bRet)
{
memset(szSaveDeviceName,,0x60);
lstrcpy(szSaveDeviceName, DispDev.DeviceName);
bRet2=TRUE;
OutputDebugString(szSaveDeviceName);
OutputDebugString(DispDev.DeviceString);
return AnalyCardType(DispDev.DeviceString);
}
i++;
}
return ;
} //功能:返回系统版本号
//参数:winVer返回版本号.
BOOL CDisplayInfo::GetOSVersion( WinVerDef* winVer )
{
OSVERSIONINFOEX osversionInfo;
ZeroMemory( &osversionInfo, sizeof(osversionInfo) );
osversionInfo.dwOSVersionInfoSize = sizeof(osversionInfo);
*winVer = WIN_VER_UNKNOWN; /*BOOL bOsVersionInfoEx=FALSE;//是否是早期版本,FALSE为早期版本,TRUE为校新版本.
if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osversionInfo)) )
{
osversionInfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);//更早期系统需要从注册表中读取一些版本信息.
if (! GetVersionEx ( (OSVERSIONINFO *) &osversionInfo) )
return FALSE;
}*/ if ( NULL == winVer || FALSE == GetVersionEx((LPOSVERSIONINFO)&osversionInfo) )
{
return FALSE;
}
switch( osversionInfo.dwMajorVersion )
{
case WIN_MAJOR_NT4_ME_98_95:
switch( osversionInfo.dwMinorVersion )
{
case WIN_MINOR_2K8_VISTA_2K_NT4_95:
if ( VER_PLATFORM_WIN32_NT == osversionInfo.dwPlatformId )
{
OutputDebugString(TEXT("WIN_VER_NT4"));
*winVer = WIN_VER_NT4;
}
else
{
OutputDebugString(TEXT("WIN_VER_95"));
*winVer = WIN_VER_95;
}
break;
case WIN_MINOR_98:
OutputDebugString(TEXT("WIN_VER_98"));
*winVer = WIN_VER_98;
break;
case WIN_MINOR_ME:
*winVer = WIN_VER_ME;
OutputDebugString(TEXT("WIN_VER_ME"));
break;
default:
break;
}
break;
case WIN_MAJOR_2K3R2_2K3_XP_2K:
switch( osversionInfo.dwMinorVersion )
{
case WIN_MINOR_2K8_VISTA_2K_NT4_95:
*winVer = WIN_VER_2K;
OutputDebugString(TEXT("WIN_VER_2K"));
break;
case WIN_MINOR_WIN7_2K8R2_XP:
*winVer = WIN_VER_XP;
OutputDebugString(TEXT("WIN_VER_XP"));
break;
case WIN_MINOR_2K3R2_2K3_XP64:
if ( VER_NT_WORKSTATION == osversionInfo.wProductType )
{
*winVer = WIN_VER_XP64;
OutputDebugString(TEXT("WIN_VER_XP64"));
break;
}
if ( != GetSystemMetrics( SM_SERVERR2 ) )
{
*winVer = WIN_VER_2K3R2;
OutputDebugString(TEXT("WIN_VER_2K3_R2"));
}
else
{
*winVer = WIN_VER_2K3;
OutputDebugString(TEXT("WIN_VER_2K3"));
}
break;
default:
break;
}
break;
case WIN_MAJOR_WIN7_2K8R2_2K8_VISTA:
switch( osversionInfo.dwMinorVersion )
{
case WIN_MINOR_2K8_VISTA_2K_NT4_95:
if ( VER_NT_WORKSTATION == osversionInfo.wProductType )
{
OutputDebugString(TEXT("WIN_VER_VISTA"));
*winVer = WIN_VER_VISTA;
}
else
{
*winVer = WIN_VER_2K8;
OutputDebugString(TEXT("WIN_VER_2K8"));
}
break;
case WIN_MINOR_WIN7_2K8R2_XP:
if ( VER_NT_WORKSTATION == osversionInfo.wProductType )
{
*winVer = WIN_VER_WIN7;
OutputDebugString(TEXT("WIN_VER_WIN7"));
}
else
{
*winVer = WIN_VER_2K8R2;
OutputDebugString(TEXT("WIN_VER_2K8_R2"));
}
break;
default:
break;
}
break;
default:
break;
}
return TRUE;
} //功能:判断当前操作系统是否比sepcVer指定的系统更新
BOOL CDisplayInfo::IsOlderSystem( WinVerDef specVer, INT* iResult )
{
if ( NULL == iResult )
{
return FALSE;
}
WinVerDef currVer = WIN_VER_UNKNOWN;
if ( FALSE == GetOSVersion( &currVer ) || WIN_VER_UNKNOWN == currVer )
{
return FALSE;
}
else
{
*iResult = currVer - specVer;
}
return TRUE;
}

原作者的下载包网址:http://download.csdn.net/detail/phmatthaus/9337081

关于win7和xp的屏设置类的更多相关文章

  1. 安装Win7或者XP系统用虚拟光驱加载Win7或者XP镜像 iso文件xp win7wim文件

    安装Win7或者XP系统用虚拟光驱加载Win7或者XP镜像 iso文件xp win7wim文件 http://pcedu.pconline.com.cn/teach/xt/1201/2657834_8 ...

  2. Java win7或 xp下配置JDK环境变量

    JAVA win7或 xp下配置JDK环境变量 by:授客 QQ:1033553122 1.安装JDK,安装过程中可以自定义安装目录等信息,例如我们选择安装目录为D:\java\jdk1.5.0_08 ...

  3. WIN XP蓝屏代码大全

    转自:廊坊师范学院信息技术提高班---韩正阳 http://blog.csdn.net/jiudihanbing WIN XP蓝屏代码大全WIN XP蓝屏代码大全一.蓝屏含义 1.故障检查信息 *** ...

  4. iOS9横竖屏设置的处理方法

    在一般的视频类APP播放的时候都会支持横屏,这样做的好处就是便于观看.你的项目中支持横屏吗?我们一起了解一下,在iOS9中横竖屏设置的处理方法吧! 支持横竖屏配置 在iOS6以后,如果APP需要支持横 ...

  5. XP 右键扩展设置 1.0 免费绿色版

    软件名称: xp右键扩展设置软件 1.0 免费绿色版软件语言: 简体中文授权方式: 免费软件运行环境: Win7 / Vista / Win2003 / WinXP / Win2008软件大小: 57 ...

  6. win7怎么更换锁屏壁纸

    win7怎么更换锁屏壁纸... -------------------------- 按键盘组合键“Windows+R”可打开“运行”窗口,输入 “gpedit.msc” 按回 ----------- ...

  7. ms12-020复现-xp蓝屏

    漏洞名:MS12-020(全称:Microsoft windows远程桌面协议RDP远程代码执行漏洞) 介绍:RDP协议是一个多通道的协议,让用户连上提供微软终端机服务的电脑. windows在处理某 ...

  8. Python小游戏——外星人入侵(保姆级教程)第一章 01创建Pygame窗口 02创建设置类Setting()

    系列文章目录 第一章:武装飞船 01:创建Pygame窗口以及响应用户输入 02:创建设置类Setting() 一.前期准备 1.语言版本 Python3.9.0 2.编译器 Pycharm2022 ...

  9. Android 无标题 全屏设置

    标题栏和状态栏 Android程序默认情况下是包含状态栏和标题栏的. 在Eclipse中新建一个Android程序,运行后显示如下: 图中标出了状态栏(显示时间.电池电量.网络等)和标题栏(显示应用的 ...

随机推荐

  1. paip.获取地理位置根据Ip

    paip.获取地理位置根据Ip html转换txt 正则表达式截取mid 作者Attilax  艾龙, EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http:// ...

  2. Android模拟器配置

    // 检查连接设备,为了保证运行正常,只能留一个连接设备 adb devices

  3. linux中touch命令参数修改文件的时间戳(转)

    linux中touch命令参数不常用,一般在使用make的时候可能会用到,用来修改文件时间戳,或者新建一个不存在的文件,以下是linux中touch命令参数的使用方法: touch [-acm][-r ...

  4. asp.net 操作excel的一系列问题(未完待续)

    最近在处理exel的一些东西,遇到了很多问题,现在就在此将问题和网上找到的解决办法 1.外部表不是预期格式错误 错误经过:在读取Excel时,出现外部表不是预期的格式 错误原因1: 由于Excel 9 ...

  5. wmi详解,RPC和防火墙

    135端口:Microsoft在这个端口运行DCE RPC end-point mapper为它的DCOM服务.这与UNIX 111端口的功能很相似.使用DCOM和RPC的服务利用计算机上的end-p ...

  6. Fiddler高级技巧 - 映射路径到本地文件夹

    适用场景: 你是前端开发人员,要开发一个小模块,需要用到线上的环境(账号.数据.跨域等),但你又没有权限往线上传文件 你是移动测试人员,需要将一组接口的返回结果替换为另一组,最简单的办法就是使用Fid ...

  7. 十大免费教程资源帮助新手快速学习JavaScript

    “JavaScript”的名头相信大家肯定是耳熟能详,但只有一小部分人群了解它的使用与应用程序构建方式.这“一小部分”人指的当然是技术过硬的有为青年.网络程序员以及IT专业人员.但对于一位新手或者说外 ...

  8. 九宫格抽奖HTML+JS版

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  9. JS图片切换效果

    源地址:http://www.codefans.net/jscss/code/4699.shtml <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1 ...

  10. Android开发(二十五)——Android上传文件至七牛

    设置头像: Drawable drawable = new BitmapDrawable(dBitmap); //Drawable drawable = Drawable.createFromPath ...