WM下代码实现转屏
在WM下用户可以经常转屏,但是这个也能通过代码实现,下面是一个经过测试的代码。
int ChangeDisplaySettings( )
{
DEVMODE DevMode;
int RotationAngles = 0;
int CurrentAngle = 0;
int NewAngle = 0;
//Check for rotation support by getting the rotation angles supported.
memset( &DevMode, 0, sizeof( DevMode ) );
DevMode.dmSize = sizeof( DevMode );
DevMode.dmFields = DM_DISPLAYQUERYORIENTATION;
if( DISP_CHANGE_SUCCESSFUL == ChangeDisplaySettingsEx( NULL, &DevMode, NULL, CDS_TEST, NULL ) )
{
RotationAngles = DevMode.dmDisplayOrientation;
}
else
{
RotationAngles = -1;
}
//Get the current rotation angle.
memset( &DevMode, 0, sizeof( DevMode ) );
DevMode.dmSize = sizeof( DevMode );
DevMode.dmFields = DM_DISPLAYORIENTATION;
if( DISP_CHANGE_SUCCESSFUL == ChangeDisplaySettingsEx( NULL, &DevMode, NULL, CDS_TEST, NULL ) )
{
CurrentAngle = DevMode.dmDisplayOrientation;
}
else
{
CurrentAngle = -1;
}
//Rotate to the "next " angle.
if ( ( CurrentAngle >= 0 ) && ( RotationAngles >= 0 ) )
{
NewAngle = CurrentAngle;
do
{
NewAngle <<= 1;
if( DMDO_0 == NewAngle )
{
NewAngle = DMDO_270;
}
if( NewAngle > DMDO_270 )
{
NewAngle = DMDO_0;
}
} while ( !( NewAngle & RotationAngles) && ( NewAngle != DMDO_0 ) );
memset( &DevMode, 0, sizeof( DevMode ) );
DevMode.dmSize = sizeof( DevMode );
DevMode.dmFields = DM_DISPLAYORIENTATION;
DevMode.dmDisplayOrientation = NewAngle;
if( DISP_CHANGE_SUCCESSFUL == ChangeDisplaySettingsEx( NULL, &DevMode, NULL, CDS_RESET, NULL ) )
{
}
else
{
}
}
return 0;
}