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.

312 lines
11 KiB

  1. // Created 04-Jan-1993 1:10pm by Jeff Parsons
  2. #include "shellprv.h"
  3. #pragma hdrstop
  4. #ifdef _X86_
  5. BINF abinfMem[] = {
  6. {IDC_HMA, BITNUM(MEMINIT_NOHMA) | 0x80},
  7. {IDC_GLOBALPROTECT, BITNUM(MEMINIT_GLOBALPROTECT) },
  8. };
  9. VINF avinfMem[] = {
  10. {FIELD_OFFSET(PROPMEM,wMinLow), VINF_AUTOMINMAX, IDC_LOWMEM, MEMLOW_MIN, MEMLOW_MAX, IDS_BAD_MEMLOW},
  11. {FIELD_OFFSET(PROPMEM,wMinEMS), VINF_AUTOMINMAX, IDC_EMSMEM, MEMEMS_MIN, MEMEMS_MAX, IDS_BAD_MEMEMS},
  12. {FIELD_OFFSET(PROPMEM,wMinXMS), VINF_AUTOMINMAX, IDC_XMSMEM, MEMXMS_MIN, MEMXMS_MAX, IDS_BAD_MEMXMS},
  13. };
  14. VINF avinfEnvMem[] = {
  15. {FIELD_OFFSET(PROPENV,cbEnvironment), VINF_AUTO, IDC_ENVMEM, ENVSIZE_MIN, ENVSIZE_MAX, IDS_BAD_ENVIRONMENT},
  16. {FIELD_OFFSET(PROPENV,wMaxDPMI), VINF_AUTO, IDC_DPMIMEM, ENVDPMI_MIN, ENVDPMI_MAX, IDS_BAD_MEMDPMI},
  17. };
  18. // Per-dialog data
  19. #define MEMINFO_RELAUNCH 0x0001 // relaunch required to take effect
  20. #define EMS_NOEMS 0x0001 // EMS no supported in protmode
  21. #define EMS_EMM386 0x0002 // EM386 is installed
  22. #define EMS_QEMM 0x0004 // Third-party mmgr installed
  23. #define EMS_RMPAGEFRAME 0x0008 // Page frame present in real mode
  24. #define EMS_SYSINIDISABLE 0x0010 // EMS forced off by system.ini
  25. typedef struct MEMINFO { /* mi */
  26. PPROPLINK ppl; // pointer to property info
  27. DWORD flMemInfo; // initially zero thx to LocalAlloc(LPTR)
  28. DWORD flEms; // EMS support flags
  29. } MEMINFO;
  30. typedef MEMINFO *PMEMINFO; /* pmi */
  31. // Private function prototypes
  32. BOOL GetSetMemProps(HWND hDlg, GETSETFN lpfn, PPROPLINK ppl, LPPROPMEM lpmem, LPPROPENV lpenv, int idError);
  33. void InitMemDlg(HWND hDlg, PMEMINFO pmi);
  34. void ApplyMemDlg(HWND hDlg, PMEMINFO pmi);
  35. void AdjustEmsControls(HWND hDlg, PMEMINFO pmi);
  36. void ExplainNoEms(HWND hDlg, PMEMINFO pmi);
  37. // Context-sensitive help ids
  38. const static DWORD rgdwHelp[] = {
  39. IDC_CONVMEMLBL, IDH_DOS_MEMORY_CONV,
  40. IDC_LOWMEM, IDH_DOS_MEMORY_CONV,
  41. IDC_GLOBALPROTECT, IDH_DOS_MEMORY_CONV_GLOBAL,
  42. IDC_EXPMEMGRP, IDH_COMM_GROUPBOX,
  43. IDC_EXPMEMLBL, IDH_DOS_MEMORY_EXP,
  44. IDC_EMSMEM, IDH_DOS_MEMORY_EXP,
  45. IDC_EXTMEMGRP, IDH_COMM_GROUPBOX,
  46. IDC_XMSMEM, IDH_DOS_MEMORY_EXT,
  47. IDC_EXTMEMLBL, IDH_DOS_MEMORY_EXT,
  48. IDC_DPMIMEMGRP, IDH_COMM_GROUPBOX,
  49. IDC_DPMIMEM, IDH_DOS_MEMORY_DPMI,
  50. IDC_DPMIMEMLBL, IDH_DOS_MEMORY_DPMI,
  51. IDC_HMA, IDH_DOS_MEMORY_EXT_HMA,
  52. IDC_CONVMEMGRP, IDH_COMM_GROUPBOX,
  53. IDC_LOCALENVLBL, IDH_DOS_PROGRAM_ENVIRSZ,
  54. IDC_ENVMEM, IDH_DOS_PROGRAM_ENVIRSZ,
  55. IDC_REALMODEDISABLE, IDH_DOS_REALMODEPROPS,
  56. IDC_NOEMSDETAILS, IDH_DOS_MEMORY_NOEMS_DETAILS,
  57. 0, 0
  58. };
  59. BOOL_PTR CALLBACK DlgMemProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  60. {
  61. BOOL fError;
  62. PMEMINFO pmi;
  63. FunctionName(DlgMemProc);
  64. pmi = (PMEMINFO)GetWindowLongPtr(hDlg, DWLP_USER);
  65. switch (uMsg) {
  66. case WM_INITDIALOG:
  67. // allocate dialog instance data
  68. if (NULL != (pmi = (PMEMINFO)LocalAlloc(LPTR, SIZEOF(MEMINFO)))) {
  69. pmi->ppl = (PPROPLINK)((LPPROPSHEETPAGE)lParam)->lParam;
  70. SetWindowLongPtr(hDlg, DWLP_USER, (LPARAM)pmi);
  71. InitMemDlg(hDlg, pmi);
  72. } else {
  73. EndDialog(hDlg, FALSE); // fail the dialog create
  74. }
  75. break;
  76. case WM_DESTROY:
  77. // free the pmi
  78. if (pmi) {
  79. EVAL(LocalFree(pmi) == NULL);
  80. SetWindowLongPtr(hDlg, DWLP_USER, 0);
  81. }
  82. break;
  83. HELP_CASES(rgdwHelp) // Handle help messages
  84. case WM_COMMAND:
  85. if (LOWORD(lParam) == 0)
  86. break; // message not from a control
  87. switch (LOWORD(wParam)) {
  88. case IDC_ENVMEM:
  89. case IDC_LOWMEM:
  90. case IDC_EMSMEM:
  91. case IDC_XMSMEM:
  92. case IDC_DPMIMEM:
  93. if (HIWORD(wParam) == CBN_SELCHANGE ||
  94. HIWORD(wParam) == CBN_EDITCHANGE) {
  95. SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0L);
  96. pmi->flMemInfo |= MEMINFO_RELAUNCH;
  97. }
  98. break;
  99. case IDC_HMA:
  100. case IDC_GLOBALPROTECT:
  101. if (HIWORD(wParam) == BN_CLICKED) {
  102. SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0L);
  103. if (LOWORD(wParam) != IDC_GLOBALPROTECT)
  104. pmi->flMemInfo |= MEMINFO_RELAUNCH;
  105. }
  106. break;
  107. case IDC_NOEMSDETAILS:
  108. if (HIWORD(wParam) == BN_CLICKED) {
  109. ExplainNoEms(hDlg, pmi);
  110. }
  111. return FALSE; // return 0 if we process WM_COMMAND
  112. }
  113. break;
  114. case WM_NOTIFY:
  115. switch (((NMHDR *)lParam)->code) {
  116. case PSN_SETACTIVE:
  117. AdjustRealModeControls(pmi->ppl, hDlg);
  118. AdjustEmsControls(hDlg, pmi);
  119. // make sure DWL_MSGRESULT is zero,
  120. // otherwise the prsht code thinks we
  121. // "failed" this notify and switches
  122. // to another (sometimes random) page -JTP
  123. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, 0);
  124. break;
  125. case PSN_KILLACTIVE:
  126. // This gives the current page a chance to validate itself
  127. fError = ValidateDlgInts(hDlg, avinfMem, ARRAYSIZE(avinfMem));
  128. fError |= ValidateDlgInts(hDlg, avinfEnvMem, ARRAYSIZE(avinfEnvMem));
  129. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, fError);
  130. break;
  131. case PSN_APPLY:
  132. // This happens on OK....
  133. ApplyMemDlg(hDlg, pmi);
  134. break;
  135. case PSN_RESET:
  136. // This happens on Cancel....
  137. break;
  138. }
  139. break;
  140. default:
  141. return FALSE; // return 0 when not processing
  142. }
  143. return TRUE;
  144. }
  145. BOOL GetSetMemProps(HWND hDlg, GETSETFN lpfn, PPROPLINK ppl, LPPROPMEM lpmem, LPPROPENV lpenv, int idError)
  146. {
  147. if (!(*lpfn)(ppl, MAKELP(0,GROUP_MEM),
  148. lpmem, SIZEOF(*lpmem), GETPROPS_NONE) ||
  149. !(*lpfn)(ppl, MAKELP(0,GROUP_ENV),
  150. lpenv, SIZEOF(*lpenv), GETPROPS_NONE)) {
  151. Warning(hDlg, (WORD)idError, (WORD)MB_ICONEXCLAMATION | MB_OK);
  152. return FALSE;
  153. }
  154. return TRUE;
  155. }
  156. void InitMemDlg(HWND hDlg, PMEMINFO pmi)
  157. {
  158. PROPMEM mem;
  159. PROPENV env;
  160. PPROPLINK ppl = pmi->ppl;
  161. FunctionName(InitMemDlg);
  162. if (!GetSetMemProps(hDlg, PifMgr_GetProperties, ppl, &mem, &env, IDS_QUERY_ERROR))
  163. return;
  164. SetDlgBits(hDlg, abinfMem, ARRAYSIZE(abinfMem), mem.flMemInit);
  165. SetDlgInts(hDlg, avinfMem, ARRAYSIZE(avinfMem), (LPVOID)&mem);
  166. SetDlgInts(hDlg, avinfEnvMem, ARRAYSIZE(avinfEnvMem), (LPVOID)&env);
  167. /* Disallow "None" as a valid setting for "Conventional memory" */
  168. SendDlgItemMessage(hDlg, IDC_LOWMEM, CB_DELETESTRING,
  169. (WPARAM)SendDlgItemMessage(hDlg, IDC_LOWMEM, CB_FINDSTRING,
  170. (WPARAM)-1, (LPARAM)(LPTSTR)g_szNone), 0L);
  171. pmi->flEms = (EMS_EMM386 | EMS_RMPAGEFRAME);
  172. AdjustEmsControls(hDlg, pmi);
  173. }
  174. void ApplyMemDlg(HWND hDlg, PMEMINFO pmi)
  175. {
  176. PROPMEM mem;
  177. PROPENV env;
  178. PPROPLINK ppl = pmi->ppl;
  179. FunctionName(ApplyMemDlg);
  180. if (!GetSetMemProps(hDlg, PifMgr_GetProperties, ppl, &mem, &env, IDS_UPDATE_ERROR))
  181. return;
  182. GetDlgBits(hDlg, abinfMem, ARRAYSIZE(abinfMem), &mem.flMemInit);
  183. GetDlgInts(hDlg, avinfMem, ARRAYSIZE(avinfMem), (LPVOID)&mem);
  184. GetDlgInts(hDlg, avinfEnvMem, ARRAYSIZE(avinfEnvMem), (LPVOID)&env);
  185. if (GetSetMemProps(hDlg, PifMgr_SetProperties, ppl, &mem, &env, IDS_UPDATE_ERROR)) {
  186. if (ppl->hwndNotify) {
  187. ppl->flProp |= PROP_NOTIFY;
  188. PostMessage(ppl->hwndNotify, ppl->uMsgNotify, SIZEOF(mem), (LPARAM)MAKELP(0,GROUP_MEM));
  189. PostMessage(ppl->hwndNotify, ppl->uMsgNotify, SIZEOF(env), (LPARAM)MAKELP(0,GROUP_ENV));
  190. }
  191. if (ppl->hVM && (pmi->flMemInfo & MEMINFO_RELAUNCH)) {
  192. pmi->flMemInfo &= ~MEMINFO_RELAUNCH;
  193. Warning(hDlg, IDS_MEMORY_RELAUNCH, MB_ICONWARNING | MB_OK);
  194. }
  195. }
  196. }
  197. void HideAndDisable(HWND hwnd)
  198. {
  199. ShowWindow(hwnd, SW_HIDE);
  200. EnableWindow(hwnd, FALSE);
  201. }
  202. void AdjustEmsControls(HWND hDlg, PMEMINFO pmi)
  203. {
  204. if (!(pmi->ppl->flProp & PROP_REALMODE)) {
  205. /*
  206. * When not marked as PROP_REALMODE, all the EMS-related controls
  207. * are visible. We need to choose which set to disable.
  208. *
  209. * We cheat, because we know that there are only two controls
  210. * in both cases, and they come right after each other.
  211. */
  212. UINT uiHide;
  213. if (pmi->flEms & EMS_NOEMS) {
  214. uiHide = IDC_EXPMEMLBL;
  215. CTASSERTF(IDC_EXPMEMLBL + 1 == IDC_EMSMEM);
  216. } else {
  217. uiHide = IDC_NOEMS;
  218. CTASSERTF(IDC_NOEMS + 1 == IDC_NOEMSDETAILS);
  219. }
  220. HideAndDisable(GetDlgItem(hDlg, uiHide));
  221. HideAndDisable(GetDlgItem(hDlg, uiHide+1));
  222. }
  223. }
  224. void ExplainNoEms(HWND hDlg, PMEMINFO pmi)
  225. {
  226. WORD idsHelp;
  227. TCHAR szMsg[MAX_STRING_SIZE];
  228. /*
  229. * Here is where we stare at all the bits to try to figure
  230. * out what recommendation to make.
  231. */
  232. ASSERTTRUE(pmi->flEms & EMS_NOEMS);
  233. if (pmi->flEms & EMS_SYSINIDISABLE) {
  234. /*
  235. * System.ini contains the line NOEMMDRIVER=1.
  236. */
  237. idsHelp = IDS_SYSINI_NOEMS;
  238. } else if (pmi->flEms & EMS_RMPAGEFRAME) {
  239. /*
  240. * Had page-frame in real mode, which means that some protmode
  241. * guy must've messed it up.
  242. */
  243. idsHelp = IDS_RING0_NOEMS;
  244. } else if (pmi->flEms & EMS_EMM386) {
  245. /*
  246. * No page-frame in real mode, and EMM386 was in charge,
  247. * so it's EMM386's fault.
  248. */
  249. idsHelp = IDS_EMM386_NOEMS;
  250. } else {
  251. /*
  252. * No page-frame in real mode, and QEMM was in charge,
  253. * so it's QEMM's fault.
  254. */
  255. idsHelp = IDS_QEMM_NOEMS;
  256. }
  257. if (LoadStringSafe(hDlg, idsHelp+1, szMsg, ARRAYSIZE(szMsg))) {
  258. Warning(hDlg, idsHelp, MB_OK, (LPCTSTR)szMsg);
  259. }
  260. }
  261. #endif