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.

905 lines
23 KiB

  1. /****************************************************************************
  2. PROGRAM: xerox.c
  3. PURPOSE: Copies keyboard input to multiple target windows.
  4. ****************************************************************************/
  5. #include "xerox.h"
  6. #include "string.h"
  7. #include "group.h"
  8. #include "pos.h"
  9. #include "stdio.h"
  10. #define cmPaste 0xFFF1
  11. #define VK_V 0x56 //Virtual Key V
  12. #define KEY_IS_DOWN 0x8000
  13. // #define TESTING
  14. static char pszMainWindowClass[] = "Main Window Class";
  15. char szTitle[] = "Xerox";
  16. HANDLE hInst;
  17. HACCEL hAccel;
  18. HWND hwndMain;
  19. HWND hwndList; // handle of listbox containing targets.
  20. BOOL InitApplication(HANDLE);
  21. BOOL InitInstance(HANDLE, INT);
  22. INT_PTR APIENTRY MainWndProc(HWND, UINT, WPARAM, LPARAM);
  23. BOOL PostToTargets(HWND, UINT, WPARAM, LPARAM);
  24. INT_PTR APIENTRY WindowListDlgProc(HWND, UINT, WPARAM, LPARAM);
  25. BOOL WindowListDlgInit(HWND);
  26. BOOL CALLBACK WindowListWindowEnum(HWND, LPARAM);
  27. INT WindowListDlgEnd(HWND, HWND*);
  28. INT_PTR APIENTRY AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
  29. INT_PTR APIENTRY GroupAddDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  30. INT_PTR APIENTRY GroupDeleteDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  31. INT_PTR APIENTRY GroupSelectDlgProc(HWND hDlg, UINT msg, WPARAM wParam,LPARAM lParam);
  32. /****************************************************************************
  33. FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  34. PURPOSE: calls initialization function, processes message loop
  35. ****************************************************************************/
  36. int
  37. WINAPI
  38. WinMain(
  39. HINSTANCE hInstance,
  40. HINSTANCE hPrevInstance,
  41. LPSTR lpCmdLine,
  42. int nCmdShow
  43. )
  44. {
  45. MSG Message;
  46. if (!hPrevInstance) {
  47. if (!InitApplication(hInstance)) {
  48. return (FALSE);
  49. }
  50. }
  51. if (!InitInstance(hInstance, nCmdShow)) {
  52. return (FALSE);
  53. }
  54. while (GetMessage(&Message, NULL, 0, 0)) {
  55. if (!TranslateAccelerator(hwndMain, hAccel, &Message)) {
  56. TranslateMessage(&Message);
  57. DispatchMessage(&Message);
  58. }
  59. }
  60. SaveGroups();
  61. FreeGroups();
  62. return ((int)Message.wParam);
  63. }
  64. /****************************************************************************
  65. FUNCTION: InitApplication(HANDLE)
  66. PURPOSE: Initializes window data and registers window class
  67. ****************************************************************************/
  68. BOOL InitApplication(HANDLE hInstance)
  69. {
  70. WNDCLASS wc;
  71. // Register the main window class
  72. wc.style = 0;
  73. wc.lpfnWndProc = MainWndProc;
  74. wc.cbClsExtra = 0;
  75. wc.cbWndExtra = 0;
  76. wc.hInstance = hInstance;
  77. wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPICON));
  78. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  79. wc.hbrBackground = GetStockObject(WHITE_BRUSH);
  80. wc.lpszMenuName = (LPSTR)IDM_MAINMENU;
  81. wc.lpszClassName = pszMainWindowClass;
  82. return (RegisterClass(&wc));
  83. }
  84. /****************************************************************************
  85. FUNCTION: InitInstance(HANDLE, int)
  86. PURPOSE: Saves instance handle and creates main window
  87. ****************************************************************************/
  88. BOOL InitInstance(HANDLE hInstance, INT nCmdShow)
  89. {
  90. RECT rc;
  91. BOOL fLastPosSet;
  92. LoadGroups();
  93. // Store instance in global
  94. hInst = hInstance;
  95. hAccel = LoadAccelerators(hInst, MAKEINTRESOURCE(IDR_ACCEL));
  96. fLastPosSet = GetLastPosition(&rc);
  97. // Create the main window
  98. hwndMain = CreateWindow(
  99. pszMainWindowClass,
  100. szTitle,
  101. WS_OVERLAPPEDWINDOW,
  102. fLastPosSet ? rc.left : CW_USEDEFAULT,
  103. fLastPosSet ? rc.top : CW_USEDEFAULT,
  104. fLastPosSet ? rc.right - rc.left : CW_USEDEFAULT,
  105. fLastPosSet ? rc.bottom - rc.top : CW_USEDEFAULT,
  106. NULL,
  107. NULL,
  108. hInstance,
  109. NULL);
  110. if (hwndMain == NULL) {
  111. return(FALSE);
  112. }
  113. if (GetCurrentGroup() != NULL) {
  114. SelectGroupDefinition(GetCurrentGroup(), hwndList, FALSE);
  115. }
  116. ShowWindow(hwndMain, nCmdShow);
  117. UpdateWindow(hwndMain);
  118. return (TRUE);
  119. }
  120. /****************************************************************************
  121. FUNCTION: MainWndProc(HWND, UINT, WPARAM, LONG)
  122. PURPOSE: Processes messages for main window
  123. COMMENTS:
  124. ****************************************************************************/
  125. INT_PTR
  126. APIENTRY
  127. MainWndProc(
  128. HWND hwnd,
  129. UINT message,
  130. WPARAM wParam,
  131. LPARAM lParam
  132. )
  133. {
  134. HMENU hMenu;
  135. BOOL Result;
  136. RECT rcWindow;
  137. WINDOWPLACEMENT wpWndPlacement;
  138. HWND hwndAdd, hwndDelete;
  139. CHAR string[MAX_STRING_BYTES];
  140. INT ItemDelete;
  141. INT TargetCount;
  142. INT Index;
  143. HWND hwndTarget;
  144. WINDOWPLACEMENT wndpl;
  145. INT NumberOfItems = 0;
  146. INT counter;
  147. HWND WindowHandleList[MAX_WINDOWS];
  148. INT SelectedWindows[MAX_WINDOWS];
  149. switch (message) {
  150. case WM_CREATE:
  151. GetWindowRect(hwnd, &rcWindow);
  152. if (GetCurrentGroup() != NULL) {
  153. wsprintf(string, "%s - (%s)", szTitle, GetCurrentGroup());
  154. SetWindowText(hwnd, string);
  155. }
  156. hwndList = CreateWindow(
  157. "LISTBOX",
  158. NULL, // Title
  159. WS_CHILD | WS_VISIBLE | LBS_MULTIPLESEL,
  160. 0, 0, // x,y
  161. rcWindow.right - rcWindow.left,
  162. rcWindow.bottom - rcWindow.top,
  163. hwnd, // owner
  164. NULL, // menu
  165. hInst,
  166. NULL);
  167. //
  168. // Attach all threads to our input state
  169. //
  170. #ifndef TESTING
  171. Result = AttachThreadInput(
  172. 0,
  173. GetCurrentThreadId(),
  174. TRUE // Attaching
  175. );
  176. if (!Result) {
  177. }
  178. #endif // !TESTING
  179. return(0); // Continue creating window
  180. case WM_INITMENU:
  181. hMenu = (HMENU)wParam;
  182. EnableMenuItem(hMenu, IDM_GROUPRSTWIN, GetCurrentGroup() != NULL ? MF_ENABLED : MF_GRAYED);
  183. EnableMenuItem(hMenu, IDM_GROUPMINWIN, GetCurrentGroup() != NULL ? MF_ENABLED : MF_GRAYED);
  184. EnableMenuItem(hMenu, IDM_GROUPDELETE, CountGroups() ? MF_ENABLED : MF_GRAYED);
  185. EnableMenuItem(hMenu, IDM_GROUPSELECT, CountGroups() ? MF_ENABLED : MF_GRAYED);
  186. EnableMenuItem(hMenu, IDM_TARGETDELETE,
  187. (SendMessage(hwndList, LB_GETCURSEL, 0, 0) != LB_ERR) ?
  188. MF_ENABLED : MF_GRAYED);
  189. break;
  190. case WM_SIZE:
  191. //
  192. // Keep the listbox in sync with the main window
  193. //
  194. MoveWindow(hwndList, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
  195. return(0);
  196. case WM_COMMAND:
  197. switch (LOWORD(wParam)) {
  198. /*
  199. * Restore the windows of the current group. Assumes that everything
  200. * can be restored.
  201. */
  202. case IDM_GROUPRSTWIN:
  203. TargetCount = (INT)SendMessage(hwndList, LB_GETCOUNT, 0, 0);
  204. if (TargetCount == LB_ERR) {
  205. break;
  206. }
  207. for (Index = 0; Index < TargetCount; Index ++) {
  208. hwndTarget = (HWND)SendMessage(hwndList, LB_GETITEMDATA, Index, 0);
  209. ShowWindow(hwndTarget, SW_RESTORE);
  210. }
  211. SetFocus(hwndMain);
  212. break;
  213. /*
  214. * Minimize the windows of the current group. Assumes that everything
  215. * can be minimized.
  216. */
  217. case IDM_GROUPMINWIN:
  218. TargetCount = (INT)SendMessage(hwndList, LB_GETCOUNT, 0, 0);
  219. if (TargetCount == LB_ERR) {
  220. break;
  221. }
  222. for (Index = 0; Index < TargetCount; Index ++) {
  223. hwndTarget = (HWND)SendMessage(hwndList, LB_GETITEMDATA, Index, 0);
  224. ShowWindow(hwndTarget, SW_MINIMIZE);
  225. }
  226. break;
  227. case IDM_TARGETADD:
  228. hwndAdd = (HWND)DialogBox(hInst,(LPSTR)IDD_WINDOWLIST, hwnd, WindowListDlgProc);
  229. SetNoCurrentGroup(hwnd, szTitle);
  230. break;
  231. case IDM_TARGETDELETE:
  232. NumberOfItems = (INT)SendMessage(hwndList, LB_GETSELCOUNT, 0, 0);
  233. if (SendMessage(hwndList, LB_GETSELITEMS, (WPARAM)NumberOfItems, (LPARAM)SelectedWindows) != NumberOfItems)
  234. {
  235. break;
  236. }
  237. if (NumberOfItems > 0)
  238. {
  239. counter = NumberOfItems;
  240. while ( counter-- > 0) {
  241. SendMessage(hwndList, LB_DELETESTRING, (WPARAM)WindowHandleList[counter], 0);
  242. }
  243. }
  244. SendMessage(hwndList, LB_SETSEL, 1, (LPARAM)(max(0, WindowHandleList[0] - 1)));
  245. SetNoCurrentGroup(hwnd, szTitle);
  246. break;
  247. case IDM_GROUPADD:
  248. //
  249. // Defines a 'group' of processes to equal the current target list
  250. //
  251. if (((LPSTR)DialogBox(hInst, MAKEINTRESOURCE(IDD_GROUPADD), hwnd, GroupAddDlgProc)) != NULL) {
  252. wsprintf(string, "%s - (%s)", szTitle, GetCurrentGroup());
  253. SetWindowText(hwnd, string);
  254. }
  255. break;
  256. case IDM_GROUPDELETE:
  257. DialogBox(hInst, MAKEINTRESOURCE(IDD_GROUPDELETE), hwnd, GroupDeleteDlgProc);
  258. if (GetCurrentGroup() == NULL) {
  259. SetWindowText(hwnd, szTitle);
  260. } else {
  261. SelectGroupDefinition(GetCurrentGroup(), hwndList, FALSE);
  262. wsprintf(string, "%s - (%s)", szTitle, GetCurrentGroup());
  263. SetWindowText(hwnd, string);
  264. }
  265. break;
  266. case IDM_GROUPSELECT:
  267. if (DialogBox(hInst, MAKEINTRESOURCE(IDD_GROUPSELECT), hwnd, GroupSelectDlgProc)) {
  268. wsprintf(string, "%s - (%s)", szTitle, GetCurrentGroup());
  269. SetWindowText(hwnd, string);
  270. }
  271. break;
  272. case IDM_REFRESHITEMS:
  273. SelectGroupDefinition(GetCurrentGroup(), hwndList, FALSE);
  274. break;
  275. case IDM_ABOUT:
  276. DialogBox(hInst,(LPSTR)IDD_ABOUT, hwnd, AboutDlgProc);
  277. break;
  278. default:
  279. break;
  280. }
  281. break;
  282. case WM_DESTROY:
  283. //
  284. // Detach all threads from our input state
  285. //
  286. #ifndef TESTING
  287. Result = AttachThreadInput(
  288. 0,
  289. GetCurrentThreadId(),
  290. FALSE // Detaching
  291. );
  292. if (!Result) {
  293. }
  294. #endif // !TESTING
  295. GetWindowPlacement( hwndMain, &wpWndPlacement );
  296. SetLastPosition(&wpWndPlacement.rcNormalPosition);
  297. PostQuitMessage(0);
  298. break;
  299. case WM_PARENTNOTIFY:
  300. if (LOWORD(wParam) == WM_RBUTTONDOWN) {
  301. // send cmPaste message.
  302. PostToTargets(hwndList,WM_SYSCOMMAND,cmPaste,lParam);
  303. }
  304. break;
  305. case WM_NCRBUTTONDOWN:
  306. // send cmPaste message.
  307. PostToTargets(hwndList,WM_SYSCOMMAND,cmPaste,lParam);
  308. break;
  309. case WM_KEYDOWN:
  310. //
  311. // Forward key messages to all targets
  312. //
  313. switch (wParam) {
  314. case VK_INSERT:
  315. if (GetKeyState(VK_SHIFT) & KEY_IS_DOWN) {
  316. PostToTargets(hwndList,WM_SYSCOMMAND,cmPaste,lParam);
  317. return (DefWindowProc(hwnd, message, wParam, lParam));
  318. }
  319. break;
  320. case VK_V:
  321. if (GetKeyState(VK_CONTROL) & KEY_IS_DOWN) {
  322. PostToTargets(hwndList,WM_SYSCOMMAND,cmPaste,lParam);
  323. return (DefWindowProc(hwnd, message, wParam, lParam));
  324. }
  325. break;
  326. }
  327. case WM_KEYUP:
  328. //
  329. // Forward key messages to all targets
  330. //
  331. #ifndef TESTING
  332. PostToTargets(hwndList, message, wParam, lParam);
  333. #endif // !TESTING
  334. // drop through to default processing...
  335. default:
  336. return(DefWindowProc(hwnd, message, wParam, lParam));
  337. }
  338. return 0;
  339. }
  340. /****************************************************************************
  341. FUNCTION: PostToTargets(HWND)
  342. PURPOSE: Posts a message to all target windows
  343. RETURNS: TRUE on success, FALSE on failure
  344. ****************************************************************************/
  345. BOOL
  346. PostToTargets(
  347. HWND hwndList,
  348. UINT message,
  349. WPARAM wparam,
  350. LPARAM lparam
  351. )
  352. {
  353. INT TargetCount;
  354. INT Index;
  355. HWND hwndTarget;
  356. BOOL Restarted = FALSE;
  357. RestartPost:
  358. TargetCount = (INT)SendMessage(hwndList, LB_GETCOUNT, 0, 0);
  359. if (TargetCount == LB_ERR) {
  360. return(FALSE);
  361. }
  362. for (Index = 0; Index < TargetCount; Index ++) {
  363. hwndTarget = (HWND)SendMessage(hwndList, LB_GETITEMDATA, Index, 0);
  364. if ((hwndTarget != INVALID_HANDLE_VALUE) &&
  365. !PostMessage(hwndTarget, message, wparam, lparam)) {
  366. if (Restarted) {
  367. return(FALSE);
  368. }
  369. if (!SelectGroupDefinition(GetCurrentGroup(), hwndList, TRUE)) {
  370. return(FALSE);
  371. }
  372. Restarted = TRUE;
  373. goto RestartPost;
  374. }
  375. }
  376. return(TRUE);
  377. }
  378. /****************************************************************************
  379. FUNCTION: WindowListDlgProc(HWND, unsigned, WORD, LONG)
  380. PURPOSE: Processes messages
  381. ****************************************************************************/
  382. INT_PTR
  383. APIENTRY
  384. WindowListDlgProc(
  385. HWND hDlg,
  386. UINT message,
  387. WPARAM wParam,
  388. LPARAM lParam
  389. )
  390. {
  391. INT NumberOfWindows = 0;
  392. INT counter = 0;
  393. HWND WindowHandleList[MAX_WINDOWS];
  394. CHAR string[MAX_STRING_BYTES];
  395. switch (message) {
  396. case WM_INITDIALOG:
  397. if (!WindowListDlgInit(hDlg)) {
  398. // Failed to initialize dialog, get out
  399. EndDialog(hDlg, FALSE);
  400. }
  401. return (TRUE);
  402. case WM_COMMAND:
  403. switch (LOWORD(wParam)) {
  404. case IDLB_WINDOWLIST:
  405. switch (HIWORD(wParam)) {
  406. case LBN_DBLCLK:
  407. break; // drop through
  408. default:
  409. return(0);
  410. }
  411. // drop through on double click ...
  412. case IDOK:
  413. NumberOfWindows = WindowListDlgEnd(hDlg, WindowHandleList);
  414. if (NumberOfWindows > 0)
  415. {
  416. while ( counter++ < NumberOfWindows) {
  417. //
  418. // If the window is already in our list, don't add it
  419. //
  420. if (FindLBData(hwndList, (DWORD_PTR)WindowHandleList[counter - 1]) >= 0) {
  421. continue;
  422. }
  423. //
  424. // Don't add ourselves to the list
  425. //
  426. if (WindowHandleList[counter - 1] == GetParent(hDlg)) {
  427. continue;
  428. }
  429. //
  430. // Add the window to the list
  431. //
  432. if (GetWindowText(WindowHandleList[counter - 1], string, sizeof(string)) > 0) {
  433. if (AddLBItemhwnd(hwndList, string, (LONG_PTR)WindowHandleList[counter - 1]) < 0) {
  434. }
  435. }
  436. }
  437. }
  438. // We're done, drop through to enddialog...
  439. case IDCANCEL:
  440. EndDialog(hDlg, FALSE);
  441. return TRUE;
  442. break;
  443. default:
  444. // We didn't process this message
  445. return FALSE;
  446. break;
  447. }
  448. break;
  449. default:
  450. // We didn't process this message
  451. return FALSE;
  452. }
  453. // We processed the message
  454. return TRUE;
  455. DBG_UNREFERENCED_PARAMETER(lParam);
  456. }
  457. /****************************************************************************
  458. FUNCTION: WindowListDlgInit(HWND)
  459. PURPOSE: Initialise the window list dialog
  460. RETURNS: TRUE on success, FALSE on failure
  461. ****************************************************************************/
  462. BOOL
  463. WindowListDlgInit(
  464. HWND hDlg
  465. )
  466. {
  467. // Fill the list box with top-level windows and their handles
  468. EnumWindows(WindowListWindowEnum, (LONG_PTR)hDlg);
  469. return(TRUE);
  470. }
  471. /****************************************************************************
  472. FUNCTION: WindowListWindowEnum
  473. PURPOSE: Window enumeration call-back function.
  474. Adds each window to the window list-box
  475. RETURNS: TRUE to continue enumeration, FALSE to stop.
  476. ****************************************************************************/
  477. BOOL
  478. CALLBACK
  479. WindowListWindowEnum(
  480. HWND hwnd,
  481. LPARAM lParam
  482. )
  483. {
  484. HWND hDlg = (HWND)lParam;
  485. CHAR string[MAX_STRING_BYTES];
  486. //
  487. // Don't add ourselves to the list
  488. //
  489. if (hwnd == hDlg) {
  490. return(TRUE);
  491. }
  492. //
  493. // Don't add our main window to the list
  494. //
  495. if (hwnd == hwndMain) {
  496. return(TRUE);
  497. }
  498. if (GetWindowText(hwnd, string, MAX_STRING_BYTES) != 0) {
  499. // This window has a caption, so add it to the list-box
  500. AddLBItem(hDlg, IDLB_WINDOWLIST, string, (LONG_PTR)hwnd);
  501. }
  502. return(TRUE);
  503. }
  504. /****************************************************************************
  505. FUNCTION: WindowListDlgEnd(HWND, *HWND)
  506. PURPOSE: Cleans up after window list dialog
  507. RETURNS: Number of window handles the user has selected or NULL
  508. ****************************************************************************/
  509. INT
  510. WindowListDlgEnd(
  511. HWND hDlg,
  512. HWND *WindowList
  513. )
  514. {
  515. HWND hwndListBox = GetDlgItem(hDlg, IDLB_WINDOWLIST);
  516. HWND hwndEdit;
  517. INT iItem, NumberOfItems;
  518. INT SelectedWindows[MAX_WINDOWS];
  519. NumberOfItems = (INT)SendMessage(hwndListBox, LB_GETSELCOUNT, 0, 0);
  520. if (SendMessage(hwndListBox, LB_GETSELITEMS, (WPARAM)NumberOfItems, (LPARAM)SelectedWindows) != NumberOfItems)
  521. {
  522. return 0;
  523. }
  524. iItem = 0;
  525. while (iItem++ < NumberOfItems)
  526. {
  527. // Read selection from list-box and get its hwnd
  528. WindowList[iItem-1] = (HWND)SendMessage(hwndListBox, LB_GETITEMDATA, SelectedWindows[iItem - 1], 0);
  529. }
  530. return (NumberOfItems);
  531. }
  532. /****************************************************************************
  533. FUNCTION: AboutDlgProc(HWND, unsigned, WORD, LONG)
  534. PURPOSE: Processes messages for About dialog
  535. ****************************************************************************/
  536. INT_PTR
  537. APIENTRY
  538. AboutDlgProc(
  539. HWND hDlg,
  540. UINT message,
  541. WPARAM wParam,
  542. LPARAM lParam
  543. )
  544. {
  545. switch (message) {
  546. case WM_COMMAND:
  547. switch (LOWORD(wParam)) {
  548. case IDOK:
  549. // we're done, drop through to quit dialog....
  550. case IDCANCEL:
  551. EndDialog(hDlg, TRUE);
  552. return TRUE;
  553. break;
  554. default:
  555. // We didn't process this message
  556. return FALSE;
  557. break;
  558. }
  559. break;
  560. default:
  561. // We didn't process this message
  562. return FALSE;
  563. }
  564. // We processed the message
  565. return TRUE;
  566. DBG_UNREFERENCED_PARAMETER(lParam);
  567. }
  568. INT_PTR
  569. APIENTRY
  570. GroupAddDlgProc(
  571. HWND hDlg,
  572. UINT msg,
  573. WPARAM wParam,
  574. LPARAM lParam
  575. )
  576. {
  577. char szName[MAX_STRING_BYTES];
  578. int item;
  579. switch (msg) {
  580. case WM_INITDIALOG:
  581. GroupListInit(GetDlgItem(hDlg, IDCB_GROUPLIST), TRUE);
  582. SendDlgItemMessage(hDlg, IDCB_GROUPLIST, CB_SETCURSEL, 0, 0);
  583. return(TRUE);
  584. case WM_COMMAND:
  585. switch (LOWORD(wParam)) {
  586. case IDOK:
  587. if (GetDlgItemText(hDlg, IDEF_GROUPNAME, szName, sizeof(szName)) > 0) {
  588. if (!AddGroupDefinition(szName, hwndList)) {
  589. EndDialog(hDlg, 0);
  590. }
  591. } else {
  592. MessageBeep(0);
  593. return(0);
  594. }
  595. EndDialog(hDlg, (INT_PTR)GetCurrentGroup());
  596. return(0);
  597. case IDCANCEL:
  598. EndDialog(hDlg, 0);
  599. return(0);
  600. case IDCB_GROUPLIST:
  601. switch (HIWORD(wParam)) {
  602. case CBN_SELCHANGE:
  603. item = (int)SendDlgItemMessage(hDlg, IDCB_GROUPLIST, CB_GETCURSEL, 0, 0);
  604. if (item != CB_ERR) {
  605. SendDlgItemMessage(hDlg, IDCB_GROUPLIST, CB_GETLBTEXT, item, (LPARAM)szName);
  606. SetDlgItemText(hDlg, IDEF_GROUPNAME, szName);
  607. }
  608. return(0);
  609. }
  610. break;
  611. }
  612. }
  613. return(0);
  614. }
  615. INT_PTR
  616. APIENTRY
  617. GroupDeleteDlgProc(
  618. HWND hDlg,
  619. UINT msg,
  620. WPARAM wParam,
  621. LPARAM lParam
  622. )
  623. {
  624. char szName[MAX_STRING_BYTES];
  625. int item;
  626. switch (msg) {
  627. case WM_INITDIALOG:
  628. GroupListInit(GetDlgItem(hDlg, IDCB_GROUPLIST), TRUE);
  629. SendDlgItemMessage(hDlg, IDCB_GROUPLIST, CB_SETCURSEL, 0, 0);
  630. return(TRUE);
  631. case WM_COMMAND:
  632. switch (LOWORD(wParam)) {
  633. case IDOK:
  634. if ((item = (int)SendDlgItemMessage(hDlg, IDCB_GROUPLIST, CB_GETCURSEL, 0, 0)) != CB_ERR) {
  635. SendDlgItemMessage(hDlg, IDCB_GROUPLIST, CB_GETLBTEXT, item, (LPARAM)szName);
  636. DeleteGroupDefinition(szName);
  637. } else {
  638. MessageBeep(0);
  639. return(0);
  640. }
  641. EndDialog(hDlg, (INT_PTR)szName);
  642. return(0);
  643. case IDCANCEL:
  644. EndDialog(hDlg, 0);
  645. return(0);
  646. }
  647. }
  648. return(0);
  649. }
  650. INT_PTR
  651. APIENTRY
  652. GroupSelectDlgProc(
  653. HWND hDlg,
  654. UINT msg,
  655. WPARAM wParam,
  656. LPARAM lParam
  657. )
  658. {
  659. char szName[MAX_STRING_BYTES];
  660. int item;
  661. switch (msg) {
  662. case WM_INITDIALOG:
  663. GroupListInit(GetDlgItem(hDlg, IDCB_GROUPLIST), TRUE);
  664. if (GetCurrentGroup() != NULL) {
  665. item = (int)SendDlgItemMessage(hDlg, IDCB_GROUPLIST, CB_FINDSTRING, -1, (LPARAM)(LPSTR)GetCurrentGroup());
  666. SendDlgItemMessage(hDlg, IDCB_GROUPLIST, CB_SETCURSEL, item, 0);
  667. } else {
  668. SendDlgItemMessage(hDlg, IDCB_GROUPLIST, CB_SETCURSEL, 0, 0);
  669. }
  670. return(TRUE);
  671. case WM_COMMAND:
  672. switch (LOWORD(wParam)) {
  673. case IDOK:
  674. if ((item = (int)SendDlgItemMessage(hDlg, IDCB_GROUPLIST, CB_GETCURSEL, 0, 0)) != CB_ERR) {
  675. SendDlgItemMessage(hDlg, IDCB_GROUPLIST, CB_GETLBTEXT, item, (LPARAM)szName);
  676. SelectGroupDefinition(szName, hwndList, FALSE);
  677. } else {
  678. MessageBeep(0);
  679. return(0);
  680. }
  681. EndDialog(hDlg, (INT_PTR)szName);
  682. return(0);
  683. case IDCANCEL:
  684. EndDialog(hDlg, 0);
  685. return(0);
  686. }
  687. }
  688. return(0);
  689. }