01. #include "stdafx.h"
02.#include <windows.h>
03.#include <stdio.h>
04.#include <tchar.h>
05.#include <conio.h>
06.
07. void CheckDisplay();
08.int main(int argc, char *argv[])
09.{
10. CheckDisplay();
11. _getch();
12. return 0;
13.}
14.void CheckDisplay()
15.{
16. BOOL FoundSecondaryDisp = FALSE;
17. DWORD DispNum = 0;
18. DISPLAY_DEVICE DisplayDevice;
19. LONG Result;
20. int i = 0;
21. DEVMODE defaultMode;
22. // initialize DisplayDevice
23. ZeroMemory(&DisplayDevice, sizeof(DisplayDevice));
24. DisplayDevice.cb = sizeof(DisplayDevice);
25. // get all display devices
26. while (EnumDisplayDevices(NULL, DispNum, &DisplayDevice, 0))
27. {
28. ZeroMemory(&defaultMode, sizeof(DEVMODE));
29. defaultMode.dmSize = sizeof(DEVMODE);
30. if ( !EnumDisplaySettings((LPCWSTR)DisplayDevice.DeviceName, ENUM_REGISTRY_SETTINGS, &defaultMode) )
31. OutputDebugString((LPCWSTR)"Store default failed/n");
32. if ((DisplayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) &&
33. !(DisplayDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE))
34. {
35. DEVMODE DevMode;
36. ZeroMemory(&DevMode, sizeof(DevMode));
37. DevMode.dmSize = sizeof(DevMode);
38. DevMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_POSITION
39. | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS ;
40. Result = ChangeDisplaySettingsEx((LPCWSTR)DisplayDevice.DeviceName, &DevMode, NULL, CDS_UPDATEREGISTRY, NULL);
41. Result = ChangeDisplaySettingsEx((LPCWSTR)DisplayDevice.DeviceName, &DevMode, NULL, CDS_UPDATEREGISTRY, NULL);
42. //The code below shows how to re-attach the secondary displays to the desktop
43. ChangeDisplaySettingsEx((LPCWSTR)DisplayDevice.DeviceName, &defaultMode, NULL, CDS_UPDATEREGISTRY, NULL);
44. ChangeDisplaySettingsEx((LPCWSTR)DisplayDevice.DeviceName, &defaultMode, NULL, CDS_UPDATEREGISTRY, NULL);
45. }
46. // Reinit DisplayDevice just to be extra clean
47. ZeroMemory(&DisplayDevice, sizeof(DisplayDevice));
48. DisplayDevice.cb = sizeof(DisplayDevice);
49. DispNum++;
50. } // end while for all display devices
51. printf("Display Device Number is %d/n",DispNum);
52.};
02.#include <windows.h>
03.#include <stdio.h>
04.#include <tchar.h>
05.#include <conio.h>
06.
07. void CheckDisplay();
08.int main(int argc, char *argv[])
09.{
10. CheckDisplay();
11. _getch();
12. return 0;
13.}
14.void CheckDisplay()
15.{
16. BOOL FoundSecondaryDisp = FALSE;
17. DWORD DispNum = 0;
18. DISPLAY_DEVICE DisplayDevice;
19. LONG Result;
20. int i = 0;
21. DEVMODE defaultMode;
22. // initialize DisplayDevice
23. ZeroMemory(&DisplayDevice, sizeof(DisplayDevice));
24. DisplayDevice.cb = sizeof(DisplayDevice);
25. // get all display devices
26. while (EnumDisplayDevices(NULL, DispNum, &DisplayDevice, 0))
27. {
28. ZeroMemory(&defaultMode, sizeof(DEVMODE));
29. defaultMode.dmSize = sizeof(DEVMODE);
30. if ( !EnumDisplaySettings((LPCWSTR)DisplayDevice.DeviceName, ENUM_REGISTRY_SETTINGS, &defaultMode) )
31. OutputDebugString((LPCWSTR)"Store default failed/n");
32. if ((DisplayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) &&
33. !(DisplayDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE))
34. {
35. DEVMODE DevMode;
36. ZeroMemory(&DevMode, sizeof(DevMode));
37. DevMode.dmSize = sizeof(DevMode);
38. DevMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_POSITION
39. | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS ;
40. Result = ChangeDisplaySettingsEx((LPCWSTR)DisplayDevice.DeviceName, &DevMode, NULL, CDS_UPDATEREGISTRY, NULL);
41. Result = ChangeDisplaySettingsEx((LPCWSTR)DisplayDevice.DeviceName, &DevMode, NULL, CDS_UPDATEREGISTRY, NULL);
42. //The code below shows how to re-attach the secondary displays to the desktop
43. ChangeDisplaySettingsEx((LPCWSTR)DisplayDevice.DeviceName, &defaultMode, NULL, CDS_UPDATEREGISTRY, NULL);
44. ChangeDisplaySettingsEx((LPCWSTR)DisplayDevice.DeviceName, &defaultMode, NULL, CDS_UPDATEREGISTRY, NULL);
45. }
46. // Reinit DisplayDevice just to be extra clean
47. ZeroMemory(&DisplayDevice, sizeof(DisplayDevice));
48. DisplayDevice.cb = sizeof(DisplayDevice);
49. DispNum++;
50. } // end while for all display devices
51. printf("Display Device Number is %d/n",DispNum);
52.};