#define SM_CMONITORS 80
// int screen_count = ::GetSystemMetrics( SM_CMONITORS );
BOOL EnumDisplayDevices(
LPCTSTR lpDevice, // device name
DWORD iDevNum, // display device
PDISPLAY_DEVICE lpDisplayDevice, // device information
DWORD dwFlags // reserved
);
typedef BOOL ( __stdcall * pEnumDiaplayDevices )( LPCTSTR lpDevice, // device name
DWORD iDevNum, // display device
PDISPLAY_DEVICE lpDisplayDevice, // device information
DWORD dwFlags // reserved
);
int
GetScreenRect( int ScreenNo, RECT *rect )
{
pEnumDiaplayDevices xenum;
BOOL flag;
DISPLAY_DEVICE dd;
ZeroMemory( &dd, sizeof( dd ) );
dd.cb = sizeof( dd );
HMODULE hhh = LoadLibrary( _T( "user32.dll" ) );
if( hhh )
{
xenum = ( pEnumDiaplayDevices )GetProcAddress( hhh, "EnumDisplayDevicesW" );
}
if( !xenum )
{
FreeLibrary( hhh );
return 1;
}
//flag = EnumDisplayDevices( NULL, ScreenNo, &dd, 0 );
flag = xenum( NULL, ScreenNo, &dd, 0 );
if( !flag )
{
FreeLibrary( hhh );
return 1;
}
DEVMODE dm;
ZeroMemory( &dm, sizeof( dm ) );
dm.dmSize = sizeof( dm );
flag = EnumDisplaySettings( dd.DeviceName, ENUM_CURRENT_SETTINGS, &dm );
rect->left = dm.dmPosition.x;
rect->top = dm.dmPosition.y;
rect->right = dm.dmPelsWidth;
rect->bottom = dm.dmPelsHeight;
FreeLibrary( hhh );
return 0;
}
//*************************
// 简单测试代码
//*************************
RECT rec;
int result = GetScreenRect( 1, &rec );
if( rec.left == rec.right )
{
// 没找到第二显示器,随便判断一下,不严格