I can't seem to get some C++ code to compile. I am flip the orientation of the display, but VS2008 is telling me the DMDO_90 and DMDO_270 are unidentified:
error C2065: 'DMDO_90' : undeclared identifier
error C2065: 'DMDO_270' : undeclared identifier
Am I missing something-- an include or something?
According to the MSDN DEVMODE structure DMDO should be defined (under the dmDisplayOrientation section)--
Here is the code I have:
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
DISPLAY_DEVICE GetPrimaryDevice()
{
int index=0;
DISPLAY_DEVICE dd;
dd.cb = sizeof(DISPLAY_DEVICE);
while (EnumDisplayDevices(NULL, index++, &dd, 0))
{
if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) return dd;
}
return dd;
}
BOOL SetDisplayResolution(long degrees)
{
DISPLAY_DEVICE dd = GetPrimaryDevice();
DEVMODE dm;
ZeroMemory(&dm, sizeof(dm));
dm.dmSize = sizeof(DEVMODE);
if (!EnumDisplaySettings(dd.DeviceName, ENUM_CURRENT_SETTINGS, &dm))
{
printf("EnumDisplaySettings failed:%d\n", GetLastError());
return FALSE;
}
switch(degrees)
{
case 90:
dm.dmDisplayOrientation = DMDO_90; //error C2065: 'DMDO_90' : undeclared identifier
break;
case 270:
dm.dmDisplayOrientation = DMDO_270; //error C2065: 'DMDO_90' : undeclared identifier
break;
default:
break;
}
DWORD dwTemp = dm.dmPelsHeight;
dm.dmPelsHeight = dm.dmPelsWidth;
dm.dmPelsWidth = dwTemp;
dm.dmFields = (DM_PELSWIDTH | DM_PELSHEIGHT);
if (ChangeDisplaySettings(&dm, CDS_TEST) !=DISP_CHANGE_SUCCESSFUL)
{
printf("\nIllegal graphics mode: %d\n", GetLastError());
return FALSE;
}
return (ChangeDisplaySettings(&dm, 0)==DISP_CHANGE_SUCCESSFUL);
}
int main()
{
if (SetDisplayResolution(90))
{
return true;
}
else
{
return false;
}
}
I am using VS 2008, and this constant is defined in wingdi.h
(please use the Intellisense or a good code tagger such as Visual Assist to show you where these constants are defined).
The relevant part of the wingdi.h
header is this:
#if(WINVER >= 0x0501)
/* DEVMODE dmDisplayOrientation specifiations */
#define DMDO_DEFAULT 0
#define DMDO_90 1
#define DMDO_180 2
#define DMDO_270 3
Note that WINVER
has to be >= 0x0501, therefore more than likely you need to set the WINVER
preprocessor symbol correctly.
Please see this link to modify WINVER: http://msdn.microsoft.com/en-us/library/6sehtctf.aspx