Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

599 lines
17 KiB

  1. /******************************************************************************
  2. Source File: deskadp.cpp
  3. Main code for the advanced desktop adapter page
  4. Copyright (c) 1997-1998 by Microsoft Corporation
  5. Change History:
  6. 12-16-97 AndreVa - Created It
  7. ******************************************************************************/
  8. #include "deskadp.h"
  9. #define DECL_CRTFREE
  10. #include <crtfree.h>
  11. #include "shfusion.h"
  12. //
  13. // The function DevicePropertiesW() is implemented in DevMgr.dll; Since we don't have a devmgr.h, we
  14. // explicitly declare it here.
  15. //
  16. typedef int (WINAPI *DEVPROPERTIESW)(
  17. HWND hwndParent,
  18. LPCTSTR MachineName,
  19. LPCTSTR DeviceID,
  20. BOOL ShowDeviceTree
  21. );
  22. // OLE-Registry magic number
  23. // 42071712-76d4-11d1-8b24-00a0c9068ff3
  24. //
  25. GUID g_CLSID_CplExt = { 0x42071712, 0x76d4, 0x11d1,
  26. { 0x8b, 0x24, 0x00, 0xa0, 0xc9, 0x06, 0x8f, 0xf3 }
  27. };
  28. DESK_EXTENSION_INTERFACE DeskInterface;
  29. static const DWORD sc_AdapterHelpIds[] =
  30. {
  31. ID_ADP_ADPINFGRP, IDH_DISPLAY_SETTINGS_ADVANCED_ADAPTER_ADAPTER_INFO,
  32. ID_ADP_AI1, IDH_DISPLAY_SETTINGS_ADVANCED_ADAPTER_ADAPTER_INFO,
  33. ID_ADP_AI2, IDH_DISPLAY_SETTINGS_ADVANCED_ADAPTER_ADAPTER_INFO,
  34. ID_ADP_AI3, IDH_DISPLAY_SETTINGS_ADVANCED_ADAPTER_ADAPTER_INFO,
  35. ID_ADP_AI4, IDH_DISPLAY_SETTINGS_ADVANCED_ADAPTER_ADAPTER_INFO,
  36. ID_ADP_AI5, IDH_DISPLAY_SETTINGS_ADVANCED_ADAPTER_ADAPTER_INFO,
  37. ID_ADP_CHIP, IDH_DISPLAY_SETTINGS_ADVANCED_ADAPTER_ADAPTER_INFO,
  38. ID_ADP_DAC, IDH_DISPLAY_SETTINGS_ADVANCED_ADAPTER_ADAPTER_INFO,
  39. ID_ADP_MEM, IDH_DISPLAY_SETTINGS_ADVANCED_ADAPTER_ADAPTER_INFO,
  40. ID_ADP_ADP_STRING, IDH_DISPLAY_SETTINGS_ADVANCED_ADAPTER_ADAPTER_INFO,
  41. ID_ADP_BIOS_INFO, IDH_DISPLAY_SETTINGS_ADVANCED_ADAPTER_ADAPTER_INFO,
  42. ID_ADP_ADPGRP, IDH_DISPLAY_SETTINGS_ADVANCED_ADAPTER_ADAPTER_TYPE,
  43. IDI_ADAPTER, IDH_DISPLAY_SETTINGS_ADVANCED_ADAPTER_ADAPTER_TYPE,
  44. ID_ADP_ADAPTOR, IDH_DISPLAY_SETTINGS_ADVANCED_ADAPTER_ADAPTER_TYPE,
  45. IDC_LIST_ALL, IDH_DISPLAY_SETTINGS_ADVANCED_ADAPTER_LIST_MODES,
  46. IDC_PROPERTIES, IDH_DISPLAY_SETTINGS_ADVANCED_ADAPTER_PROPERTIES,
  47. 0, 0
  48. };
  49. static const DWORD sc_ListAllHelpIds[] =
  50. {
  51. ID_MODE_LIST, IDH_DISPLAY_SETTINGS_ADVANCED_ADAPTER_LISTMODE_DIALOGBOX,
  52. ID_MODE_LISTGRP, IDH_DISPLAY_SETTINGS_ADVANCED_ADAPTER_LISTMODE_DIALOGBOX,
  53. 0, 0
  54. };
  55. ///////////////////////////////////////////////////////////////////////////////
  56. //
  57. // Messagebox wrapper
  58. //
  59. ///////////////////////////////////////////////////////////////////////////////
  60. int
  61. FmtMessageBox(
  62. HWND hwnd,
  63. UINT fuStyle,
  64. DWORD dwTitleID,
  65. DWORD dwTextID)
  66. {
  67. TCHAR Title[256];
  68. TCHAR Text[1500];
  69. LoadString(g_hInst, dwTextID, Text, ARRAYSIZE(Text));
  70. LoadString(g_hInst, dwTitleID, Title, ARRAYSIZE(Title));
  71. return (MessageBox(hwnd, Text, Title, fuStyle));
  72. }
  73. ///////////////////////////////////////////////////////////////////////////////
  74. //
  75. // Main dialog box Windows Proc
  76. //
  77. ///////////////////////////////////////////////////////////////////////////////
  78. INT_PTR
  79. CALLBACK
  80. ListAllModesProc(
  81. HWND hDlg,
  82. UINT uMessage,
  83. WPARAM wParam,
  84. LPARAM lParam
  85. )
  86. {
  87. LPDEVMODEW lpdm, lpdmCur;
  88. HWND hList;
  89. DWORD i;
  90. LRESULT item;
  91. switch (uMessage)
  92. {
  93. case WM_INITDIALOG:
  94. //
  95. // Save the lParam - we will store the new mode here
  96. //
  97. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  98. lpdmCur = *((LPDEVMODEW *)lParam);
  99. Assert (lpdmCur != NULL);
  100. //
  101. // Build the list of modes to display
  102. //
  103. i = 0;
  104. hList = GetDlgItem(hDlg, ID_MODE_LIST);
  105. while (lpdm = DeskInterface.lpfnEnumAllModes(DeskInterface.pContext, i))
  106. {
  107. TCHAR achFreData[50];
  108. TCHAR achFre[50];
  109. TCHAR achStr[80];
  110. TCHAR achText[120];
  111. DWORD idColor;
  112. DWORD idFreq;
  113. //
  114. // convert bit count to number of colors and make it a string
  115. //
  116. switch (lpdm->dmBitsPerPel)
  117. {
  118. case 32: idColor = IDS_MODE_TRUECOLOR32; break;
  119. case 24: idColor = IDS_MODE_TRUECOLOR24; break;
  120. case 16: idColor = IDS_MODE_16BIT_COLOR; break;
  121. case 15: idColor = IDS_MODE_15BIT_COLOR; break;
  122. case 8: idColor = IDS_MODE_8BIT_COLOR; break;
  123. case 4: idColor = IDS_MODE_4BIT_COLOR; break;
  124. default:
  125. FmtMessageBox(hDlg,
  126. MB_OK | MB_ICONINFORMATION,
  127. IDS_BAD_COLOR,
  128. IDS_BAD_COLOR);
  129. EndDialog(hDlg, -1);
  130. break;
  131. }
  132. if (lpdm->dmDisplayFrequency == 0)
  133. {
  134. FmtMessageBox(hDlg,
  135. MB_OK | MB_ICONINFORMATION,
  136. IDS_BAD_REFRESH,
  137. IDS_BAD_REFRESH);
  138. EndDialog(hDlg, -1);
  139. break;
  140. }
  141. else if (lpdm->dmDisplayFrequency == 1)
  142. {
  143. LoadString(g_hInst, IDS_MODE_REFRESH_DEF, achFre, ARRAYSIZE(achFre));
  144. }
  145. else
  146. {
  147. if (lpdm->dmDisplayFrequency <= 50)
  148. idFreq = IDS_MODE_REFRESH_INT;
  149. else
  150. idFreq = IDS_MODE_REFRESH_HZ;
  151. LoadString(g_hInst, idFreq, achFreData, ARRAYSIZE(achFreData));
  152. StringCchPrintf(achFre, ARRAYSIZE(achFre), achFreData, lpdm->dmDisplayFrequency);
  153. }
  154. LoadString(g_hInst, idColor, achStr, ARRAYSIZE(achStr));
  155. StringCchPrintf(achText, ARRAYSIZE(achText), achStr, lpdm->dmPelsWidth, lpdm->dmPelsHeight, achFre);
  156. item = ListBox_AddString(hList, achText);
  157. if (lpdm == lpdmCur)
  158. ListBox_SetCurSel(hList, item);
  159. ListBox_SetItemData(hList, item, lpdm);
  160. i++;
  161. }
  162. //
  163. // If no modes are available, put up a popup and exit.
  164. //
  165. if (i == 0)
  166. {
  167. EndDialog(hDlg, -1);
  168. }
  169. break;
  170. case WM_COMMAND:
  171. switch (LOWORD(wParam))
  172. {
  173. case ID_MODE_LIST:
  174. if (HIWORD(wParam) != LBN_DBLCLK)
  175. {
  176. return FALSE;
  177. }
  178. //
  179. // fall through, as DBLCLK means select.
  180. //
  181. case IDOK:
  182. //
  183. // Save the mode back
  184. //
  185. item = SendDlgItemMessage(hDlg, ID_MODE_LIST, LB_GETCURSEL, 0, 0);
  186. if ((item != LB_ERR) &&
  187. (lpdm = (LPDEVMODEW) SendDlgItemMessage(hDlg, ID_MODE_LIST, LB_GETITEMDATA, item, 0)))
  188. {
  189. *((LPDEVMODEW *)GetWindowLongPtr(hDlg, DWLP_USER)) = lpdm;
  190. EndDialog(hDlg, TRUE);
  191. break;
  192. }
  193. //
  194. // fall through
  195. //
  196. case IDCANCEL:
  197. EndDialog(hDlg, FALSE);
  198. break;
  199. default:
  200. return FALSE;
  201. }
  202. break;
  203. case WM_HELP:
  204. WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  205. TEXT("display.hlp"),
  206. HELP_WM_HELP,
  207. (DWORD_PTR)(LPTSTR)sc_ListAllHelpIds);
  208. break;
  209. case WM_CONTEXTMENU:
  210. WinHelp((HWND)wParam,
  211. TEXT("display.hlp"),
  212. HELP_CONTEXTMENU,
  213. (DWORD_PTR)(LPTSTR)sc_ListAllHelpIds);
  214. break;
  215. default:
  216. return FALSE;
  217. }
  218. return TRUE;
  219. }
  220. void Adaptor_OnApply(HWND hDlg)
  221. {
  222. HINSTANCE hInst;
  223. LPDISPLAY_SAVE_SETTINGS lpfnDisplaySaveSettings = NULL;
  224. long lRet = PSNRET_INVALID_NOCHANGEPAGE;
  225. hInst = LoadLibrary(TEXT("desk.cpl"));
  226. if (hInst)
  227. {
  228. lpfnDisplaySaveSettings = (LPDISPLAY_SAVE_SETTINGS)
  229. GetProcAddress(hInst, "DisplaySaveSettings");
  230. if (lpfnDisplaySaveSettings)
  231. {
  232. LONG lSave = lpfnDisplaySaveSettings(DeskInterface.pContext, hDlg);
  233. if (lSave == DISP_CHANGE_SUCCESSFUL)
  234. {
  235. //
  236. // Save the current mode - to restore it in case the user cancels the p. sheet
  237. //
  238. LPDEVMODEW lpdmOnCancel = DeskInterface.lpfnGetSelectedMode(DeskInterface.pContext);
  239. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)lpdmOnCancel);
  240. lRet = PSNRET_NOERROR;
  241. }
  242. else if (lSave == DISP_CHANGE_RESTART)
  243. {
  244. //
  245. // User wants to reboot system.
  246. //
  247. PropSheet_RestartWindows(GetParent(hDlg));
  248. lRet = PSNRET_NOERROR;
  249. }
  250. }
  251. FreeLibrary(hInst);
  252. }
  253. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, lRet);
  254. }
  255. void Adaptor_OnInitDialog(HWND hDlg)
  256. {
  257. Assert (DeskInterface.cbSize == 0);
  258. //
  259. // Get the CPL extension interfaces from IDataObject.
  260. //
  261. FORMATETC fmte = {(CLIPFORMAT)RegisterClipboardFormat(DESKCPLEXT_INTERFACE),
  262. (DVTARGETDEVICE FAR *) NULL,
  263. DVASPECT_CONTENT,
  264. -1,
  265. TYMED_HGLOBAL};
  266. STGMEDIUM stgm;
  267. HRESULT hres = g_lpdoTarget->GetData(&fmte, &stgm);
  268. if (SUCCEEDED(hres) && stgm.hGlobal)
  269. {
  270. //
  271. // The storage now contains Display device path (\\.\DisplayX) in UNICODE.
  272. //
  273. PDESK_EXTENSION_INTERFACE pInterface =
  274. (PDESK_EXTENSION_INTERFACE) GlobalLock(stgm.hGlobal);
  275. if (pInterface != NULL)
  276. {
  277. RtlCopyMemory(&DeskInterface,
  278. pInterface,
  279. min(pInterface->cbSize,
  280. sizeof(DESK_EXTENSION_INTERFACE)));
  281. GlobalUnlock(stgm.hGlobal);
  282. SendDlgItemMessageW(hDlg, ID_ADP_CHIP, WM_SETTEXT, 0, (LPARAM)&(DeskInterface.Info.ChipType[0]));
  283. SendDlgItemMessageW(hDlg, ID_ADP_DAC, WM_SETTEXT, 0, (LPARAM)&(DeskInterface.Info.DACType[0]));
  284. SendDlgItemMessageW(hDlg, ID_ADP_MEM, WM_SETTEXT, 0, (LPARAM)&(DeskInterface.Info.MemSize[0]));
  285. SendDlgItemMessageW(hDlg, ID_ADP_ADP_STRING, WM_SETTEXT, 0, (LPARAM)&(DeskInterface.Info.AdapString[0]));
  286. SendDlgItemMessageW(hDlg, ID_ADP_BIOS_INFO, WM_SETTEXT, 0, (LPARAM)&(DeskInterface.Info.BiosString[0]));
  287. //
  288. // Save the initial selected mode - to restore it in case the user cancels the p. sheet
  289. //
  290. LPDEVMODEW lpdmOnCancel = DeskInterface.lpfnGetSelectedMode(DeskInterface.pContext);
  291. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)lpdmOnCancel);
  292. }
  293. ReleaseStgMedium(&stgm);
  294. }
  295. //
  296. // Get device description from IDataObject.
  297. //
  298. LPWSTR pDeviceDescription;
  299. FORMATETC fmte2 = {(CLIPFORMAT)RegisterClipboardFormat(DESKCPLEXT_DISPLAY_NAME),
  300. (DVTARGETDEVICE FAR *) NULL,
  301. DVASPECT_CONTENT,
  302. -1,
  303. TYMED_HGLOBAL};
  304. hres = g_lpdoTarget->GetData(&fmte2, &stgm);
  305. if (SUCCEEDED(hres) && stgm.hGlobal)
  306. {
  307. pDeviceDescription = (LPWSTR) GlobalLock(stgm.hGlobal);
  308. SendDlgItemMessageW(hDlg, ID_ADP_ADAPTOR, WM_SETTEXT, 0, (LPARAM)pDeviceDescription);
  309. GlobalUnlock(stgm.hGlobal);
  310. ReleaseStgMedium(&stgm);
  311. }
  312. //
  313. // Enable/disable the properties button
  314. //
  315. BOOL bEnable = FALSE;
  316. LPWSTR pwDeviceID = NULL;
  317. FORMATETC fmte3 = {(CLIPFORMAT)RegisterClipboardFormat(DESKCPLEXT_DISPLAY_ID),
  318. (DVTARGETDEVICE FAR *)NULL,
  319. DVASPECT_CONTENT,
  320. -1,
  321. TYMED_HGLOBAL};
  322. hres = g_lpdoTarget->GetData(&fmte3, &stgm);
  323. if (SUCCEEDED(hres) && stgm.hGlobal)
  324. {
  325. pwDeviceID = (LPWSTR)GlobalLock(stgm.hGlobal);
  326. bEnable = ((pwDeviceID != NULL) && (*pwDeviceID != L'\0'));
  327. GlobalUnlock(stgm.hGlobal);
  328. ReleaseStgMedium(&stgm);
  329. }
  330. HWND hPropButton = GetDlgItem(hDlg, IDC_PROPERTIES);
  331. if (hPropButton != NULL)
  332. EnableWindow(hPropButton, bEnable);
  333. }
  334. void Adaptor_OnCancel(HWND hDlg)
  335. {
  336. //
  337. // Restore initial mode
  338. //
  339. LPDEVMODEW lpdmOnCancel = (LPDEVMODEW) GetWindowLongPtr(hDlg, DWLP_USER);
  340. DeskInterface.lpfnSetSelectedMode(DeskInterface.pContext, lpdmOnCancel);
  341. }
  342. void Adaptor_OnListAllModes(HWND hDlg)
  343. {
  344. LPDEVMODEW lpdmBefore, lpdmAfter;
  345. lpdmAfter = lpdmBefore = DeskInterface.lpfnGetSelectedMode(DeskInterface.pContext);
  346. if (DialogBoxParam(g_hInst,
  347. MAKEINTRESOURCE(DLG_SET_MODE_LIST),
  348. hDlg,
  349. ListAllModesProc,
  350. (LPARAM) &lpdmAfter) == 1 &&
  351. lpdmAfter && (lpdmAfter != lpdmBefore))
  352. {
  353. //
  354. // If the user selected a new setting, tell the property sheet
  355. // we have outstanding changes. This will enable the Apply button.
  356. //
  357. PropSheet_Changed(GetParent(hDlg), hDlg);
  358. DeskInterface.lpfnSetSelectedMode(DeskInterface.pContext, lpdmAfter);
  359. }
  360. }
  361. void Adaptor_OnProperties(HWND hDlg)
  362. {
  363. // Invoke the device manager property sheets to show the properties of the
  364. // given hardware.
  365. LPWSTR pwDeviceID;
  366. HRESULT hres;
  367. STGMEDIUM stgm;
  368. FORMATETC fmte2 = {(CLIPFORMAT)RegisterClipboardFormat(DESKCPLEXT_DISPLAY_ID),
  369. (DVTARGETDEVICE FAR *) NULL,
  370. DVASPECT_CONTENT,
  371. -1,
  372. TYMED_HGLOBAL};
  373. hres = g_lpdoTarget->GetData(&fmte2, &stgm);
  374. if (SUCCEEDED(hres) && stgm.hGlobal)
  375. {
  376. pwDeviceID = (LPWSTR) GlobalLock(stgm.hGlobal);
  377. HINSTANCE hinstDevMgr = LoadLibrary(TEXT("DEVMGR.DLL"));
  378. if (hinstDevMgr)
  379. {
  380. DEVPROPERTIESW pfnDevPropW =
  381. (DEVPROPERTIESW)GetProcAddress(hinstDevMgr, "DevicePropertiesW");
  382. if (pfnDevPropW)
  383. {
  384. //Display the property sheets for this device.
  385. (*pfnDevPropW)(hDlg, NULL, pwDeviceID, FALSE);
  386. }
  387. FreeLibrary(hinstDevMgr);
  388. }
  389. GlobalUnlock(stgm.hGlobal);
  390. ReleaseStgMedium(&stgm);
  391. }
  392. }
  393. //---------------------------------------------------------------------------
  394. //
  395. // PropertySheeDlgProc()
  396. //
  397. // The dialog procedure for the "Adapter" property sheet page.
  398. //
  399. //---------------------------------------------------------------------------
  400. INT_PTR
  401. CALLBACK
  402. PropertySheeDlgProc(
  403. HWND hDlg,
  404. UINT uMessage,
  405. WPARAM wParam,
  406. LPARAM lParam
  407. )
  408. {
  409. switch (uMessage)
  410. {
  411. case WM_INITDIALOG:
  412. RtlZeroMemory(&DeskInterface, sizeof(DeskInterface));
  413. if (!g_lpdoTarget)
  414. {
  415. return FALSE;
  416. }
  417. else
  418. {
  419. Adaptor_OnInitDialog(hDlg);
  420. }
  421. break;
  422. case WM_COMMAND:
  423. if (DeskInterface.cbSize > 0)
  424. {
  425. switch( LOWORD(wParam) )
  426. {
  427. case IDC_LIST_ALL:
  428. Adaptor_OnListAllModes(hDlg);
  429. break;
  430. case IDC_PROPERTIES:
  431. Adaptor_OnProperties(hDlg);
  432. break;
  433. default:
  434. return FALSE;
  435. }
  436. }
  437. break;
  438. case WM_NOTIFY:
  439. if (DeskInterface.cbSize > 0)
  440. {
  441. switch (((NMHDR FAR *)lParam)->code)
  442. {
  443. case PSN_APPLY:
  444. Adaptor_OnApply(hDlg);
  445. break;
  446. case PSN_RESET:
  447. Adaptor_OnCancel(hDlg);
  448. break;
  449. default:
  450. return FALSE;
  451. }
  452. }
  453. break;
  454. case WM_HELP:
  455. WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
  456. TEXT("display.hlp"),
  457. HELP_WM_HELP,
  458. (DWORD_PTR)(LPTSTR)sc_AdapterHelpIds);
  459. break;
  460. case WM_CONTEXTMENU:
  461. WinHelp((HWND)wParam,
  462. TEXT("display.hlp"),
  463. HELP_CONTEXTMENU,
  464. (DWORD_PTR)(LPTSTR)sc_AdapterHelpIds);
  465. break;
  466. default:
  467. return FALSE;
  468. }
  469. return TRUE;
  470. }