int get_screen_info(int id, _TCHAR* name, int* width, int* height, int* bpp) { DISPLAY_DEVICE dd; memset(&dd, 0, sizeof(DISPLAY_DEVICE)); dd.cb = sizeof(DISPLAY_DEVICE); if (EnumDisplayDevices(NULL, id, &dd, 0) != 0) { HDC dc; if (name != NULL) _stprintf(name, _T("%s (%s)"), dd.DeviceName, dd.DeviceString); dc = CreateDC(dd.DeviceName, NULL, NULL, NULL); *width = GetDeviceCaps(dc, HORZRES); *height = GetDeviceCaps(dc, VERTRES); *bpp = GetDeviceCaps(dc, BITSPIXEL); //ReleaseDC(NULL, dc); DeleteDC(dc); } else { return 0; } return 1; }
int _tmain(int argc, _TCHAR* argv[]) { int deviceIndex=0; int result; DWORD bpp=16; do { PDISPLAY_DEVICE displayDevice = new DISPLAY_DEVICE(); displayDevice->cb = sizeof(DISPLAY_DEVICE); result = EnumDisplayDevices(NULL, deviceIndex++, displayDevice, 0); if (displayDevice->StateFlags & DISPLAY_DEVICE_ACTIVE) { PDISPLAY_DEVICE monitor = new DISPLAY_DEVICE(); monitor->cb = sizeof(DISPLAY_DEVICE); EnumDisplayDevices(displayDevice->DeviceName, 0, monitor, 0); PDEVMODE dm = new DEVMODE(); if ( EnumDisplaySettings(displayDevice->DeviceName, ENUM_CURRENT_SETTINGS, dm) ) { dm->dmBitsPerPel=(DWORD)bpp; ChangeDisplaySettingsEx(displayDevice->DeviceName, dm, \ NULL, (CDS_GLOBAL | CDS_UPDATEREGISTRY | CDS_RESET), NULL); } } } while (result); return 0; }
/* ======================== GetDisplayCoordinates ======================== */ static bool GetDisplayCoordinates( const int deviceNum, int & x, int & y, int & width, int & height, int & displayHz ) { idStr deviceName = GetDeviceName( deviceNum ); if ( deviceName.Length() == 0 ) { return false; } DISPLAY_DEVICE device = {}; device.cb = sizeof( device ); if ( !EnumDisplayDevices( 0, // lpDevice deviceNum, &device, 0 /* dwFlags */ ) ) { return false; } DISPLAY_DEVICE monitor; monitor.cb = sizeof( monitor ); if ( !EnumDisplayDevices( deviceName.c_str(), 0, &monitor, 0 /* dwFlags */ ) ) { return false; } DEVMODE devmode; devmode.dmSize = sizeof( devmode ); if ( !EnumDisplaySettings( deviceName.c_str(),ENUM_CURRENT_SETTINGS, &devmode ) ) { return false; } common->Printf( "display device: %i\n", deviceNum ); common->Printf( " DeviceName : %s\n", device.DeviceName ); common->Printf( " DeviceString: %s\n", device.DeviceString ); common->Printf( " StateFlags : 0x%x\n", device.StateFlags ); common->Printf( " DeviceID : %s\n", device.DeviceID ); common->Printf( " DeviceKey : %s\n", device.DeviceKey ); common->Printf( " DeviceName : %s\n", monitor.DeviceName ); common->Printf( " DeviceString: %s\n", monitor.DeviceString ); common->Printf( " StateFlags : 0x%x\n", monitor.StateFlags ); common->Printf( " DeviceID : %s\n", monitor.DeviceID ); common->Printf( " DeviceKey : %s\n", monitor.DeviceKey ); common->Printf( " dmPosition.x : %i\n", devmode.dmPosition.x ); common->Printf( " dmPosition.y : %i\n", devmode.dmPosition.y ); common->Printf( " dmBitsPerPel : %i\n", devmode.dmBitsPerPel ); common->Printf( " dmPelsWidth : %i\n", devmode.dmPelsWidth ); common->Printf( " dmPelsHeight : %i\n", devmode.dmPelsHeight ); common->Printf( " dmDisplayFlags : 0x%x\n", devmode.dmDisplayFlags ); common->Printf( " dmDisplayFrequency: %i\n", devmode.dmDisplayFrequency ); x = devmode.dmPosition.x; y = devmode.dmPosition.y; width = devmode.dmPelsWidth; height = devmode.dmPelsHeight; displayHz = devmode.dmDisplayFrequency; return true; }
bool GetWindowsMonitorSize( int *width, int *height) { int WidthMm = 0; int HeightMm = 0; DISPLAY_DEVICE dd; dd.cb = sizeof(dd); DWORD dev = 0; // device index int id = 1; // monitor number, as used by Display Properties > Settings wxString DeviceID; bool bFoundDevice = false; while (EnumDisplayDevices(0, dev, &dd, 0) && !bFoundDevice) { DISPLAY_DEVICE ddMon; ZeroMemory(&ddMon, sizeof(ddMon)); ddMon.cb = sizeof(ddMon); DWORD devMon = 0; while (EnumDisplayDevices(dd.DeviceName, devMon, &ddMon, 0) && !bFoundDevice) { if (ddMon.StateFlags & DISPLAY_DEVICE_ACTIVE && !(ddMon.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER)) { DeviceID = wxString(ddMon.DeviceID, wxConvUTF8); DeviceID = DeviceID.Mid (8); DeviceID = DeviceID.Mid (0, DeviceID.Find ( '\\' )); bFoundDevice = GetSizeForDevID(DeviceID, &WidthMm, &HeightMm); } devMon++; ZeroMemory(&ddMon, sizeof(ddMon)); ddMon.cb = sizeof(ddMon); } ZeroMemory(&dd, sizeof(dd)); dd.cb = sizeof(dd); dev++; } if(width) *width = WidthMm; if(height) *height = HeightMm; return bFoundDevice; }
BOOL CMonitorManager::GetMonitorResolution(HWND hWnd, long *lResoluteW, long *lResoluteH) { HMONITOR hm = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); BOOL bFindMonitor = FALSE; for(int i = 0; i < m_MonitorList.size(); i++) { if (hm == m_MonitorList[i].hMonitor) { bFindMonitor = TRUE; break; } } if (!bFindMonitor) return FALSE; DISPLAY_DEVICE dd; ZeroMemory(&dd, sizeof(DISPLAY_DEVICE)); dd.cb = sizeof(DISPLAY_DEVICE); bFindMonitor = EnumDisplayDevices(NULL, i, &dd, 0); if (!bFindMonitor) return FALSE; DEVMODE dm; ZeroMemory(&dm, sizeof(DEVMODE)); dm.dmSize = sizeof(dm); bFindMonitor = EnumDisplaySettings((char*)dd.DeviceName, ENUM_CURRENT_SETTINGS, &dm); if (!bFindMonitor) return FALSE; *lResoluteW = dm.dmPelsWidth; *lResoluteH = dm.dmPelsHeight; return TRUE; }
//-------------------------------------------------------------------------- VE_BOOL VeWindows::AddDisplay(LPSTR DeviceName) { VeDevice::VideoDisplay kDisplay; DisplayData* pkDisplayData; VeDevice::DisplayMode kMode; DISPLAY_DEVICE kDevice; if(!GetDisplayMode(DeviceName, ENUM_CURRENT_SETTINGS, &kMode)) { return VE_FALSE; } pkDisplayData = VE_NEW DisplayData; if(!pkDisplayData) { return VE_FALSE; } VeStrcpy(pkDisplayData->m_acDeviceName, DeviceName); kDevice.cb = sizeof(kDevice); if (EnumDisplayDevices(DeviceName, 0, &kDevice, 0)) { kDisplay.m_kName = kDevice.DeviceString; } kDisplay.m_kDesktopMode = kMode; kDisplay.m_kCurrentMode = kMode; kDisplay.m_spDriverData = pkDisplayData; m_kDisplays.PushBack(kDisplay); return VE_TRUE; }
static BOOL Rotate( int iDevNum, SHORT dmOrientation ) { DISPLAY_DEVICE d; DEVMODE dm; int w; LONG r; ZeroMemory( &d, sizeof( d ) ); d.cb = sizeof( d ); if( !EnumDisplayDevices( NULL, iDevNum, &d, 0 ) ) { DebugMsg( _T("EnumDisplayDevices failed:%d\r\n" ), GetLastError() ); return FALSE; } if( !EnumDisplaySettings( d.DeviceName, ENUM_CURRENT_SETTINGS, &dm ) ){ DebugMsg( _T("EnumDisplaySettings(\"%s\") failed:%d\r\n" ), d.DeviceName, GetLastError() ); return FALSE; } if( dm.dmDisplayOrientation == dmOrientation ) return TRUE; w = dm.dmPelsHeight; dm.dmPelsHeight = dm.dmPelsWidth; dm.dmPelsWidth = w; dm.dmDisplayOrientation = dmOrientation; r = ChangeDisplaySettingsEx( d.DeviceName, &dm, NULL, CDS_UPDATEREGISTRY, NULL ); if( r != DISP_CHANGE_SUCCESSFUL ){ DebugMsg( _T("ChangeDisplaySettingsEx failed:%d\r\n"), r ); return FALSE; } return TRUE; }
bool output_device_enumerator_win32::enumerate_device(gl::output_device_descriptor& desc, const std::string& name) { _issues.push_back(std::string("output_device_enumerator_win32::enumerate_device(): {")); DISPLAY_DEVICE disp_device; disp_device.cb = sizeof(DISPLAY_DEVICE); unsigned dev_index = 0; bool found_dev = false; while (!found_dev && EnumDisplayDevices(NULL, dev_index, &disp_device, 0)) { if (name == std::string(disp_device.DeviceName)) { found_dev = true; } else { dev_index++; } } if (found_dev) { return (this->enumerate_device(desc, dev_index)); } else { _issues.push_back(std::string("\tError: unable to find device: ") + name); return (false); } }
int win_shadow_enum_monitors(MONITOR_DEF* monitors, int maxMonitors) { HDC hdc; int index; int desktopWidth; int desktopHeight; DWORD iDevNum = 0; int numMonitors = 0; MONITOR_DEF* monitor; DISPLAY_DEVICE displayDevice; ZeroMemory(&displayDevice, sizeof(DISPLAY_DEVICE)); displayDevice.cb = sizeof(DISPLAY_DEVICE); if (EnumDisplayDevices(NULL, iDevNum, &displayDevice, 0)) { hdc = CreateDC(displayDevice.DeviceName, NULL, NULL, NULL); desktopWidth = GetDeviceCaps(hdc, HORZRES); desktopHeight = GetDeviceCaps(hdc, VERTRES); index = 0; numMonitors = 1; monitor = &monitors[index]; monitor->left = 0; monitor->top = 0; monitor->right = desktopWidth; monitor->bottom = desktopHeight; monitor->flags = 1; DeleteDC(hdc); } return numMonitors; }
HRESULT CSystemInfo::GetDisplayInfo(CString& strDisplay) { DISPLAY_DEVICE displayInfo; DWORD dwIndex = 0; displayInfo.cb = sizeof(DISPLAY_DEVICE); displayInfo.StateFlags = 0; while (EnumDisplayDevices(NULL, dwIndex, &displayInfo, NULL)) { dwIndex++; if (0 == _tcslen(displayInfo.DeviceID)) { continue; } if (strDisplay.GetLength() > 0) { strDisplay.Append("&"); } strDisplay.Append(displayInfo.DeviceString); } return S_OK; }
BOOL CMirageManager::LookupDisplayDevices(DISPLAY_DEVICE& deviceInfo, DWORD& deviceNumber, bool bShouldLog) { memset(&deviceInfo, 0, sizeof(deviceInfo)); deviceInfo.cb = sizeof(deviceInfo); deviceNumber = 0; BOOL result = FALSE; std::wstring dataStream(_T("")); while (result = EnumDisplayDevices(NULL, deviceNumber, &deviceInfo, 0)) { if (bShouldLog) { dataStream.append(_T("Detected Device :: ")); dataStream.append(deviceInfo.DeviceName); dataStream.append(_T(" - ")); dataStream.append(deviceInfo.DeviceString); CMirageManager::WriteDiagnostics(dataStream); dataStream.clear(); } if (wcscmp(deviceInfo.DeviceString, DRIVER_NAME) == 0) { result = TRUE; break; } ++deviceNumber; } return result; }
void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) { HDC dc; WORD values[768]; DISPLAY_DEVICE display; if (ramp->size != 256) { _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Gamma ramp size must be 256"); return; } memcpy(values + 0, ramp->red, 256 * sizeof(unsigned short)); memcpy(values + 256, ramp->green, 256 * sizeof(unsigned short)); memcpy(values + 512, ramp->blue, 256 * sizeof(unsigned short)); ZeroMemory(&display, sizeof(DISPLAY_DEVICE)); display.cb = sizeof(DISPLAY_DEVICE); EnumDisplayDevices(monitor->win32.name, 0, &display, 0); dc = CreateDC(L"DISPLAY", display.DeviceString, NULL, NULL); SetDeviceGammaRamp(dc, values); DeleteDC(dc); }
//************************************ // 函数名称: GetMonitorDisplayDevice // 返回类型: DISPLAY_DEVICE& // 参数信息: DWORD _MonitorIndex // 函数说明: //************************************ DISPLAY_DEVICE& DuiMonitor::GetMonitorDisplayDevice( DWORD _MonitorIndex /*= 1*/ ) { static DISPLAY_DEVICE mDisplayDevice; memset(&mDisplayDevice,0, sizeof(mDisplayDevice)); if(_MonitorIndex <= 0 || _MonitorIndex > GetMonitorCount()) return mDisplayDevice; DEVMODE mDevMode; memset(&mDevMode,0, sizeof(mDevMode)); DWORD mCheckCount = 0,mMonitorCount = 0; while(mMonitorCount != _MonitorIndex) { mDisplayDevice.cb = sizeof(DISPLAY_DEVICE); if(EnumDisplayDevices(NULL, mCheckCount, &mDisplayDevice,0) == FALSE) break; if(EnumDisplaySettings(mDisplayDevice.DeviceName,ENUM_CURRENT_SETTINGS,&mDevMode)) mMonitorCount++; mCheckCount++; } return mDisplayDevice; }
BOOL DetectVirtualMonitor(BOOL log) { INT devNum = 0; DISPLAY_DEVICE displayDevice; BOOL result; BOOL bFound = FALSE; FillMemory(&displayDevice, sizeof(DISPLAY_DEVICE), 0); displayDevice.cb = sizeof(DISPLAY_DEVICE); // First enumerate for Primary display device: while ((result = EnumDisplayDevices(NULL, devNum, &displayDevice, 0))) { if (log) { logInfo("%s, %s %s \n", &displayDevice.DeviceString[0], &displayDevice.DeviceName[0], &displayDevice.DeviceID[0]/*, &displayDevice.DeviceKey[0]*/); } if (strcmp(&displayDevice.DeviceID[0], DRIVER_NAME) == 0) { bFound = TRUE; if (!log) break; } devNum++; } return bFound; }
static SDL_bool WIN_AddDisplay(_THIS, LPTSTR DeviceName) { SDL_VideoDisplay display; SDL_DisplayData *displaydata; SDL_DisplayMode mode; DISPLAY_DEVICE device; #ifdef DEBUG_MODES printf("Display: %s\n", WIN_StringToUTF8(DeviceName)); #endif if (!WIN_GetDisplayMode(_this, DeviceName, ENUM_CURRENT_SETTINGS, &mode)) { return SDL_FALSE; } displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata)); if (!displaydata) { return SDL_FALSE; } SDL_memcpy(displaydata->DeviceName, DeviceName, sizeof(displaydata->DeviceName)); SDL_zero(display); device.cb = sizeof(device); if (EnumDisplayDevices(DeviceName, 0, &device, 0)) { display.name = WIN_StringToUTF8(device.DeviceString); } display.desktop_mode = mode; display.current_mode = mode; display.driverdata = displaydata; SDL_AddVideoDisplay(&display); SDL_free(display.name); return SDL_TRUE; }
// set fullscreen (for opengl) int scrnSetFull(const bool& full) { if (full) { DISPLAY_DEVICE dev; memset(&dev, 0, sizeof(dev)); dev.cb = sizeof(dev); EnumDisplayDevices(NULL, nVidAdapter, &dev, 0); DEVMODE mode; memset(&mode, 0, sizeof(mode)); mode.dmSize = sizeof(mode); mode.dmBitsPerPel = nVidScrnDepth; mode.dmPelsWidth = nVidScrnWidth; mode.dmPelsHeight = nVidScrnHeight; mode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; LONG ret = ChangeDisplaySettingsEx(dev.DeviceName, &mode, NULL, CDS_FULLSCREEN, NULL); if (ret != DISP_CHANGE_SUCCESSFUL) { return 1; } SetWindowPos(hScrnWnd, NULL, 0, 0, nVidScrnWidth, nVidScrnHeight, SWP_NOZORDER | SWP_NOACTIVATE); // MoveWindow(hScrnWnd, 0, 0, nVidScrnWidth, nVidScrnHeight, FALSE); ShowWindow(hScrnWnd, SW_NORMAL); bFakeFullscreen = false; } else { ChangeDisplaySettingsEx(NULL, NULL, NULL, 0, NULL); } return 0; }
//************************************ // 函数名称: GetMonitorCount // 返回类型: DWORD // 参数信息: bool _bReCheck // 函数说明: //************************************ DWORD DuiMonitor::GetMonitorCount(bool _bReCheck/* = false*/) { static DWORD mMonitorCount = 0; if(mMonitorCount && !_bReCheck) return mMonitorCount; DEVMODE mDevMode; memset(&mDevMode,0, sizeof(mDevMode)); DISPLAY_DEVICE mDisplayDevice; DWORD mCheckCount = 0; while(true) { memset(&mDisplayDevice,0, sizeof(mDisplayDevice)); mDisplayDevice.cb = sizeof(DISPLAY_DEVICE); if(EnumDisplayDevices(NULL, mCheckCount, &mDisplayDevice,0) == FALSE) break; if(EnumDisplaySettings(mDisplayDevice.DeviceName,ENUM_CURRENT_SETTINGS,&mDevMode)) mMonitorCount++; mCheckCount++; } return mMonitorCount; }
HDC Pipe::createWGLDisplayDC() { uint32_t device = getPipe()->getDevice(); if( device == EQ_UNDEFINED_UINT32 ) device = 0; DISPLAY_DEVICE devInfo; devInfo.cb = sizeof( devInfo ); if( !EnumDisplayDevices( 0, device, &devInfo, 0 )) { setError( ERROR_WGLPIPE_ENUMDISPLAYS_FAILED ); EQWARN << getError() << ": " << co::base::sysError << std::endl; return 0; } const HDC displayDC = CreateDC( "DISPLAY", devInfo.DeviceName, 0, 0 ); if( !displayDC ) { setError( ERROR_WGLPIPE_CREATEDC_FAILED ); EQWARN << getError() << ": " << co::base::sysError << std::endl; return 0; } return displayDC; }
void COpenGL::EnumModes(std::vector<dMode> *modeVector) { DISPLAY_DEVICE dd; dd.cb = sizeof(dd); DWORD dev = 0; int iMode = 0; dMode mode; while (EnumDisplayDevices(0, dev, &dd, 0)) { if (!(dd.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) && (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)) { DEVMODE dm; memset(&dm, 0, sizeof(dm)); dm.dmSize = sizeof(dm); iMode = 0; while(EnumDisplaySettings(dd.DeviceName,iMode,&dm)) { if(dm.dmBitsPerPel>=16) { mode.width = dm.dmPelsWidth; mode.height = dm.dmPelsHeight; mode.rate = dm.dmDisplayFrequency; mode.depth = dm.dmBitsPerPel; modeVector->push_back(mode); } iMode++; } } dev++; } }
nsresult nsSystemInfo::Init() { DISPLAY_DEVICE lpDisplayDevice; lpDisplayDevice.cb = sizeof(lpDisplayDevice); int deviceIndex = 0; while (EnumDisplayDevices(NULL, deviceIndex, &lpDisplayDevice, 0)) { if (lpDisplayDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) break; deviceIndex++; } mDeviceKey = lpDisplayDevice.DeviceKey; mDeviceID = lpDisplayDevice.DeviceID; mDeviceString.AssignLiteral(lpDisplayDevice.DeviceString); DEVMODE dm; dm.dmSize = sizeof(dm); EnumDisplaySettings(lpDisplayDevice.DeviceName, ENUM_CURRENT_SETTINGS, &dm); mBitsPerPixel = dm.dmBitsPerPel; mPixelWidth = dm.dmPelsWidth; mPixelHeight = dm.dmPelsHeight; getDriverDetails(mDeviceID, mDriverVersion, mDriverDate); return NS_OK; }
static bool win_get_monitor_info(int adapter, ALLEGRO_MONITOR_INFO *info) { DISPLAY_DEVICE dd; DEVMODE dm; memset(&dd, 0, sizeof(dd)); dd.cb = sizeof(dd); if (!EnumDisplayDevices(NULL, adapter, &dd, 0)) { return false; } memset(&dm, 0, sizeof(dm)); dm.dmSize = sizeof(dm); if (!EnumDisplaySettings(dd.DeviceName, ENUM_CURRENT_SETTINGS, &dm)) { return false; } ASSERT(dm.dmFields & DM_PELSHEIGHT); ASSERT(dm.dmFields & DM_PELSWIDTH); /* Disabled this assertion for now as it fails under Wine 1.2. */ /* ASSERT(dm.dmFields & DM_POSITION); */ info->x1 = dm.dmPosition.x; info->y1 = dm.dmPosition.y; info->x2 = info->x1 + dm.dmPelsWidth; info->y2 = info->y1 + dm.dmPelsHeight; return true; }
static int dispApapterInit() { if (!hVideoDlg) { return 1; } unsigned int count = 0; int ret = 0; DISPLAY_DEVICE dev; memset(&dev, 0, sizeof(dev)); dev.cb = sizeof(dev); do { ret = EnumDisplayDevices(NULL, count, &dev, 0); if (ret) { if (dev.StateFlags & DISPLAY_DEVICE_ACTIVE) { SendDlgItemMessage(hVideoDlg, IDC_PREF_DISPADAPTER, CB_ADDSTRING, 0, (LPARAM)dev.DeviceName); } count++; } } while (ret); SendDlgItemMessage(hVideoDlg, IDC_PREF_DISPADAPTER, CB_SETCURSEL, (WPARAM)nVidAdapter, 0); return 0; }
__declspec(dllexport) void GetNumberofDisplays(UINT *NumDisplays) { *NumDisplays = 0; BOOL retval; DEVMODE StoredDevMode; DISPLAY_DEVICE TempDisplayDeviceStruct; LPCWSTR AdapterName; DWORD count = 0; DWORD modecount = 0; TempDisplayDeviceStruct.cb = sizeof(DISPLAY_DEVICE); retval = EnumDisplayDevices(NULL, count, &TempDisplayDeviceStruct, EDD_GET_DEVICE_INTERFACE_NAME); while (retval) { if (TempDisplayDeviceStruct.StateFlags != DISPLAY_DEVICE_MIRRORING_DRIVER) { // A mirroring driver is just a pseudo display device that is used internally want to ignore them // The current display device is at least known to the system. However, if you pull the plug on a // device, it will still have a DisplayDeviceStruct. But it seems that it has no modes // associated with it when it cannot be accessed. So, before we know that the device is really available // make sure that there are some modes that are available. modecount = 0; AdapterName = (WCHAR *)&TempDisplayDeviceStruct.DeviceName; StoredDevMode.dmSize = sizeof(DEVMODE); StoredDevMode.dmDriverExtra = 0; retval = EnumDisplaySettings(AdapterName, modecount, (DEVMODE *)&StoredDevMode); // see if there are at least a couple of modes for this display device while (retval && modecount <= 2) { modecount++; retval = EnumDisplaySettings(AdapterName, modecount, (DEVMODE *)&StoredDevMode); } // If we exited the above loop and were still getting good data, then we have found // a viable display device if (retval) (*NumDisplays)++; } // Get the next display device count++; TempDisplayDeviceStruct.cb = sizeof(DISPLAY_DEVICE); retval = EnumDisplayDevices(NULL, count, &TempDisplayDeviceStruct, 0); } return; }
///////////////////////////////////////////////////////////////////////////// //! Tests if graphics interop is supported on the current system //! @return CUTTrue if graphics interop is supported ////////////////////////////////////////////////////////////////////////////// CUTBoolean CUTIL_API isInteropSupported() { #ifdef _WIN32 int num_devices = 0; int dev = 0; do { DISPLAY_DEVICE dispDevice; memset(&dispDevice, 0, sizeof(dispDevice)); dispDevice.cb = sizeof(dispDevice); if (!EnumDisplayDevices(NULL, dev, &dispDevice, 0)) break; if ((dispDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) || (!(dispDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) && !(dispDevice.StateFlags & DISPLAY_DEVICE_MODESPRUNED))) ++num_devices; ++dev; } while (dev); #else // Linux void* handle = 0; // NvCfgBool (*ptr_nvCfgGetDevices)( int*, NvCfgDevice**); typedef NvCfgBool (*nvCfgGetDevicesType)( int*, NvCfgDevice**); nvCfgGetDevicesType ptr_nvCfgGetDevices; // acquire handle to shared library handle = dlopen( "libnvidia-cfg.so", RTLD_LAZY); if( ! handle) { // no NVIDIA driver installed fprintf( stderr, "Cannot find NVIDIA driver.\n" ); fprintf( stderr, "Graphics interoperability not supported.\n" ); return CUTFalse; } ptr_nvCfgGetDevices = (nvCfgGetDevicesType) dlsym( handle, "nvCfgGetDevices"); char* error = 0; if( 0 != (error = dlerror())) { fprintf( stderr, "Cannot query number of devices in the system.\n" ); fprintf( stderr, "Graphics interoperability not supported.\n" ); return CUTFalse; } // call function int num_devices; NvCfgDevice* devs; (*ptr_nvCfgGetDevices)( &num_devices, &devs); #endif // _WIN32 if( 1 != num_devices) { fprintf( stderr, "Graphics interoperability on multi GPU systems currently not supported.\n" ); return CUTFalse; } return CUTTrue; }
/** * \brief return the name of the selected device if it is indepedant */ static char *get_display_name(void) { DISPLAY_DEVICE disp; disp.cb = sizeof(disp); EnumDisplayDevices(NULL, vo_adapter_num, &disp, 0); if (disp.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) return NULL; return disp.DeviceName; }
// static HRESULT D3DPipelineManager::GDICheckForBadHardware() { DISPLAY_DEVICE dd; dd.cb = sizeof(DISPLAY_DEVICE); int failedDevices = 0; int attachedDevices = 0; int i = 0; WCHAR *id; WCHAR vendorId[5]; WCHAR deviceId[5]; DWORD dwDId, dwVId; J2dTraceLn(J2D_TRACE_INFO, "D3DPPLM::GDICheckForBadHardware"); // i<20 is to guard against buggy drivers while (EnumDisplayDevices(NULL, i, &dd, 0) && i < 20) { if (dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) { attachedDevices++; id = dd.DeviceID; if (wcslen(id) > 21) { // get vendor ID wcsncpy(vendorId, id+8, 4); int args1 = swscanf(vendorId, L"%X", &dwVId); // get device ID wcsncpy(deviceId, id+17, 4); int args2 = swscanf(deviceId, L"%X", &dwDId); if (args1 == 1 && args2 == 1) { J2dTraceLn2(J2D_TRACE_VERBOSE, " device: vendorID=0x%04x, deviceId=0x%04x", dwVId, dwDId); // since we don't have a driver version here we will // just ask to ignore the version for now; bad hw // entries with specific drivers information will be // processed later when d3d is initialized and we can // obtain a driver version if (FAILED(CheckForBadHardware(dwVId, dwDId, MAX_VERSION))){ failedDevices++; } } } } i++; } if (failedDevices == attachedDevices) { J2dRlsTraceLn(J2D_TRACE_ERROR, "D3DPPLM::GDICheckForBadHardware: no suitable devices found"); return E_FAIL; } return S_OK; }
static int fullResInit() { if (!hVideoDlg) { return 1; } DEVMODE devMode; devMode.dmSize = sizeof(DEVMODE); devMode.dmDriverExtra = 0; DISPLAY_DEVICE device; device.cb = sizeof(DISPLAY_DEVICE); EnumDisplayDevices(NULL, nVidAdapter, &device, 0); // fullscreen res box // Run through all possible screenmodes and fill the combobox for (int i = 0; EnumDisplaySettings(device.DeviceName, i, &devMode); i++) { // We're only interested in 16, 24, or 32 bit modes. if (devMode.dmBitsPerPel & 0x30) { long item = 0, itemValue; long newRes = (devMode.dmPelsWidth << 16) | devMode.dmPelsHeight; // See if the resolution is already in the combobox do { itemValue = SendDlgItemMessage(hVideoDlg, IDC_PREF_FULLSCREENRES, CB_GETITEMDATA, item, 0); item++; } while ((itemValue != CB_ERR) && (itemValue != newRes)); // If not, add it if (itemValue == CB_ERR) { TCHAR szRes[MAX_PATH]; _stprintf(szRes, _T("%li x %li"), devMode.dmPelsWidth, devMode.dmPelsHeight); item = SendDlgItemMessage(hVideoDlg, IDC_PREF_FULLSCREENRES, CB_ADDSTRING, 0, (LPARAM)&szRes); SendDlgItemMessage(hVideoDlg, IDC_PREF_FULLSCREENRES, CB_SETITEMDATA, item, newRes); } } } // set select long myRes = (nVidWidth << 16) | nVidHeight; long count = SendDlgItemMessage(hVideoDlg, IDC_PREF_FULLSCREENRES, CB_GETCOUNT, 0, 0); long item = 0; for (long i = 0; i < count; i++) { item = SendDlgItemMessage(hVideoDlg, IDC_PREF_FULLSCREENRES, CB_GETITEMDATA, i, 0); if (myRes == item) { SendDlgItemMessage(hVideoDlg, IDC_PREF_FULLSCREENRES, CB_SETCURSEL, (WPARAM)i, 0); break; } } // depth SendDlgItemMessage(hVideoDlg, IDC_PREF_16BIT, BM_SETCHECK, (nVidDepth == 16) ? BST_CHECKED : BST_UNCHECKED, 0); SendDlgItemMessage(hVideoDlg, IDC_PREF_32BIT, BM_SETCHECK, (nVidDepth == 32) ? BST_CHECKED : BST_UNCHECKED, 0); return 0; }
// ディスプレイの位置とサイズを返す int Window::GetDisplayRect( long displaynum, int *x, int *y, int *width, int *height ) { DISPLAY_DEVICE disdev; DEVMODE devmode; if ( x ) { *x = 0; } if ( y ) { *y = 0; } if ( width ) { *width = 0; } if ( height ) { *height = 0; } memset( &disdev, 0, sizeof( DISPLAY_DEVICE ) ); disdev.cb = sizeof( DISPLAY_DEVICE ); if ( EnumDisplayDevices( NULL, displaynum, &disdev, 0 ) == 0 ) { // 不正なディスプレイ番号 return 1; } memset( &devmode, 0, sizeof( DEVMODE ) ); devmode.dmSize = sizeof( DEVMODE ); if ( EnumDisplaySettingsEx( disdev.DeviceName, /*ENUM_CURRENT_SETTINGS*/ENUM_REGISTRY_SETTINGS, &devmode, EDS_RAWMODE ) == 0 ) { // 設定を取得できなかった return 2; } if ( x ) { *x = devmode.dmPosition.x; } if ( y ) { *y = devmode.dmPosition.y; } if ( width ) { *width = devmode.dmPelsWidth; } if ( height ) { *height = devmode.dmPelsHeight; } return 0; }
std::list<DISPLAY_DEVICE> DisplayManager::ListAllDevices() { std::list<DISPLAY_DEVICE> devs; DISPLAY_DEVICE dev = {}; dev.cb = sizeof(DISPLAY_DEVICE); for (int i = 0; EnumDisplayDevices(NULL, i, &dev, NULL) != 0; ++i) { if (dev.StateFlags & DISPLAY_DEVICE_ACTIVE) { devs.push_back(dev); } } return devs; }
int WIN_InitModes(_THIS) { SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; DWORD i, j, count; DISPLAY_DEVICE device; device.cb = sizeof(device); for (i = 0;; ++i) { TCHAR DeviceName[32]; if (!EnumDisplayDevices(NULL, i, &device, 0)) { break; } if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) { continue; } SDL_memcpy(DeviceName, device.DeviceName, sizeof(DeviceName)); #ifdef DEBUG_MODES printf("Device: %s\n", WIN_StringToUTF8(DeviceName)); #endif count = 0; for (j = 0;; ++j) { if (!EnumDisplayDevices(DeviceName, j, &device, 0)) { break; } if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) { continue; } count += WIN_AddDisplay(device.DeviceName); } if (count == 0) { WIN_AddDisplay(DeviceName); } } if (_this->num_displays == 0) { SDL_SetError("No displays available"); return -1; } return 0; }