2 * PROJECT: ReactX Diagnosis Application
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: base/applications/dxdiag/display.c
5 * PURPOSE: ReactX diagnosis display page
6 * COPYRIGHT: Copyright 2008 Johannes Anderwald
15 GetFileModifyTime(LPCWSTR pFullPath
, WCHAR
* szTime
, int szTimeSize
)
19 SYSTEMTIME SysTime
, LocalTime
;
21 TIME_ZONE_INFORMATION TimeInfo
;
23 hFile
= CreateFileW(pFullPath
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
27 if (!GetFileTime(hFile
, NULL
, NULL
, &AccessTime
))
34 if(!GetTimeZoneInformation(&TimeInfo
))
37 if (!FileTimeToSystemTime(&AccessTime
, &SysTime
))
40 if (!SystemTimeToTzSpecificLocalTime(&TimeInfo
, &SysTime
, &LocalTime
))
43 Length
= GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &LocalTime
, NULL
, szTime
, szTimeSize
);
44 szTime
[Length
-1] = L
' ';
45 return GetTimeFormatW(LOCALE_USER_DEFAULT
, TIME_FORCE24HOURFORMAT
, &LocalTime
, NULL
, &szTime
[Length
], szTimeSize
-Length
);
51 DriverFilesCallback(IN PVOID Context
,
58 LPCWSTR pFullPath
= (LPCWSTR
)Param1
;
60 LRESULT Length
, fLength
;
61 HWND
* hDlgCtrls
= (HWND
*)Context
;
63 if (wcsstr(pFullPath
, L
"\\DRIVERS\\"))
65 /* exclude files from drivers dir to have failsafe file version/date information */
69 pFile
= wcsrchr(pFullPath
, L
'\\');
74 fLength
= wcslen(pFile
) + 1;
76 Length
= SendMessageW(hDlgCtrls
[0], WM_GETTEXTLENGTH
, 0, 0) + 1;
77 pBuffer
= HeapAlloc(GetProcessHeap(), 0, (Length
+ fLength
) * sizeof(WCHAR
));
79 return ERROR_OUTOFMEMORY
;
81 Length
= SendMessageW(hDlgCtrls
[0], WM_GETTEXT
, Length
, (LPARAM
)pBuffer
);
84 pBuffer
[Length
++] = L
',';
88 /* set file version */
89 if (GetFileVersion(pFullPath
, szVer
, sizeof(szVer
)/sizeof(WCHAR
)))
90 SendMessageW(hDlgCtrls
[1], WM_SETTEXT
, 0, (LPARAM
)szVer
);
92 if (GetFileModifyTime(pFullPath
, szVer
, sizeof(szVer
)/sizeof(WCHAR
)))
93 SendMessageW(hDlgCtrls
[2], WM_SETTEXT
, 0, (LPARAM
)szVer
);
96 wcscpy(&pBuffer
[Length
], pFile
);
97 SendMessageW(hDlgCtrls
[0], WM_SETTEXT
, 0, (LPARAM
)pBuffer
);
98 HeapFree(GetProcessHeap(), 0, pBuffer
);
103 EnumerateDrivers(PVOID Context
, HDEVINFO hList
, PSP_DEVINFO_DATA pInfoData
)
106 SP_DEVINSTALL_PARAMS DeviceInstallParams
= {0};
107 SP_DRVINFO_DATA DriverInfoData
;
110 DeviceInstallParams
.cbSize
= sizeof(DeviceInstallParams
);
111 if (!SetupDiGetDeviceInstallParamsW(hList
, pInfoData
, &DeviceInstallParams
))
114 DeviceInstallParams
.FlagsEx
|= (DI_FLAGSEX_INSTALLEDDRIVER
| DI_FLAGSEX_ALLOWEXCLUDEDDRVS
);
115 if (!SetupDiSetDeviceInstallParams(hList
, pInfoData
, &DeviceInstallParams
))
118 if (!SetupDiBuildDriverInfoList(hList
, pInfoData
, SPDIT_CLASSDRIVER
))
121 DriverInfoData
.cbSize
= sizeof(DriverInfoData
);
122 if (!SetupDiEnumDriverInfoW(hList
, pInfoData
, SPDIT_CLASSDRIVER
, 0, &DriverInfoData
))
125 DriverInfoData
.cbSize
= sizeof(DriverInfoData
);
126 if (!SetupDiSetSelectedDriverW(hList
, pInfoData
, &DriverInfoData
))
129 hQueue
= SetupOpenFileQueue();
130 if (hQueue
== (HSPFILEQ
)INVALID_HANDLE_VALUE
)
133 DeviceInstallParams
.cbSize
= sizeof(DeviceInstallParams
);
134 if (!SetupDiGetDeviceInstallParamsW(hList
, pInfoData
, &DeviceInstallParams
))
136 SetupCloseFileQueue(hQueue
);
140 DeviceInstallParams
.FileQueue
= hQueue
;
141 DeviceInstallParams
.Flags
|= DI_NOVCP
;
143 if (!SetupDiSetDeviceInstallParamsW(hList
, pInfoData
, &DeviceInstallParams
))
145 SetupCloseFileQueue(hQueue
);
149 if(!SetupDiCallClassInstaller(DIF_INSTALLDEVICEFILES
, hList
, pInfoData
))
151 SetupCloseFileQueue(hQueue
);
156 /* enumerate the driver files */
157 SetupScanFileQueueW(hQueue
, SPQ_SCAN_USE_CALLBACK
, NULL
, DriverFilesCallback
, Context
, &Result
);
158 SetupCloseFileQueue(hQueue
);
163 SetDeviceDetails(HWND
* hDlgCtrls
, LPCGUID classGUID
, LPGUID
* deviceGUID
)
167 SP_DEVINFO_DATA InfoData
;
170 /* create the setup list */
171 hInfo
= SetupDiGetClassDevsW(classGUID
, NULL
, NULL
, DIGCF_PRESENT
|DIGCF_PROFILE
);
172 if (hInfo
== INVALID_HANDLE_VALUE
)
177 ZeroMemory(&InfoData
, sizeof(InfoData
));
178 InfoData
.cbSize
= sizeof(InfoData
);
180 if (SetupDiEnumDeviceInfo(hInfo
, dwIndex
, &InfoData
))
182 /* set device name */
183 if (SetupDiGetDeviceRegistryPropertyW(hInfo
, &InfoData
, SPDRP_DEVICEDESC
, NULL
, (PBYTE
)szText
, sizeof(szText
), NULL
))
184 SendMessageW(hDlgCtrls
[0], WM_SETTEXT
, 0, (LPARAM
)szText
);
186 /* set the manufacturer name */
187 if (SetupDiGetDeviceRegistryPropertyW(hInfo
, &InfoData
, SPDRP_MFG
, NULL
, (PBYTE
)szText
, sizeof(szText
), NULL
))
188 SendMessageW(hDlgCtrls
[1], WM_SETTEXT
, 0, (LPARAM
)szText
);
191 * we currently enumerate only the first adapter
193 EnumerateDrivers(&hDlgCtrls
[2], hInfo
, &InfoData
);
197 if (GetLastError() == ERROR_NO_MORE_ITEMS
)
203 /* destroy the setup list */
204 SetupDiDestroyDeviceInfoList(hInfo
);
210 InitializeDialog(HWND hwndDlg
, PDISPLAY_DEVICEW pDispDevice
)
218 IDirect3D9
* ppObj
= NULL
;
219 D3DADAPTER_IDENTIFIER9 Identifier
;
225 //ppObj = Direct3DCreate9(D3D_SDK_VERSION);
228 hResult
= IDirect3D9_GetAdapterIdentifier(ppObj
, D3DADAPTER_DEFAULT
, 2/*D3DENUM_WHQL_LEVEL*/, &Identifier
);
229 if (hResult
== D3D_OK
)
232 if (Identifier
.WHQLLevel
)
234 /* adapter is WHQL certified */
235 LoadStringW(hInst
, IDS_OPTION_YES
, szText
, sizeof(szText
)/sizeof(WCHAR
));
239 LoadStringW(hInst
, IDS_OPTION_NO
, szText
, sizeof(szText
)/sizeof(WCHAR
));
242 IDirect3D9_Release(ppObj
);
246 LoadStringW(hInst
, IDS_DEVICE_STATUS_UNKNOWN
, szText
, sizeof(szText
)/sizeof(WCHAR
));
248 szText
[(sizeof(szText
)/sizeof(WCHAR
))-1] = L
'\0';
249 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_ADAPTER_LOGO
, WM_SETTEXT
, 0, (LPARAM
)szText
);
251 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, &pDispDevice
->DeviceKey
[18], 0, KEY_READ
, &hKey
) != ERROR_SUCCESS
)
254 if (GetRegValue(hKey
, NULL
, L
"HardwareInformation.ChipType", REG_BINARY
, szText
, sizeof(szText
)))
257 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_ADAPTER_CHIP
, WM_SETTEXT
, 0, (LPARAM
)szText
);
260 if (GetRegValue(hKey
, NULL
, L
"HardwareInformation.DacType", REG_BINARY
, szText
, sizeof(szText
)))
263 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_ADAPTER_DAC
, WM_SETTEXT
, 0, (LPARAM
)szText
);
266 if (GetRegValue(hKey
, NULL
, L
"HardwareInformation.MemorySize", REG_BINARY
, (LPWSTR
)&dwMemory
, sizeof(dwMemory
)))
268 /* set chip memory size */
269 if (dwMemory
> (1048576))
271 /* buggy ATI driver requires that */
275 if (LoadStringW(hInst
, IDS_FORMAT_ADAPTER_MEM
, szFormat
, sizeof(szFormat
)/sizeof(WCHAR
)))
276 szFormat
[(sizeof(szFormat
)/sizeof(WCHAR
))-1] = L
'\0';
277 wsprintfW(szText
, szFormat
, dwMemory
);
278 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_ADAPTER_MEM
, WM_SETTEXT
, 0, (LPARAM
)szText
);
281 /* retrieve current display mode */
282 DevMode
.dmSize
= sizeof(DEVMODEW
);
283 if (EnumDisplaySettingsW(pDispDevice
->DeviceName
, ENUM_CURRENT_SETTINGS
, &DevMode
))
286 if (LoadStringW(hInst
, IDS_FORMAT_ADAPTER_MODE
, szFormat
, sizeof(szFormat
)/sizeof(WCHAR
)))
287 szFormat
[(sizeof(szFormat
)/sizeof(WCHAR
))-1] = L
'\0';
288 wsprintfW(szText
, szFormat
, DevMode
.dmPelsWidth
, DevMode
.dmPelsHeight
, DevMode
.dmBitsPerPel
, DevMode
.dmDisplayFrequency
);
289 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_ADAPTER_MODE
, WM_SETTEXT
, 0, (LPARAM
)szText
);
292 /* query attached monitor */
293 wcscpy(szText
, pDispDevice
->DeviceName
);
294 ZeroMemory(pDispDevice
, sizeof(DISPLAY_DEVICEW
));
295 pDispDevice
->cb
= sizeof(DISPLAY_DEVICEW
);
296 if (EnumDisplayDevicesW(szText
, 0, pDispDevice
, 0))
298 /* set monitor name */
299 SendDlgItemMessageW(hwndDlg
, IDC_STATIC_ADAPTER_MONITOR
, WM_SETTEXT
, 0, (LPARAM
)pDispDevice
->DeviceString
);
302 hDlgCtrls
[0] = GetDlgItem(hwndDlg
, IDC_STATIC_ADAPTER_ID
);
303 hDlgCtrls
[1] = GetDlgItem(hwndDlg
, IDC_STATIC_ADAPTER_VENDOR
);
304 hDlgCtrls
[2] = GetDlgItem(hwndDlg
, IDC_STATIC_ADAPTER_DRIVER
);
305 hDlgCtrls
[3] = GetDlgItem(hwndDlg
, IDC_STATIC_ADAPTER_VERSION
);
306 hDlgCtrls
[4] = GetDlgItem(hwndDlg
, IDC_STATIC_ADAPTER_DATE
);
308 SetDeviceDetails(hDlgCtrls
, &GUID_DEVCLASS_DISPLAY
, NULL
);
312 void InitializeDisplayAdapters(PDXDIAG_CONTEXT pContext
)
314 DISPLAY_DEVICEW DispDevice
;
323 ZeroMemory(&DispDevice
, sizeof(DISPLAY_DEVICEW
));
324 DispDevice
.cb
= sizeof(DISPLAY_DEVICEW
);
325 if (!EnumDisplayDevicesW(NULL
, pContext
->NumDisplayAdapter
+ dwOffset
, &DispDevice
, 0))
328 /* skip devices not attached to the desktop and mirror drivers */
329 if (!(DispDevice
.StateFlags
& DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
) || (DispDevice
.StateFlags
& DISPLAY_DEVICE_MIRRORING_DRIVER
))
334 if (pContext
->NumDisplayAdapter
)
335 hDlgs
= HeapReAlloc(GetProcessHeap(), 0, pContext
->hDisplayWnd
, (pContext
->NumDisplayAdapter
+ 1) * sizeof(HWND
));
337 hDlgs
= HeapAlloc(GetProcessHeap(), 0, (pContext
->NumDisplayAdapter
+ 1) * sizeof(HWND
));
342 pContext
->hDisplayWnd
= hDlgs
;
343 hwndDlg
= CreateDialogParamW(hInst
, MAKEINTRESOURCEW(IDD_DISPLAY_DIALOG
), pContext
->hMainDialog
, DisplayPageWndProc
, (LPARAM
)pContext
); EnableDialogTheme(hwndDlg
);
347 /* initialize the dialog */
348 InitializeDialog(hwndDlg
, &DispDevice
);
350 szDisplay
[0] = L
'\0';
351 LoadStringW(hInst
, IDS_DISPLAY_DIALOG
, szDisplay
, sizeof(szDisplay
)/sizeof(WCHAR
));
352 szDisplay
[(sizeof(szDisplay
)/sizeof(WCHAR
))-1] = L
'\0';
354 wsprintfW (szText
, L
"%s %u", szDisplay
, pContext
->NumDisplayAdapter
+ 1);
355 InsertTabCtrlItem(GetDlgItem(pContext
->hMainDialog
, IDC_TAB_CONTROL
), pContext
->NumDisplayAdapter
+ 1, szText
);
357 hDlgs
[pContext
->NumDisplayAdapter
] = hwndDlg
;
358 pContext
->NumDisplayAdapter
++;
366 DisplayPageWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
369 PDXDIAG_CONTEXT pContext
= (PDXDIAG_CONTEXT
)GetWindowLongPtr(hDlg
, DWLP_USER
);
374 pContext
= (PDXDIAG_CONTEXT
) lParam
;
375 SetWindowLongPtr(hDlg
, DWLP_USER
, (LONG_PTR
)pContext
);
376 SetWindowPos(hDlg
, NULL
, 10, 32, 0, 0, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOSIZE
| SWP_NOZORDER
);
381 switch(LOWORD(wParam
))
383 case IDC_BUTTON_TESTDD
:
384 case IDC_BUTTON_TEST3D
:
385 GetWindowRect(pContext
->hMainDialog
, &rect
);
386 /* FIXME log result errors */
387 if (IDC_BUTTON_TESTDD
== LOWORD(wParam
))
389 else if (IDC_BUTTON_TEST3D
== LOWORD(wParam
))
391 SetWindowPos(pContext
->hMainDialog
, NULL
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOSIZE
| SWP_NOZORDER
);