1 //-----------------------------------------------------------------------------
4 // Desc: This sample demonstrates how to enumerate all of the devices and show
5 // the driver information about each.
8 // Copyright (c) 1998 Microsoft Corporation. All rights reserved.
9 //-----------------------------------------------------------------------------
11 #ifndef WIN32_LEAN_AND_MEAN
12 #define WIN32_LEAN_AND_MEAN
14 //-----------------------------------------------------------------------------
16 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 #define TITLE "DirectDraw Enumeration Example"
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
32 #define MAX_DEVICES 16
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
37 int g_iMaxDevices = 0;
39 DDDEVICEIDENTIFIER DeviceInfo;
40 DDDEVICEIDENTIFIER DeviceInfoHost;
41 } g_DeviceInfo[MAX_DEVICES];
46 //-----------------------------------------------------------------------------
48 // Desc: This function is called if an initialization function fails
49 //-----------------------------------------------------------------------------
51 InitFail(LPCTSTR szError, ...)
56 va_start(vl, szError);
57 vsprintf(szBuff, szError, vl);
58 MessageBox(NULL, szBuff, TITLE, MB_OK);
65 //-----------------------------------------------------------------------------
66 // Name: SetInfoDlgText()
67 // Desc: Update all of the text and buttons in the dialog
68 //-----------------------------------------------------------------------------
70 SetInfoDlgText(HWND hDlg, int iCurrent, DWORD dwHost)
74 LPDDDEVICEIDENTIFIER pDI;
76 if (dwHost == DDGDI_GETHOSTIDENTIFIER)
77 CheckRadioButton( hDlg, IDC_RADIO_DEVICE, IDC_RADIO_HOST, IDC_RADIO_HOST );
79 CheckRadioButton( hDlg, IDC_RADIO_DEVICE, IDC_RADIO_DEVICE, IDC_RADIO_DEVICE );
81 pDI = &g_DeviceInfo[iCurrent].DeviceInfo;
82 if (dwHost == DDGDI_GETHOSTIDENTIFIER)
83 pDI = &g_DeviceInfo[iCurrent].DeviceInfoHost;
85 wsprintf(szBuff, "Device information for device %d of %d",iCurrent + 1,g_iMaxDevices);
86 SetDlgItemText( hDlg, IDC_RADIO_DEVICE, szBuff);
89 wsprintf(szBuff,"%08X",pDI->dwVendorId);
90 SetDlgItemText( hDlg, IDC_DWVENDORID, szBuff);
91 wsprintf(szBuff,"%08X",pDI->dwDeviceId);
92 SetDlgItemText( hDlg, IDC_DWDEVICEID, szBuff);
93 wsprintf(szBuff,"%08X",pDI->dwSubSysId);
94 SetDlgItemText( hDlg, IDC_DWSUBSYS, szBuff);
95 wsprintf(szBuff,"%08X",pDI->dwRevision);
96 SetDlgItemText( hDlg, IDC_DWREVISION, szBuff);
99 wsprintf(szBuff,"%d.%02d.%02d.%04d",
100 HIWORD(pDI->liDriverVersion.u.HighPart),
101 LOWORD(pDI->liDriverVersion.u.HighPart),
102 HIWORD(pDI->liDriverVersion.u.LowPart),
103 LOWORD(pDI->liDriverVersion.u.LowPart) );
104 SetDlgItemText( hDlg, IDC_VERSION, szBuff);
106 //Device description and HAL filename
107 SetDlgItemText( hDlg, IDC_DESCRIPTION, pDI->szDescription);
108 SetDlgItemText( hDlg, IDC_FILENAME, pDI->szDriver);
110 //Unique driver/device identifier:
111 pGUID = &pDI->guidDeviceIdentifier;
112 wsprintf(szBuff, "%08X-%04X-%04X-%02X%02X%02X%02X%02X%02X%02X%02X",
113 pGUID->Data1, pGUID->Data2, pGUID->Data3,
114 pGUID->Data4[0], pGUID->Data4[1], pGUID->Data4[2], pGUID->Data4[3],
115 pGUID->Data4[4], pGUID->Data4[5], pGUID->Data4[6], pGUID->Data4[7]);
116 SetDlgItemText( hDlg, IDC_GUID, szBuff);
118 // Change the state and style of the Prev and Next buttons if needed
121 // The Prev button should be disabled
122 SetFocus(GetDlgItem(hDlg, IDOK));
123 SendDlgItemMessage( hDlg, IDC_PREV, BM_SETSTYLE, BS_PUSHBUTTON, TRUE);
124 SendMessage(hDlg, DM_SETDEFID, IDOK, 0);
125 EnableWindow(GetDlgItem(hDlg, IDC_PREV), FALSE);
128 if (IsWindowEnabled(GetDlgItem(hDlg, IDC_PREV)) == FALSE)
129 EnableWindow(GetDlgItem(hDlg, IDC_PREV), TRUE);
131 if (iCurrent >= (g_iMaxDevices - 1))
133 // The Next button should be disabled
134 SetFocus(GetDlgItem(hDlg, IDOK));
135 SendDlgItemMessage( hDlg, IDC_NEXT, BM_SETSTYLE, BS_PUSHBUTTON, TRUE);
136 SendMessage(hDlg, DM_SETDEFID, IDOK, 0);
137 EnableWindow(GetDlgItem(hDlg, IDC_NEXT), FALSE);
140 if (IsWindowEnabled(GetDlgItem(hDlg, IDC_NEXT)) == FALSE)
141 EnableWindow(GetDlgItem(hDlg, IDC_NEXT), TRUE);
147 //-----------------------------------------------------------------------------
148 // Name: InfoDlgProc()
149 // Desc: The dialog window proc
150 //-----------------------------------------------------------------------------
152 InfoDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
155 static int iCurrent = 0;
156 static DWORD dwHost = 0;
161 // Setup the first devices text
162 SetInfoDlgText(hDlg, iCurrent, dwHost);
165 switch (HIWORD(wParam))
168 switch (LOWORD(wParam))
172 EndDialog(hDlg, TRUE);
175 // Show the previous device
178 SetInfoDlgText(hDlg, iCurrent, dwHost);
181 // Show the next device
182 if (iCurrent < g_iMaxDevices)
184 SetInfoDlgText(hDlg, iCurrent, dwHost);
187 case IDC_RADIO_DEVICE:
188 if (dwHost == DDGDI_GETHOSTIDENTIFIER )
191 dwHost = DDGDI_GETHOSTIDENTIFIER;
192 SetInfoDlgText(hDlg, iCurrent, dwHost);
206 //-----------------------------------------------------------------------------
207 // Name: DDEnumCallbackEx()
208 // Desc: This callback gets the information for each device enumerated
209 //-----------------------------------------------------------------------------
211 DDEnumCallbackEx(GUID *pGUID, LPSTR pDescription, LPSTR pName,
212 LPVOID pContext, HMONITOR hm)
214 LPDIRECTDRAW pDD; // DD1 interface, used to get DD4 interface
215 LPDIRECTDRAW4 pDD4 = NULL; // DirectDraw4 interface
218 // Create the main DirectDraw object
219 hRet = DirectDrawCreate(pGUID, &pDD, NULL);
222 InitFail("DirectDrawCreate FAILED");
223 return DDENUMRET_CANCEL;
226 // Fetch DirectDraw4 interface
227 hRet = pDD->QueryInterface(IID_IDirectDraw4, (LPVOID *)&pDD4);
230 InitFail("QueryInterface FAILED");
231 return DDENUMRET_CANCEL;
234 // Get the device information and save it
235 hRet = pDD4->GetDeviceIdentifier(&g_DeviceInfo[g_iMaxDevices].DeviceInfo,0);
236 hRet = pDD4->GetDeviceIdentifier(&g_DeviceInfo[g_iMaxDevices].DeviceInfoHost,DDGDI_GETHOSTIDENTIFIER);
238 // Finished with the DirectDraw object, so release it
242 // Bump to the next open slot or finish the callbacks if full
243 if (g_iMaxDevices < MAX_DEVICES)
246 return DDENUMRET_CANCEL;
253 //-----------------------------------------------------------------------------
254 // Name: DDEnumCallback()
255 // Desc: Old style callback retained for backwards compatibility
256 //-----------------------------------------------------------------------------
258 DDEnumCallback(GUID *pGUID, LPSTR pDescription, LPSTR pName, LPVOID context)
260 return (DDEnumCallbackEx(pGUID, pDescription, pName, context, NULL));
266 //-----------------------------------------------------------------------------
268 // Desc: Entry point to the program. Initializes everything and calls
269 // DirectDrawEnumerateEx() to get all of the device info.
270 //-----------------------------------------------------------------------------
272 WinMain(HINSTANCE hInstance,
273 HINSTANCE hPrevInstance,
277 LPDIRECTDRAWENUMERATEEX pDirectDrawEnumerateEx;
280 // Do a GetModuleHandle and GetProcAddress in order to get the
281 // DirectDrawEnumerateEx function
282 hDDrawDLL = GetModuleHandle("DDRAW");
285 InitFail("LoadLibrary() FAILED");
288 pDirectDrawEnumerateEx = (LPDIRECTDRAWENUMERATEEX )GetProcAddress(hDDrawDLL,"DirectDrawEnumerateExA");
289 if (pDirectDrawEnumerateEx)
291 pDirectDrawEnumerateEx(DDEnumCallbackEx, NULL,
292 DDENUM_ATTACHEDSECONDARYDEVICES |
293 DDENUM_DETACHEDSECONDARYDEVICES |
294 DDENUM_NONDISPLAYDEVICES);
298 // Old DirectDraw, so do it the old way
299 DirectDrawEnumerate(DDEnumCallback, NULL);
302 if (0 == g_iMaxDevices)
304 InitFail("No devices to enumerate.");
308 // Bring up the dialog to show all the devices
309 DialogBox(hInstance, MAKEINTRESOURCE(IDD_DRIVERINFO), GetDesktopWindow(), (DLGPROC) InfoDlgProc);