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.

523 lines
14 KiB

  1. #define WIN31
  2. #include <windows.h>
  3. #include "RegEdit.h"
  4. HWND hWndNames, hWndIds;
  5. WORD fMode;
  6. extern char cUsesDDE[];
  7. extern HANDLE *pLocalVals;
  8. WORD NEAR PASCAL StoreValue(HWND hWndEdit, HANDLE *pValue)
  9. {
  10. HANDLE hTemp = NULL;
  11. if(!SendMessage(hWndEdit, EM_GETMODIFY, 0, 0L))
  12. return(0);
  13. SendMessage(hWndEdit, EM_SETMODIFY, 0, 0L);
  14. if(SendMessage(hWndEdit, WM_GETTEXTLENGTH, 0, 0L))
  15. if(!(hTemp=GetEditString(hWndEdit)))
  16. return(IDS_OUTOFMEMORY);
  17. if(*pValue)
  18. LocalFree(*pValue);
  19. *pValue = hTemp;
  20. return(NULL);
  21. }
  22. VOID NEAR PASCAL SetValue(HWND hDlg, int i, HWND hWndEdit, HANDLE hValue,
  23. BOOL bEnable)
  24. {
  25. if(bEnable) {
  26. if(i >= ID_FIRSTDDEEDIT)
  27. EnableWindow(GetWindow(hWndEdit, GW_HWNDPREV), TRUE);
  28. EnableWindow(hWndEdit, TRUE);
  29. if(hValue) {
  30. SendMessage(hWndEdit, WM_SETTEXT, 0, (LONG)(LPSTR)LocalLock(hValue));
  31. LocalUnlock(hValue);
  32. } else
  33. goto ClearEdit;
  34. } else {
  35. if(GetFocus() == hWndEdit)
  36. SendMessage(hDlg, WM_NEXTDLGCTL, GetDlgItem(hDlg, ID_CLASSID), 1L);
  37. EnableWindow(GetWindow(hWndEdit, GW_HWNDPREV), FALSE);
  38. EnableWindow(hWndEdit, FALSE);
  39. ClearEdit:
  40. SendMessage(hWndEdit, WM_SETTEXT, 0, (LONG)(LPSTR)"");
  41. }
  42. }
  43. int FAR PASCAL EditDlg(HWND hDlg, WORD message, WORD wParam, DWORD lParam)
  44. {
  45. static HANDLE hCustExes = NULL;
  46. switch(message) {
  47. case WM_ACTIVATE:
  48. if(wParam)
  49. hWndHelp = hDlg;
  50. return(FALSE);
  51. case WM_DESTROY:
  52. GetLocalCopies(GetDlgItem(hDlg, ID_CLASSNAME), NULL);
  53. break;
  54. case WM_COMMAND:
  55. switch(wParam) {
  56. case ID_SAVEACTION:
  57. wParam = IsDlgButtonChecked(hDlg, ID_OPENRADIO)
  58. ? ID_OPENRADIO : ID_PRINTRADIO;
  59. /* We fall through here */
  60. case ID_OPENRADIO:
  61. case ID_PRINTRADIO:
  62. {
  63. WORD wOld, wNew, wTemp, wErrMsg = NULL;
  64. BOOL bCheck;
  65. HWND hWndEdit;
  66. int i;
  67. wOld = (ID_LASTEDIT-ID_FIRSTACTIONEDIT+1) *
  68. (IsDlgButtonChecked(hDlg, ID_OPENRADIO) ? 0 : 1);
  69. wNew = wParam==ID_OPENRADIO ? 0 : 1;
  70. bCheck = cUsesDDE[wNew];
  71. wNew *= ID_LASTEDIT-ID_FIRSTACTIONEDIT+1;
  72. for(i=ID_FIRSTACTIONEDIT; i<=ID_LASTEDIT; ++i, ++wOld, ++wNew) {
  73. if(wTemp=StoreValue(hWndEdit=GetDlgItem(hDlg, i), pLocalVals+wOld))
  74. wErrMsg = wTemp;
  75. SetValue(hDlg, i, hWndEdit, pLocalVals[wNew], i<ID_FIRSTDDEEDIT ||
  76. (bCheck && (i!=(ID_FIRSTDDEEDIT+1) || SendDlgItemMessage(hDlg,
  77. ID_FIRSTDDEEDIT, WM_GETTEXTLENGTH, 0, 0L))));
  78. }
  79. CheckDlgButton(hDlg, ID_USESDDE, bCheck);
  80. EnableWindow(GetDlgItem(hDlg, ID_GROUPDDE), bCheck);
  81. CheckRadioButton(hDlg, ID_OPENRADIO, ID_PRINTRADIO, wParam);
  82. if(wErrMsg)
  83. MyMessageBox(hDlg, wErrMsg, MB_OK, 0);
  84. break;
  85. }
  86. case ID_USESDDE:
  87. {
  88. WORD wOld;
  89. wOld = IsDlgButtonChecked(hDlg, ID_OPENRADIO) ? 0 : 1;
  90. cUsesDDE[wOld] = (char)(!IsDlgButtonChecked(hDlg, ID_USESDDE));
  91. SendMessage(hDlg, WM_COMMAND, ID_SAVEACTION, 0L);
  92. break;
  93. }
  94. case ID_FIRSTDDEEDIT:
  95. if(HIWORD(lParam) == EN_CHANGE) {
  96. BOOL bCheck, bEnabled;
  97. HWND hWndEdit;
  98. WORD wNew;
  99. hWndEdit = GetDlgItem(hDlg, ID_FIRSTDDEEDIT+1);
  100. bEnabled = IsWindowEnabled(hWndEdit);
  101. bCheck = (BOOL)SendMessage(LOWORD(lParam), WM_GETTEXTLENGTH, 0, 0L);
  102. if((bCheck && bEnabled) || (!bCheck && !bEnabled))
  103. break;
  104. wNew = ID_FIRSTDDEEDIT+1-ID_FIRSTACTIONEDIT;
  105. if(!IsDlgButtonChecked(hDlg, ID_OPENRADIO))
  106. wNew += ID_LASTEDIT-ID_FIRSTACTIONEDIT+1;
  107. if(StoreValue(hWndEdit, pLocalVals+wNew))
  108. break;
  109. SetValue(hDlg, ID_FIRSTDDEEDIT+1, hWndEdit, pLocalVals[wNew],
  110. bCheck);
  111. }
  112. break;
  113. case IDOK:
  114. {
  115. HANDLE hId;
  116. HWND hWndName;
  117. WORD wErrMsg = IDS_INVALIDNAME;
  118. WORD wErrCtl = ID_CLASSNAME;
  119. if(!SendMessage(hWndName=GetDlgItem(hDlg, ID_CLASSNAME),
  120. WM_GETTEXTLENGTH, 0, 0L))
  121. goto Error1_1;
  122. wErrMsg = IDS_OUTOFMEMORY;
  123. wErrCtl = NULL;
  124. /* Update our memory handles for the current action */
  125. SendMessage(hDlg, WM_COMMAND, ID_SAVEACTION, 0L);
  126. /* Get the current class id */
  127. if(!(hId=GetEditString(GetDlgItem(hDlg, ID_CLASSID))))
  128. goto Error1_1;
  129. if((fMode&(FLAG_NEW|FLAG_COPY)) && (wErrMsg=CreateId(hId))) {
  130. PSTR pId;
  131. MyMessageBox(hDlg, wErrMsg, MB_OK, lstrlen(pId=LocalLock(hId)),
  132. (LPSTR)pId);
  133. SetFocus(GetDlgItem(hDlg, ID_CLASSID));
  134. LocalUnlock(hId);
  135. LocalFree(hId);
  136. break;
  137. }
  138. /* Merge the data with the given class */
  139. if(wErrMsg=MergeData(hWndName, hId))
  140. goto Error1_2;
  141. EndDialog(hDlg, hId);
  142. break;
  143. Error1_2:
  144. LocalFree(hId);
  145. Error1_1:
  146. MyMessageBox(hDlg, wErrMsg, MB_OK, 0);
  147. if(wErrCtl)
  148. SetFocus(GetDlgItem(hDlg, wErrCtl));
  149. break;
  150. }
  151. case IDCANCEL:
  152. EndDialog(hDlg, FALSE);
  153. break;
  154. case ID_BROWSE:
  155. {
  156. HANDLE hPath, hLocPath;
  157. LPSTR lpPath;
  158. HWND hWndEdit, hWndApp;
  159. wHelpId = IDW_OPENEXE;
  160. if(!DoFileOpenDlg(hDlg, IDS_BROWSETITLE, IDS_EXES, IDS_CUSTEXES,
  161. &hCustExes, &hPath, TRUE))
  162. break;
  163. lpPath = GlobalLock(hPath);
  164. hWndApp = GetDlgItem(hDlg, ID_FIRSTDDEEDIT+2);
  165. if(IsDlgButtonChecked(hDlg, ID_USESDDE) &&
  166. !SendMessage(hWndApp, WM_GETTEXTLENGTH, 0, 0L) &&
  167. (hLocPath=StringToLocalHandle(lpPath, LMEM_MOVEABLE))) {
  168. SendMessage(hWndApp, WM_SETTEXT, 0,
  169. (DWORD)((LPSTR)GetAppName(hLocPath)));
  170. SendMessage(hWndApp, EM_SETMODIFY, 1, 0L);
  171. LocalFree(hLocPath);
  172. }
  173. hWndEdit = GetDlgItem(hDlg, ID_COMMAND);
  174. SendMessage(hWndEdit, WM_SETTEXT, 0, (DWORD)lpPath);
  175. SendMessage(hWndEdit, EM_SETMODIFY, 1, 0L);
  176. GlobalUnlock(hPath);
  177. GlobalFree(hPath);
  178. break;
  179. }
  180. case ID_HELP:
  181. if(GetParent(LOWORD(lParam)) != hDlg)
  182. break;
  183. case ID_HELPBUTTON:
  184. MyHelp(hDlg, HELP_CONTEXT, IDW_MODIFY+fMode);
  185. break;
  186. default:
  187. break;
  188. }
  189. return(FALSE);
  190. break;
  191. case WM_INITDIALOG:
  192. {
  193. HANDLE hId, hTitle;
  194. HWND hWndId, hWndName;
  195. WORD wErrMsg;
  196. hId = GetListboxString(hWndIds,
  197. (WORD)SendMessage(hWndNames, LB_GETCURSEL, 0, 0L));
  198. hWndName = GetDlgItem(hDlg, ID_CLASSNAME);
  199. if(fMode&FLAG_NEW) {
  200. if(wErrMsg=GetLocalCopies(hWndName, NULL))
  201. goto Error2_1;
  202. cUsesDDE[0] = cUsesDDE[1] = 1;
  203. } else {
  204. wErrMsg = IDS_OUTOFMEMORY;
  205. if(!hId || (wErrMsg=GetLocalCopies(hWndName, hId)))
  206. goto Error2_1;
  207. }
  208. hWndId = GetDlgItem(hDlg, ID_CLASSID);
  209. SendMessage(hWndId, EM_LIMITTEXT, MAX_KEY_LENGTH-1, 0L);
  210. if(fMode&(FLAG_NEW|FLAG_COPY)) {
  211. DestroyWindow(GetDlgItem(hDlg, ID_STATCLASSID));
  212. wErrMsg = IDS_OUTOFMEMORY;
  213. if(!(hTitle=MyLoadString(fMode&FLAG_NEW ? IDS_ADD : IDS_COPY, NULL,
  214. LMEM_MOVEABLE)))
  215. goto Error2_1;
  216. SendMessage(hDlg, WM_SETTEXT, 0, (DWORD)((LPSTR)LocalLock(hTitle)));
  217. LocalUnlock(hTitle);
  218. LocalFree(hTitle);
  219. SetFocus(hWndId);
  220. } else {
  221. DestroyWindow(hWndId);
  222. hWndId = GetDlgItem(hDlg, ID_STATCLASSID);
  223. SetWindowWord(hWndId, GWW_ID, ID_CLASSID);
  224. SendMessage(hWndId, WM_SETTEXT, 0, (DWORD)((LPSTR)LocalLock(hId)));
  225. LocalUnlock(hId);
  226. SetFocus(GetDlgItem(hDlg, ID_CLASSNAME));
  227. }
  228. CheckRadioButton(hDlg, ID_OPENRADIO, ID_PRINTRADIO, ID_OPENRADIO);
  229. SendMessage(hDlg, WM_COMMAND, ID_OPENRADIO, 0L);
  230. if(hId)
  231. LocalFree(hId);
  232. return(FALSE);
  233. Error2_1:
  234. MyMessageBox(hDlg, wErrMsg, MB_OK, 0);
  235. PostMessage(hDlg, WM_COMMAND, IDCANCEL, 0L);
  236. if(hId)
  237. LocalFree(hId);
  238. break;
  239. }
  240. default:
  241. return(FALSE);
  242. }
  243. return(TRUE);
  244. }
  245. int FAR PASCAL MainWndDlg(HWND hDlg, WORD message, WORD wParam, DWORD lParam)
  246. {
  247. static int nTop;
  248. switch(message) {
  249. case WM_COMMAND:
  250. switch(wParam) {
  251. case ID_NAMELIST:
  252. if(HIWORD(lParam) == LBN_DBLCLK)
  253. SendMessage(hWndMain, WM_COMMAND, ID_MODIFY, 0L);
  254. break;
  255. default:
  256. break;
  257. }
  258. return(FALSE);
  259. break;
  260. case WM_SIZE:
  261. {
  262. RECT rcList, rcWnd;
  263. int hgtWnd, hgt;
  264. hgtWnd = HIWORD(lParam) + 1;
  265. hgt = hgtWnd - nTop;
  266. SetWindowPos(hWndNames, NULL, -1, nTop, LOWORD(lParam)+2, hgt,
  267. SWP_NOZORDER);
  268. GetWindowRect(hWndNames, &rcList);
  269. ScreenToClient(hDlg, (POINT *)(&rcList) + 1);
  270. if(rcList.bottom != hgtWnd) {
  271. GetWindowRect(hDlg, &rcWnd);
  272. SetWindowPos(hDlg, NULL, 0, 0, rcWnd.right-rcWnd.left,
  273. rcWnd.bottom-rcWnd.top-hgtWnd+rcList.bottom,
  274. SWP_NOMOVE | SWP_NOZORDER);
  275. }
  276. break;
  277. }
  278. case WM_INITDIALOG:
  279. {
  280. RECT rcTemp;
  281. GetWindowRect(GetDlgItem(hDlg, ID_NAMELIST), &rcTemp);
  282. ScreenToClient(hDlg, (POINT *)&rcTemp);
  283. nTop = rcTemp.top;
  284. break;
  285. }
  286. default:
  287. return(FALSE);
  288. }
  289. return(TRUE);
  290. }
  291. long FAR PASCAL MainWnd(HWND hWnd, WORD iMessage, WORD wParam, LONG lParam)
  292. {
  293. HCURSOR oldCursor;
  294. switch(iMessage) {
  295. case WM_ACTIVATE:
  296. if(wParam)
  297. break;
  298. goto DoDefault;
  299. case WM_CREATE:
  300. {
  301. WORD wErrMsg = IDS_OUTOFMEMORY;
  302. if(!(lpMainWndDlg=MakeProcInstance(MainWndDlg, hInstance)))
  303. goto Error1_1;
  304. if(!(hWndDlg=CreateDialog(hInstance, MAKEINTRESOURCE(MAINWND), hWnd,
  305. lpMainWndDlg)))
  306. goto Error1_1;
  307. hWndNames = GetDlgItem(hWndDlg, ID_NAMELIST);
  308. hWndIds = GetDlgItem(hWndDlg, ID_IDLIST);
  309. if(wErrMsg=ResetClassList(hWndIds, hWndNames))
  310. goto Error1_1;
  311. ShowWindow(hWndDlg, SW_SHOW);
  312. goto DoDefault;
  313. Error1_1:
  314. MyMessageBox(hWnd, wErrMsg, MB_OK, 0);
  315. DestroyWindow(hWnd);
  316. break;
  317. }
  318. /* Return 1 to say it's OK to close
  319. */
  320. case WM_CLOSE:
  321. case WM_QUERYENDSESSION:
  322. return(1L);
  323. case WM_COMMAND:
  324. oldCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
  325. switch(wParam) {
  326. case ID_FINISHMERGE:
  327. {
  328. WORD wErrMsg;
  329. if(wErrMsg=ResetClassList(hWndIds, hWndNames))
  330. MyMessageBox(GetLastActivePopup(hWnd), wErrMsg, MB_OK, 0);
  331. break;
  332. }
  333. case ID_ADD:
  334. fMode = FLAG_NEW;
  335. goto DoDlg;
  336. case ID_COPY:
  337. fMode = FLAG_COPY;
  338. goto DoDlg;
  339. case ID_MODIFY:
  340. fMode = 0;
  341. DoDlg:
  342. {
  343. HANDLE hId, hName;
  344. PSTR pId, pName;
  345. WORD wErrMsg = IDS_OUTOFMEMORY;
  346. int nNewId;
  347. if(!(hId=DoDialogBox(MAKEINTRESOURCE(EDITDLG), hWnd, EditDlg)))
  348. break;
  349. if(hId == 0xffff)
  350. goto Error2_1;
  351. if(wErrMsg=MyGetClassName(hId, &hName))
  352. goto Error2_2;
  353. if(wParam == ID_MODIFY) {
  354. int nClassId;
  355. nClassId = (WORD)SendMessage(hWndNames, LB_GETCURSEL, 0, 0L);
  356. SendMessage(hWndNames, WM_SETREDRAW, 0, 0L);
  357. SendMessage(hWndNames, LB_DELETESTRING, nClassId, 0L);
  358. SendMessage(hWndIds, LB_DELETESTRING, nClassId, 0L);
  359. SendMessage(hWndNames, WM_SETREDRAW, 1, 0L);
  360. }
  361. pName = LocalLock(hName);
  362. pId = LocalLock(hId);
  363. wErrMsg = IDS_OUTOFMEMORY;
  364. if((nNewId=(int)SendMessage(hWndNames, LB_ADDSTRING, 0,
  365. (DWORD)((LPSTR)pName)))!=LB_ERR
  366. && SendMessage(hWndIds, LB_INSERTSTRING, nNewId,
  367. (DWORD)((LPSTR)pId))!=LB_ERR)
  368. wErrMsg = NULL;
  369. SendMessage(hWndNames, LB_SETCURSEL, nNewId, 0L);
  370. LocalUnlock(hId);
  371. LocalUnlock(hName);
  372. LocalFree(hName);
  373. Error2_2:
  374. LocalFree(hId);
  375. Error2_1:
  376. if(wErrMsg)
  377. MyMessageBox(hWnd, wErrMsg, MB_OK, 0);
  378. break;
  379. }
  380. case ID_DELETE:
  381. {
  382. HANDLE hId, hName;
  383. WORD wErrMsg = IDS_OUTOFMEMORY;
  384. PSTR pName;
  385. int nClassId;
  386. if((nClassId=(int)SendMessage(hWndNames, LB_GETCURSEL, 0, 0L))
  387. == LB_ERR)
  388. break;
  389. if(!(hId=GetListboxString(hWndIds, nClassId)))
  390. goto Error4_1;
  391. if(!(hName=GetListboxString(hWndNames, nClassId)))
  392. goto Error4_2;
  393. pName = LocalLock(hName);
  394. wErrMsg = NULL;
  395. if(MyMessageBox(hWnd, IDS_SUREDELETE, MB_ICONEXCLAMATION | MB_YESNO,
  396. lstrlen(pName), (LPSTR)pName) != IDYES)
  397. goto Error4_3;
  398. if(wErrMsg=DeleteClassId(hId))
  399. goto Error4_3;
  400. SendMessage(hWndIds, LB_DELETESTRING, nClassId, 0L);
  401. SendMessage(hWndNames, LB_DELETESTRING, nClassId, 0L);
  402. if(SendMessage(hWndNames, LB_SETCURSEL, nClassId, 0L) == LB_ERR)
  403. SendMessage(hWndNames, LB_SETCURSEL, --nClassId, 0L);
  404. Error4_3:
  405. LocalUnlock(hName);
  406. LocalFree(hName);
  407. Error4_2:
  408. LocalFree(hId);
  409. Error4_1:
  410. if(wErrMsg)
  411. MyMessageBox(hWnd, wErrMsg, MB_OK, 0);
  412. break;
  413. }
  414. default:
  415. break;
  416. }
  417. SetCursor(oldCursor);
  418. break;
  419. default:
  420. DoDefault:
  421. return(DefWindowProc(hWnd, iMessage, wParam, lParam));
  422. break;
  423. }
  424. return 0L;
  425. }