Skip to content

Commit aa0089a

Browse files
committed
[DXDIAG] Rework display enumeration, to use DirectDrawEnumerateEx
We can now get a device GUID by display, which is given to DirectDrawCreate.
1 parent 343d1d4 commit aa0089a

File tree

1 file changed

+66
-39
lines changed

1 file changed

+66
-39
lines changed

base/applications/dxdiag/display.c

Lines changed: 66 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -305,62 +305,89 @@ InitializeDialog(HWND hwndDlg, PDISPLAY_DEVICEW pDispDevice)
305305
return TRUE;
306306
}
307307

308-
void InitializeDisplayAdapters(PDXDIAG_CONTEXT pContext)
308+
309+
static BOOL WINAPI
310+
DDEnumerateCallback(
311+
IN GUID *lpGuid,
312+
IN LPSTR lpDriverName,
313+
IN LPSTR lpDriverDescription,
314+
IN LPVOID lpContext,
315+
IN HMONITOR hMonitor)
309316
{
310317
DISPLAY_DEVICEW DispDevice;
318+
LPWSTR lpDriverDescriptionW;
319+
PDXDIAG_CONTEXT pContext = lpContext;
311320
PDXDIAG_DISPLAY *pDisplayAdapters;
312321
PDXDIAG_DISPLAY pDisplayAdapter;
313322
HWND hwndDlg;
314323
WCHAR szDisplay[20];
315324
WCHAR szText[30];
316-
DWORD dwOffset = 0;
317-
318-
while(TRUE)
319-
{
320-
ZeroMemory(&DispDevice, sizeof(DISPLAY_DEVICEW));
321-
DispDevice.cb = sizeof(DISPLAY_DEVICEW);
322-
if (!EnumDisplayDevicesW(NULL, pContext->NumDisplayAdapter + dwOffset, &DispDevice, 0))
323-
return;
325+
int len;
326+
BOOL ret;
324327

325-
/* skip devices not attached to the desktop and mirror drivers */
326-
if (!(DispDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) || (DispDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER))
327-
{
328-
dwOffset++;
329-
continue;
330-
}
331-
if (pContext->NumDisplayAdapter)
332-
pDisplayAdapters = HeapReAlloc(GetProcessHeap(), 0, pContext->DisplayAdapters, (pContext->NumDisplayAdapter + 1) * sizeof(PDXDIAG_DISPLAY));
333-
else
334-
pDisplayAdapters = HeapAlloc(GetProcessHeap(), 0, sizeof(PDXDIAG_DISPLAY));
328+
/* Convert lpDriverDescription to WCHAR */
329+
len = MultiByteToWideChar(CP_ACP, 0, lpDriverDescription, strlen(lpDriverDescription), NULL, 0);
330+
if (!len)
331+
return FALSE;
332+
lpDriverDescriptionW = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
333+
if (!lpDriverDescriptionW)
334+
return FALSE;
335+
MultiByteToWideChar(CP_ACP, 0, lpDriverDescription, strlen(lpDriverDescription), lpDriverDescriptionW, len);
336+
lpDriverDescriptionW[len] = UNICODE_NULL;
337+
338+
/* Get associated display device */
339+
ZeroMemory(&DispDevice, sizeof(DispDevice));
340+
DispDevice.cb = sizeof(DispDevice);
341+
ret = EnumDisplayDevicesW(lpDriverDescriptionW, 0, &DispDevice, 0);
342+
HeapFree(GetProcessHeap(), 0, lpDriverDescriptionW);
343+
if (!ret)
344+
return TRUE;
345+
346+
pDisplayAdapter = HeapAlloc(GetProcessHeap(), 0, sizeof(DXDIAG_DISPLAY));
347+
if (!pDisplayAdapter)
348+
return FALSE;
335349

336-
if (!pDisplayAdapters)
337-
break;
350+
if (pContext->NumDisplayAdapter)
351+
pDisplayAdapters = HeapReAlloc(GetProcessHeap(), 0, pContext->DisplayAdapters, (pContext->NumDisplayAdapter + 1) * sizeof(PDXDIAG_DISPLAY));
352+
else
353+
pDisplayAdapters = HeapAlloc(GetProcessHeap(), 0, (pContext->NumDisplayAdapter + 1) * sizeof(PDXDIAG_DISPLAY));
338354

339-
pDisplayAdapter = HeapAlloc(GetProcessHeap(), 0, sizeof(DXDIAG_DISPLAY));
340-
if (!pDisplayAdapter)
341-
break;
355+
if (!pDisplayAdapters)
356+
{
357+
HeapFree(GetProcessHeap(), 0, pDisplayAdapter);
358+
return FALSE;
359+
}
342360

343-
pContext->DisplayAdapters = pDisplayAdapters;
344-
hwndDlg = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_DISPLAY_DIALOG), pContext->hMainDialog, DisplayPageWndProc, (LPARAM)pDisplayAdapter); EnableDialogTheme(hwndDlg);
345-
if (!hwndDlg)
346-
break;
361+
pContext->DisplayAdapters = pDisplayAdapters;
362+
hwndDlg = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_DISPLAY_DIALOG), pContext->hMainDialog, DisplayPageWndProc, (LPARAM)pDisplayAdapter);
363+
EnableDialogTheme(hwndDlg);
364+
if (!hwndDlg)
365+
{
366+
HeapFree(GetProcessHeap(), 0, pDisplayAdapter);
367+
return FALSE;
368+
}
347369

348-
/* initialize the dialog */
349-
InitializeDialog(hwndDlg, &DispDevice);
370+
/* initialize the dialog */
371+
InitializeDialog(hwndDlg, &DispDevice);
350372

351-
szDisplay[0] = L'\0';
352-
LoadStringW(hInst, IDS_DISPLAY_DIALOG, szDisplay, sizeof(szDisplay)/sizeof(WCHAR));
353-
szDisplay[(sizeof(szDisplay)/sizeof(WCHAR))-1] = L'\0';
373+
szDisplay[0] = UNICODE_NULL;
374+
LoadStringW(hInst, IDS_DISPLAY_DIALOG, szDisplay, ARRAYSIZE(szDisplay));
375+
szDisplay[ARRAYSIZE(szDisplay) - 1] = UNICODE_NULL;
354376

355-
wsprintfW (szText, L"%s %u", szDisplay, pContext->NumDisplayAdapter + 1);
356-
InsertTabCtrlItem(GetDlgItem(pContext->hMainDialog, IDC_TAB_CONTROL), pContext->NumDisplayAdapter + 1, szText);
377+
wsprintfW(szText, L"%s %u", szDisplay, pContext->NumDisplayAdapter + 1);
378+
InsertTabCtrlItem(GetDlgItem(pContext->hMainDialog, IDC_TAB_CONTROL), pContext->NumDisplayAdapter + 1, szText);
357379

358-
pDisplayAdapter->hDisplayWnd = hwndDlg;
359-
pDisplayAdapters[pContext->NumDisplayAdapter] = pDisplayAdapter;
360-
pContext->NumDisplayAdapter++;
361-
}
380+
pDisplayAdapter->hDisplayWnd = hwndDlg;
381+
if (lpGuid)
382+
pDisplayAdapter->guid = *lpGuid;
383+
pContext->DisplayAdapters[pContext->NumDisplayAdapter++] = pDisplayAdapter;
384+
return TRUE;
385+
}
362386

363387

388+
void InitializeDisplayAdapters(PDXDIAG_CONTEXT pContext)
389+
{
390+
DirectDrawEnumerateExA(DDEnumerateCallback, pContext, DDENUM_ATTACHEDSECONDARYDEVICES);
364391
}
365392

366393

0 commit comments

Comments
 (0)