Source code of Windows XP (NT5)
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.

1314 lines
43 KiB

  1. /****************************************************************************
  2. PROGRAM: DdeSpy.c
  3. ****************************************************************************/
  4. #define UNICODE
  5. #include <windows.h> /* required for all Windows applications */
  6. #include <windowsx.h>
  7. #include <shellapi.h>
  8. #include <dde.h>
  9. #include <stdio.h>
  10. #include <io.h>
  11. #include <errno.h>
  12. #include <string.h>
  13. #include <stdlib.h>
  14. #include <ctype.h>
  15. #include "ddespy.h"
  16. #include "lists.h"
  17. /* GLOBAL Variables used for DDESPY */
  18. UINT idInst = 0;
  19. HINSTANCE hInst;
  20. HICON hIcon;
  21. HWND hWndString = NULL;
  22. HWND hwndSpy = NULL;
  23. HANDLE fhOutput = NULL;
  24. OFSTRUCT ofsOpen;
  25. TCHAR OpenName[MAX_FNAME + 1];
  26. TCHAR TBuf[BUFFER_SIZE];
  27. TCHAR TBuf2[BUFFER_SIZE];
  28. TCHAR szNULL[] = TEXT("");
  29. LPTSTR apszResources[IDS_LAST + 1];
  30. PFNCALLBACK pfnDdeCallback = NULL;
  31. HWND hwndTrack[IT_COUNT] = { 0 };
  32. LPTSTR TrackTitle[IT_COUNT];
  33. BOOL fBlockMsg[WM_DDE_LAST - WM_DDE_FIRST + 1] = { 0 };
  34. BOOL fBlockCb[15] = { 0 };
  35. LPTSTR TrackHeading[IT_COUNT];
  36. struct { /* profile data */
  37. BOOL fOutput[IO_COUNT];
  38. BOOL fFilter[IF_COUNT];
  39. BOOL fTrack[IT_COUNT];
  40. BOOL fTerse;
  41. } pro;
  42. BOOL LoadResourceStrings()
  43. {
  44. int i, cbLeft, cbRes;
  45. LPTSTR psz;
  46. cbLeft = 0x1000;
  47. psz = LocalAlloc(LPTR, sizeof(TCHAR) * cbLeft);
  48. for (i = 0; i <= IDS_LAST; i++) {
  49. apszResources[i] = psz;
  50. cbRes = LoadString(hInst, i, psz, cbLeft) + 1;
  51. cbLeft -= cbRes;
  52. psz += cbRes;
  53. }
  54. for (i = 0; i < IT_COUNT; i++) {
  55. TrackTitle[i] = RefString(IDS_TRACKTITLE_1 + i);
  56. TrackHeading[i] = RefString(IDS_TRACKHEADING_1 + i);
  57. }
  58. lstrcpy(TBuf, RefString(IDS_DEFAULT_OUTPUT_FNAME));
  59. GetFullPathName(TBuf, sizeof(OpenName) / sizeof(TCHAR),
  60. OpenName, (LPTSTR *)TBuf2);
  61. return(TRUE);
  62. }
  63. int
  64. WINAPI
  65. WinMain(
  66. HINSTANCE hInstance,
  67. HINSTANCE hPrevInstance,
  68. LPSTR lpCmdLine,
  69. int nCmdShow)
  70. {
  71. MSG msg;
  72. UNREFERENCED_PARAMETER(lpCmdLine);
  73. hInst = hInstance;
  74. if (!LoadResourceStrings()) {
  75. return (FALSE);
  76. }
  77. if (!hPrevInstance)
  78. if (!InitApplication(hInstance)) /* Initialize shared things */
  79. return (FALSE); /* Exits if unable to initialize */
  80. /* Perform initializations that apply to a specific instance */
  81. if (!InitInstance(hInstance, nCmdShow)) {
  82. CloseApp();
  83. return (FALSE);
  84. }
  85. /* Acquire and dispatch messages until a WM_QUIT message is received. */
  86. while (GetMessage(&msg, /* message structure */
  87. NULL, /* handle of window receiving the message */
  88. 0, /* lowest message to examine */
  89. 0)) /* highest message to examine */
  90. {
  91. TranslateMessage(&msg); /* Translates virtual key codes */
  92. DispatchMessage(&msg); /* Dispatches message to window */
  93. }
  94. CloseApp();
  95. return ((int)msg.wParam); /* Returns the value from PostQuitMessage */
  96. }
  97. BOOL InitApplication(HINSTANCE hInstance)
  98. {
  99. WNDCLASS wc;
  100. if (!InitTestSubs())
  101. return(FALSE);
  102. /* Fill in window class structure with parameters that describe the */
  103. /* main window. */
  104. wc.style = 0; /* Class style(s). */
  105. wc.lpfnWndProc = (WNDPROC)MainWndProc; /* Function to retrieve messages for */
  106. /* windows of this class. */
  107. wc.cbClsExtra = 0; /* No per-class extra data. */
  108. wc.cbWndExtra = 0; /* No per-window extra data. */
  109. wc.hInstance = hInstance; /* Application that owns the class. */
  110. /* faster, also can localize "DDESpy" */
  111. hIcon = wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DDESPY));
  112. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  113. wc.hbrBackground = GetStockObject(WHITE_BRUSH);
  114. wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU); /* Name of menu resource in .RC file. */
  115. wc.lpszClassName = RefString(IDS_CLASS);
  116. /* Register the window class and return success/failure code. */
  117. return (RegisterClass(&wc));
  118. }
  119. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  120. {
  121. RECT Rect;
  122. INT i;
  123. /* Save the instance handle in static variable, which will be used in */
  124. /* many subsequence calls from this application to Windows. */
  125. pfnDdeCallback = (PFNCALLBACK)MakeProcInstance((FARPROC)DdeCallback,
  126. hInstance);
  127. GetProfile();
  128. /* Create a main window for this application instance. */
  129. hwndSpy = CreateWindow(
  130. RefString(IDS_CLASS),
  131. RefString(IDS_TITLE),
  132. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  133. CW_USEDEFAULT, /* Default horizontal position. */
  134. CW_USEDEFAULT, /* Default vertical position. */
  135. CW_USEDEFAULT, /* Default width. */
  136. CW_USEDEFAULT, /* Default height. */
  137. NULL, /* Overlapped windows have no parent. */
  138. NULL, /* Use the window class menu. */
  139. hInstance, /* This instance owns this window. */
  140. NULL /* Pointer not needed. */
  141. );
  142. GetClientRect(hwndSpy, (LPRECT) &Rect);
  143. hWndString = CreateWindow( /* String Window (class Registered in Teststubs)*/
  144. RefString(IDS_STRINGCLASS),
  145. szNULL,
  146. WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL,
  147. 0,
  148. 0,
  149. Rect.right - Rect.left,
  150. Rect.bottom - Rect.top,
  151. hwndSpy,
  152. NULL,
  153. hInst,
  154. (LPTSTR)LongToPtr(MAKELONG(CCHARS, CLINES)));
  155. for (i = 0; i < IT_COUNT; i++) {
  156. if (pro.fTrack[i]) {
  157. pro.fTrack[i] = FALSE;
  158. SendMessage(hwndSpy, WM_COMMAND,
  159. GET_WM_COMMAND_MPS(IDM_TRACK_FIRST + i, 0, 0));
  160. }
  161. }
  162. if (!hwndSpy || !hWndString) {
  163. CloseApp();
  164. return (FALSE);
  165. }
  166. /* Make the window visible; update its client area; and return "success" */
  167. ShowWindow(hwndSpy, nCmdShow); /* Show the window */
  168. UpdateWindow(hwndSpy); /* Sends WM_PAINT message */
  169. if (SetFilters()) {
  170. return(FALSE);
  171. }
  172. return(TRUE);
  173. }
  174. VOID CloseApp()
  175. {
  176. DdeUninitialize(idInst); /* perform cleanup and store profile */
  177. SaveProfile();
  178. if (fhOutput != NULL)
  179. CloseHandle(fhOutput);
  180. UnregisterClass(RefString(IDS_CLASS), hInst);
  181. CloseTestSubs(hInst);
  182. }
  183. LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  184. {
  185. int i;
  186. switch (message) {
  187. case WM_CREATE:
  188. LoadAccelerators(hInst, MAKEINTRESOURCE(IDR_ACCEL));
  189. if (pro.fOutput[IO_FILE])
  190. fhOutput = (HANDLE)DoDialog(
  191. MAKEINTRESOURCE(IDD_OPEN),
  192. (DLGPROC)OpenDlg,
  193. 0,
  194. TRUE,
  195. hWnd,
  196. hInst);
  197. pro.fOutput[IO_FILE] = (fhOutput != NULL);
  198. break;
  199. case WM_INITMENU:
  200. if (GetMenu(hWnd) != (HMENU)wParam)
  201. break;
  202. for (i = 0; i < IO_COUNT; i++) {
  203. CheckMenuItem((HMENU)wParam, IDM_OUTPUT_FIRST + i,
  204. pro.fOutput[i] ? MF_CHECKED : MF_UNCHECKED);
  205. }
  206. for (i = 0; i < IF_COUNT; i++) {
  207. CheckMenuItem((HMENU)wParam, IDM_FILTER_FIRST + i,
  208. pro.fFilter[i] ? MF_CHECKED : MF_UNCHECKED);
  209. }
  210. for (i = 0; i < IT_COUNT; i++) {
  211. CheckMenuItem((HMENU)wParam, IDM_TRACK_FIRST + i,
  212. pro.fTrack[i] ? MF_CHECKED : MF_UNCHECKED);
  213. }
  214. break;
  215. case WM_COMMAND: /* message: command from application menu */
  216. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  217. case IDM_OUTPUT_FILE:
  218. case IDM_OUTPUT_DEBUG:
  219. case IDM_OUTPUT_SCREEN:
  220. switch (wParam) {
  221. case IDM_OUTPUT_FILE:
  222. if (fhOutput != NULL) {
  223. wsprintf(TBuf, RefString(IDS_QCLOSEFILE_TEXT), OpenName);
  224. if (IDYES != MessageBox(hWnd,
  225. TBuf, RefString(IDS_QCLOSEFILE_CAPTION),
  226. MB_YESNO | MB_ICONQUESTION)) {
  227. break;
  228. }
  229. CloseHandle(fhOutput);
  230. }
  231. fhOutput = (HANDLE)DoDialog(
  232. MAKEINTRESOURCE(IDD_OPEN),
  233. (DLGPROC)OpenDlg,
  234. 0,
  235. TRUE,
  236. hWnd,
  237. hInst);
  238. pro.fOutput[IO_FILE] = (fhOutput != NULL);
  239. break;
  240. case IDM_OUTPUT_DEBUG:
  241. pro.fOutput[IO_DEBUG] = !pro.fOutput[IO_DEBUG];
  242. break;
  243. case IDM_OUTPUT_SCREEN:
  244. pro.fOutput[IO_SCREEN] = !pro.fOutput[IO_SCREEN];
  245. break;
  246. }
  247. break;
  248. case IDM_CLEARSCREEN:
  249. if (hWndString) {
  250. HANDLE hpsw;
  251. STRWND *psw;
  252. hpsw = (HANDLE)GetWindowLongPtr(hWndString, 0);
  253. psw = (STRWND *)LocalLock(hpsw);
  254. ClearScreen(psw);
  255. LocalUnlock(hpsw);
  256. InvalidateRect(hWndString, NULL, TRUE);
  257. }
  258. break;
  259. case IDM_MARK:
  260. DoDialog(MAKEINTRESOURCE(IDD_VALUEENTRY), (DLGPROC)MarkDlgProc, 0, TRUE, hWnd, hInst);
  261. break;
  262. case IDM_FILTER_HSZINFO:
  263. case IDM_FILTER_INIT_TERM:
  264. case IDM_FILTER_DDEMSGS:
  265. case IDM_FILTER_CALLBACKS:
  266. case IDM_FILTER_ERRORS:
  267. pro.fFilter[wParam - IDM_FILTER_FIRST] =
  268. !pro.fFilter[wParam - IDM_FILTER_FIRST];
  269. SetFilters();
  270. break;
  271. case IDM_FILTER_DIALOG:
  272. DoDialog(MAKEINTRESOURCE(IDD_MSGFILTERS), (DLGPROC)FilterDlgProc, 0, TRUE, hWnd, hInst);
  273. break;
  274. case IDM_TRACK_HSZS:
  275. case IDM_TRACK_CONVS:
  276. case IDM_TRACK_LINKS:
  277. case IDM_TRACK_SVRS:
  278. pro.fTrack[wParam - IDM_TRACK_FIRST] =
  279. !pro.fTrack[wParam - IDM_TRACK_FIRST];
  280. if (pro.fTrack[wParam - IDM_TRACK_FIRST]) {
  281. hwndTrack[wParam - IDM_TRACK_FIRST] = CreateMCLBFrame(
  282. NULL,
  283. TrackTitle[wParam - IDM_TRACK_FIRST],
  284. WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_MINIMIZE,
  285. hIcon, (HBRUSH)(COLOR_APPWORKSPACE + 1),
  286. TrackHeading[wParam - IDM_TRACK_FIRST]);
  287. } else {
  288. DestroyWindow(hwndTrack[wParam - IDM_TRACK_FIRST]);
  289. hwndTrack[wParam - IDM_TRACK_FIRST] = 0;
  290. }
  291. SetFilters();
  292. break;
  293. case IDM_ABOUT:
  294. DoDialog(MAKEINTRESOURCE(IDD_ABOUTBOX), (DLGPROC)About, 0, TRUE, hWnd, hInst);
  295. break;
  296. default:
  297. return (DefWindowProc(hWnd, message, wParam, lParam));
  298. }
  299. break;
  300. case WM_DESTROY: /* message: window being destroyed */
  301. for (i = IDM_TRACK_FIRST; i <= IDM_TRACK_LAST; i++) {
  302. if (pro.fTrack[i - IDM_TRACK_FIRST]) {
  303. DestroyWindow(hwndTrack[i - IDM_TRACK_FIRST]);
  304. hwndTrack[i - IDM_TRACK_FIRST] = 0;
  305. }
  306. }
  307. PostQuitMessage(0);
  308. break;
  309. case WM_SIZE:
  310. if (hWndString) {
  311. RECT rc;
  312. GetClientRect(hWnd, &rc);
  313. MoveWindow(hWndString, 0, 0, rc.right, rc.bottom, TRUE);
  314. }
  315. // fall through
  316. default:
  317. return (DefWindowProc(hWnd, message, wParam, lParam));
  318. }
  319. return (0);
  320. }
  321. BOOL CALLBACK About(
  322. HWND hDlg,
  323. UINT message,
  324. WPARAM wParam,
  325. LPARAM lParam)
  326. {
  327. switch (message) {
  328. case WM_INITDIALOG: /* message: initialize dialog box */
  329. return (TRUE);
  330. case WM_COMMAND: /* message: received a command */
  331. if (GET_WM_COMMAND_ID(wParam, lParam) == IDOK
  332. || GET_WM_COMMAND_ID(wParam, lParam) == IDCANCEL) {
  333. EndDialog(hDlg, TRUE); /* Exits the dialog box */
  334. return (TRUE);
  335. }
  336. break;
  337. }
  338. return (FALSE); /* Didn't process a message */
  339. }
  340. HDDEDATA CALLBACK DdeCallback(
  341. UINT wType,
  342. UINT wFmt,
  343. HCONV hConv,
  344. HSZ hsz1,
  345. HSZ hsz2,
  346. HDDEDATA hData,
  347. UINT dwData1,
  348. UINT dwData2)
  349. {
  350. LPVOID pData;
  351. UINT cb;
  352. TCHAR *psz1, *psz2, *psz3;
  353. TCHAR *szAction;
  354. INT i;
  355. BOOL fInt = FALSE;
  356. wFmt;
  357. hConv;
  358. dwData1;
  359. switch (wType) {
  360. case XTYP_MONITOR:
  361. if (pData = DdeAccessData(hData, (LPDWORD)&cb)) {
  362. switch (dwData2) {
  363. case MF_HSZ_INFO:
  364. if (pro.fTrack[IT_HSZS]) {
  365. switch (((MONHSZSTRUCT FAR *)pData)->fsAction) {
  366. case MH_DELETE:
  367. wsprintf(TBuf, fInt ? TEXT("0x%lx\t*\t%s(int)")
  368. : TEXT("0x%lx\t*\t%s"),
  369. ((MONHSZSTRUCT FAR *)pData)->hsz,
  370. (LPTSTR)((MONHSZSTRUCT FAR *)pData)->str);
  371. i = GetMCLBColValue(TBuf, hwndTrack[IT_HSZS], 2);
  372. if (i > 1) {
  373. wsprintf(TBuf2, fInt ? TEXT("0x%lx\t%d\t%s(int)")
  374. : TEXT("0x%lx\t%d\t%s"),
  375. ((MONHSZSTRUCT FAR *)pData)->hsz,
  376. i - 1,
  377. (LPTSTR)((MONHSZSTRUCT FAR *)pData)->str);
  378. AddMCLBText(TBuf, TBuf2, hwndTrack[IT_HSZS]);
  379. } else if (i == 1) {
  380. DeleteMCLBText(TBuf, hwndTrack[IT_HSZS]);
  381. }
  382. break;
  383. case MH_KEEP:
  384. case MH_CREATE:
  385. wsprintf(TBuf, fInt ? TEXT("0x%lx\t*\t%s(int)")
  386. : TEXT("0x%lx\t*\t%s"),
  387. ((MONHSZSTRUCT FAR *)pData)->hsz,
  388. (LPTSTR)((MONHSZSTRUCT FAR *)pData)->str);
  389. i = GetMCLBColValue(TBuf, hwndTrack[IT_HSZS], 2) + 1;
  390. wsprintf(TBuf2, fInt ? TEXT("0x%lx\t%d\t%s(int)")
  391. : TEXT("0x%lx\t%d\t%s"),
  392. ((MONHSZSTRUCT FAR *)pData)->hsz,
  393. i,
  394. (LPTSTR)((MONHSZSTRUCT FAR *)pData)->str);
  395. AddMCLBText(TBuf, TBuf2, hwndTrack[IT_HSZS]);
  396. }
  397. }
  398. if (!pro.fFilter[IF_HSZ]) {
  399. DdeUnaccessData(hData);
  400. return(0);
  401. }
  402. switch (((MONHSZSTRUCT FAR *)pData)->fsAction) {
  403. case MH_CLEANUP:
  404. szAction = RefString(IDS_ACTION_CLEANEDUP);
  405. break;
  406. case MH_DELETE:
  407. szAction = RefString(IDS_ACTION_DESTROYED);
  408. break;
  409. case MH_KEEP:
  410. szAction = RefString(IDS_ACTION_INCREMENTED);
  411. break;
  412. case MH_CREATE:
  413. szAction = RefString(IDS_ACTION_CREATED);
  414. break;
  415. default:
  416. DdeUnaccessData(hData);
  417. return(0);
  418. }
  419. if (pro.fTerse) {
  420. wsprintf(TBuf, TEXT("[%x:%ld] HSZ %s: %lx(%s)"),
  421. ((MONHSZSTRUCT FAR *)pData)->hTask,
  422. ((MONHSZSTRUCT FAR *)pData)->dwTime,
  423. (LPTSTR)szAction,
  424. ((MONHSZSTRUCT FAR *)pData)->hsz,
  425. (LPTSTR)((MONHSZSTRUCT FAR *)pData)->str);
  426. } else {
  427. wsprintf(TBuf,
  428. /* so we can localize message */
  429. RefString(IDS_FMT_SH_MSG1),
  430. ((MONHSZSTRUCT FAR *)pData)->hTask,
  431. ((MONHSZSTRUCT FAR *)pData)->dwTime,
  432. (LPTSTR)szAction,
  433. ((MONHSZSTRUCT FAR *)pData)->hsz,
  434. (LPTSTR)((MONHSZSTRUCT FAR *)pData)->str);
  435. }
  436. break;
  437. case MF_SENDMSGS:
  438. case MF_POSTMSGS:
  439. if (fBlockMsg[((MONMSGSTRUCT FAR *)pData)->wMsg - WM_DDE_FIRST]) {
  440. DdeUnaccessData(hData);
  441. return(0);
  442. }
  443. if (pro.fTerse) {
  444. wsprintf(TBuf, RefString(IDS_FMT_TRS_MSG1),
  445. ((MONMSGSTRUCT FAR *)pData)->hTask,
  446. ((MONMSGSTRUCT FAR *)pData)->dwTime,
  447. ((MONMSGSTRUCT FAR *)pData)->wParam,
  448. ((MONMSGSTRUCT FAR *)pData)->hwndTo,
  449. (dwData2 == MF_SENDMSGS) ? RefString(IDS_SENT) : RefString(IDS_POSTED),
  450. (LPTSTR)DdeMsg2String(((MONMSGSTRUCT FAR *)pData)->wMsg));
  451. } else {
  452. wsprintf(TBuf, RefString(IDS_FMT_MSG1),
  453. ((MONMSGSTRUCT FAR *)pData)->hTask,
  454. ((MONMSGSTRUCT FAR *)pData)->dwTime,
  455. ((MONMSGSTRUCT FAR *)pData)->hwndTo,
  456. (dwData2 == MF_SENDMSGS) ? RefString(IDS_SENT) : RefString(IDS_POSTED),
  457. (LPTSTR)DdeMsg2String(((MONMSGSTRUCT FAR *)pData)->wMsg));
  458. }
  459. OutputString(TBuf);
  460. wsprintf(TBuf, pro.fTerse ? RefString(IDS_FMT_TRS_MSG2) : RefString(IDS_FMT_MSG2),
  461. ((MONMSGSTRUCT FAR *)pData)->wParam);
  462. DisectMsgLP(((MONMSGSTRUCT FAR *)pData)->wMsg,
  463. ((MONMSGSTRUCT FAR *)pData),
  464. &TBuf[lstrlen(TBuf)]);
  465. break;
  466. case MF_CALLBACKS:
  467. if (fBlockCb[(((MONCBSTRUCT FAR *)pData)->wType & XTYP_MASK) >> XTYP_SHIFT]) {
  468. DdeUnaccessData(hData);
  469. return(0);
  470. }
  471. wsprintf(TBuf,
  472. pro.fTerse ? RefString(IDS_FMT_TRS_CB1) : RefString(IDS_FMT_CB1),
  473. ((MONCBSTRUCT FAR *)pData)->hTask,
  474. ((MONCBSTRUCT FAR *)pData)->dwTime,
  475. (LPTSTR)Type2String(((MONCBSTRUCT FAR *)pData)->wType));
  476. wsprintf(DumpFormat(((MONCBSTRUCT FAR *)pData)->wFmt, &TBuf[lstrlen(TBuf)]),
  477. pro.fTerse ? RefString(IDS_FMT_TRS_CB2) : RefString(IDS_FMT_CB2),
  478. (UINT_PTR)((MONCBSTRUCT FAR *)pData)->hConv,
  479. ((MONCBSTRUCT FAR *)pData)->hsz1,
  480. (LPTSTR)(psz1 = GetHszName(((MONCBSTRUCT FAR *)pData)->hsz1)),
  481. ((MONCBSTRUCT FAR *)pData)->hsz2,
  482. (LPTSTR)(psz2 = GetHszName(((MONCBSTRUCT FAR *)pData)->hsz2)),
  483. ((MONCBSTRUCT FAR *)pData)->hData,
  484. ((MONCBSTRUCT FAR *)pData)->dwData1,
  485. ((MONCBSTRUCT FAR *)pData)->dwData2,
  486. ((MONCBSTRUCT FAR *)pData)->dwRet);
  487. MyFree(psz1);
  488. MyFree(psz2);
  489. OutputString(TBuf);
  490. if (((MONCBSTRUCT FAR *)pData)->dwData1 &&
  491. (((MONCBSTRUCT FAR *)pData)->wType == XTYP_CONNECT ||
  492. ((MONCBSTRUCT FAR *)pData)->wType == XTYP_WILDCONNECT)) {
  493. // display proposed context
  494. wsprintf(TBuf,
  495. pro.fTerse ? RefString(IDS_FMT_TRS_CTXT1) : RefString(IDS_FMT_CTXT1),
  496. ((MONCBSTRUCT FAR *)pData)->cc.wFlags,
  497. ((MONCBSTRUCT FAR *)pData)->cc.wCountryID,
  498. ((MONCBSTRUCT FAR *)pData)->cc.iCodePage,
  499. ((MONCBSTRUCT FAR *)pData)->cc.dwLangID,
  500. ((MONCBSTRUCT FAR *)pData)->cc.dwSecurity,
  501. ((MONCBSTRUCT FAR *)pData)->cc.qos.ImpersonationLevel,
  502. ((MONCBSTRUCT FAR *)pData)->cc.qos.ContextTrackingMode,
  503. ((MONCBSTRUCT FAR *)pData)->cc.qos.EffectiveOnly);
  504. OutputString(TBuf);
  505. }
  506. if (((MONCBSTRUCT FAR *)pData)->hData && ((MONCBSTRUCT FAR *)pData)->cbData) {
  507. wsprintf(TBuf, RefString(IDS_INPUT_DATA));
  508. OutputString(TBuf);
  509. DumpData((LPBYTE)((MONCBSTRUCT FAR *)pData)->Data,
  510. ((MONCBSTRUCT FAR *)pData)->cbData,
  511. TBuf,
  512. ((MONCBSTRUCT FAR *)pData)->wFmt);
  513. OutputString(TBuf);
  514. if (cb > MAX_DISPDATA)
  515. OutputString(RefString(IDS_TABDDD));
  516. // DdeUnaccessData(((MONCBSTRUCT FAR *)pData)->hData);
  517. }
  518. if ((((MONCBSTRUCT FAR *)pData)->wType & XCLASS_DATA) &&
  519. ((MONCBSTRUCT FAR *)pData)->dwRet &&
  520. ((MONCBSTRUCT FAR *)pData)->cbData) {
  521. wsprintf(TBuf, RefString(IDS_OUTPUT_DATA));
  522. OutputString(TBuf);
  523. DumpData((LPBYTE)((MONCBSTRUCT FAR *)pData)->Data,
  524. ((MONCBSTRUCT FAR *)pData)->cbData,
  525. TBuf,
  526. ((MONCBSTRUCT FAR *)pData)->wFmt);
  527. OutputString(TBuf);
  528. if (cb > MAX_DISPDATA)
  529. OutputString(RefString(IDS_TABDDD));
  530. // DdeUnaccessData(((MONCBSTRUCT FAR *)pData)->dwRet);
  531. }
  532. DdeUnaccessData(hData);
  533. return(0);
  534. break;
  535. case MF_ERRORS:
  536. wsprintf(TBuf, pro.fTerse ? RefString(IDS_FMT_TRS_ER1) : RefString(IDS_FMT_ER1),
  537. ((MONERRSTRUCT FAR *)pData)->hTask,
  538. ((MONERRSTRUCT FAR *)pData)->dwTime,
  539. ((MONERRSTRUCT FAR *)pData)->wLastError,
  540. (LPTSTR)Error2String(((MONERRSTRUCT FAR *)pData)->wLastError));
  541. break;
  542. case MF_LINKS:
  543. psz1 = GetHszName(((MONLINKSTRUCT FAR *)pData)->hszSvc);
  544. psz2 = GetHszName(((MONLINKSTRUCT FAR *)pData)->hszTopic);
  545. psz3 = GetHszName(((MONLINKSTRUCT FAR *)pData)->hszItem);
  546. if (!GetClipboardFormatName(((MONLINKSTRUCT FAR *)pData)->wFmt, TBuf2, BUFFER_SIZE))
  547. lstrcpy(TBuf2, pdf(((MONLINKSTRUCT FAR *)pData)->wFmt));
  548. if (!lstrcmp(RefString(IDS_HUH), TBuf2)) {
  549. wsprintf(TBuf2, TEXT("%d"), ((MONLINKSTRUCT FAR *)pData)->wFmt);
  550. }
  551. wsprintf(TBuf, TEXT("%s\t%s\t%s\t%s\t%s\t%lx\t%lx"),
  552. (LPTSTR)psz1, (LPTSTR)psz2, (LPTSTR)psz3,
  553. (LPTSTR)TBuf2,
  554. ((MONLINKSTRUCT FAR *)pData)->fNoData ?
  555. RefString(IDS_WARM) : RefString(IDS_HOT),
  556. ((MONLINKSTRUCT FAR *)pData)->hConvClient,
  557. ((MONLINKSTRUCT FAR *)pData)->hConvServer);
  558. if (((MONLINKSTRUCT FAR *)pData)->fEstablished) {
  559. AddMCLBText(TBuf, TBuf, hwndTrack[IT_LINKS]);
  560. } else {
  561. DeleteMCLBText(TBuf, hwndTrack[IT_LINKS]);
  562. }
  563. MyFree(psz1);
  564. MyFree(psz2);
  565. MyFree(psz3);
  566. DdeUnaccessData(hData);
  567. return(0);
  568. case MF_CONV:
  569. psz1 = GetHszName(((MONCONVSTRUCT FAR *)pData)->hszSvc);
  570. psz2 = GetHszName(((MONCONVSTRUCT FAR *)pData)->hszTopic);
  571. wsprintf(TBuf, TEXT("%s\t%s\t%lx\t%lx"),
  572. (LPTSTR)psz1, (LPTSTR)psz2,
  573. ((MONCONVSTRUCT FAR *)pData)->hConvClient,
  574. ((MONCONVSTRUCT FAR *)pData)->hConvServer);
  575. if (((MONCONVSTRUCT FAR *)pData)->fConnect) {
  576. AddMCLBText(TBuf, TBuf, hwndTrack[IT_CONVS]);
  577. } else {
  578. DeleteMCLBText(TBuf, hwndTrack[IT_CONVS]);
  579. }
  580. MyFree(psz1);
  581. MyFree(psz2);
  582. DdeUnaccessData(hData);
  583. return(0);
  584. default:
  585. lstrcpy(TBuf, RefString(IDS_UNKNOWN_CALLBACK));
  586. }
  587. DdeUnaccessData(hData);
  588. OutputString(TBuf);
  589. }
  590. break;
  591. case XTYP_REGISTER:
  592. case XTYP_UNREGISTER:
  593. if (!pro.fTrack[IT_SVRS]) {
  594. return(0);
  595. }
  596. psz1 = GetHszName(hsz1);
  597. psz2 = GetHszName(hsz2);
  598. wsprintf(TBuf, TEXT("%s\t%s"), (LPTSTR)psz1, (LPTSTR)psz2);
  599. if (wType == XTYP_REGISTER) {
  600. AddMCLBText(NULL, TBuf, hwndTrack[IT_SVRS]);
  601. } else {
  602. DeleteMCLBText(TBuf, hwndTrack[IT_SVRS]);
  603. }
  604. MyFree(psz1);
  605. MyFree(psz2);
  606. break;
  607. }
  608. return(0);
  609. }
  610. LPTSTR DisectMsgLP(UINT msg, MONMSGSTRUCT *pmms, LPTSTR pszBuf)
  611. {
  612. static LONG m2t[] = {
  613. /* LOW HIGH */
  614. MAKELONG(T_APP | T_ATOM, T_TOPIC | T_ATOM), // WM_DDE_INITIATE
  615. 0, // WM_DDE_TERMINATE
  616. MAKELONG(T_OPTIONHANDLE, T_ITEM | T_ATOM), // WM_DDE_ADVISE
  617. MAKELONG(T_FORMAT, T_ITEM | T_ATOM), // WM_DDE_UNADVISE
  618. MAKELONG(T_APP | T_ATOM | T_OR | T_STATUS,
  619. T_TOPIC | T_ITEM | T_ATOM | T_OR | T_STRINGHANDLE),
  620. // WM_DDE_ACK
  621. MAKELONG(T_DATAHANDLE, T_ITEM | T_ATOM), // WM_DDE_DATA
  622. MAKELONG(T_FORMAT, T_ITEM | T_ATOM), // WM_DDE_REQUEST
  623. MAKELONG(T_DATAHANDLE, T_ITEM | T_ATOM), // WM_DDE_POKE
  624. MAKELONG(0, T_STRINGHANDLE), // WM_DDE_EXECUTE
  625. };
  626. // ASSUMED: msg is a valid DDE message!!!
  627. pszBuf = DisectWord(LOWORD(m2t[msg - WM_DDE_FIRST]),
  628. (UINT)pmms->dmhd.uiLo, &pmms->dmhd, pszBuf);
  629. *pszBuf++ = TEXT('\r');
  630. *pszBuf++ = TEXT('\n');
  631. *pszBuf++ = TEXT('\t');
  632. return(DisectWord(HIWORD(m2t[msg - WM_DDE_FIRST]),
  633. (UINT)pmms->dmhd.uiHi, &pmms->dmhd, pszBuf));
  634. }
  635. /*
  636. * Allocates local memory for and retrieves the string form of an HSZ.
  637. * Returns a pointer to the local memory or NULL if failure.
  638. * The string must be freed via MyFree().
  639. */
  640. LPTSTR GetHszName(HSZ hsz)
  641. {
  642. LPTSTR psz;
  643. UINT cb;
  644. cb = (UINT)DdeQueryString(idInst, hsz, NULL, 0, 0) + 1;
  645. psz = LocalAlloc (LPTR, sizeof(TCHAR) * cb);
  646. DdeQueryString(idInst, hsz, psz, cb, 0);
  647. return(psz);
  648. }
  649. LPTSTR
  650. DisectWord(
  651. UINT type,
  652. UINT data,
  653. DDEML_MSG_HOOK_DATA *pdmhd,
  654. LPTSTR pstr
  655. )
  656. {
  657. UINT wT;
  658. *pstr = TEXT('\0'); // in case we do nothing.
  659. if (type & T_ATOM) {
  660. wT = GlobalGetAtomName((ATOM)data, (LPTSTR)pstr, 25);
  661. if (wT || data == 0) {
  662. if (type & T_APP) {
  663. lstrcpy(pstr, RefString(IDS_APPIS));
  664. pstr += lstrlen(pstr);
  665. }
  666. if (type & T_TOPIC) {
  667. lstrcpy(pstr, RefString(IDS_TOPICIS));
  668. pstr += lstrlen(pstr);
  669. }
  670. if (type & T_ITEM) {
  671. lstrcpy(pstr, RefString(IDS_ITEMIS));
  672. pstr += lstrlen(pstr);
  673. }
  674. }
  675. if (wT) {
  676. wsprintf(pstr, TEXT("0x%x(\""), data);
  677. pstr += lstrlen(pstr);
  678. GlobalGetAtomName((ATOM)data, (LPTSTR)pstr, 25);
  679. pstr += wT;
  680. if (wT == 25) {
  681. *pstr++ = TEXT('.');
  682. *pstr++ = TEXT('.');
  683. *pstr++ = TEXT('.');
  684. }
  685. *pstr++ = TEXT('\"');
  686. *pstr++ = TEXT(')');
  687. *pstr = TEXT('\0');
  688. type &= ~(T_OR | T_STRINGHANDLE); // its an atom, so its not an object!
  689. } else if (data == 0) { // could be a wild atom
  690. *pstr++ = TEXT('*');
  691. *pstr = TEXT('\0');
  692. } else if (type & T_OR) {
  693. type &= ~T_OR; // not an atom, must be somthin else.
  694. } else {
  695. /* so we can localize message */
  696. wsprintf(pstr, RefString(IDS_BADATOM), data);
  697. pstr += lstrlen(pstr);
  698. }
  699. }
  700. if (type & T_OR) {
  701. lstrcpy(pstr, RefString(IDS_OR));
  702. pstr += lstrlen(pstr);
  703. }
  704. if (type & T_OPTIONHANDLE) {
  705. if (pdmhd->cbData >= 4) {
  706. wsprintf(pstr, pro.fTerse ? RefString(IDS_FMT_TRS_STATUSIS) : RefString(IDS_FMT_STATUSIS), LOWORD(pdmhd->Data[0]));
  707. pstr += lstrlen(pstr);
  708. if (LOWORD(pdmhd->Data[0]) & DDE_FACKREQ) {
  709. lstrcpy(pstr, RefString(IDS_FACKREQ));
  710. pstr += lstrlen(pstr);
  711. }
  712. if (LOWORD(pdmhd->Data[0]) & DDE_FDEFERUPD) {
  713. lstrcpy(pstr, RefString(IDS_DEFERUPD));
  714. pstr += lstrlen(pstr);
  715. }
  716. *pstr++ = TEXT(')');
  717. *pstr++ = TEXT(' ');
  718. pstr = DumpFormat((UINT)HIWORD(pdmhd->Data[0]), pstr);
  719. }
  720. }
  721. if (type & T_FORMAT) {
  722. pstr = DumpFormat(data, pstr);
  723. }
  724. if (type & T_STATUS) {
  725. wsprintf(pstr, pro.fTerse ? RefString(IDS_FMT_TRS_STATUSIS) : RefString(IDS_FMT_STATUSIS), LOWORD(data));
  726. pstr += lstrlen(pstr);
  727. if (data & DDE_FACK) {
  728. lstrcpy(pstr, RefString(IDS_FACK));
  729. pstr += lstrlen(pstr);
  730. }
  731. if (data & DDE_FBUSY) {
  732. lstrcpy(pstr, RefString(IDS_FBUSY));
  733. pstr += lstrlen(pstr);
  734. }
  735. *pstr++ = TEXT(')');
  736. *pstr = TEXT('\0');
  737. }
  738. if (type & T_STRINGHANDLE && pdmhd->cbData) {
  739. WCHAR szData[16];
  740. memset(szData, '\0', 16 * sizeof(WCHAR));
  741. memcpy(szData, pdmhd->Data, min(16 * sizeof(WCHAR), pdmhd->cbData));
  742. szData[15] = L'\0';
  743. wsprintf(pstr, pro.fTerse ?
  744. RefString(IDS_FMT_TRS_EXEC1) : RefString(IDS_FMT_EXEC1), (LPWSTR)szData);
  745. pstr += lstrlen(pstr);
  746. *pstr = TEXT('\0');
  747. }
  748. if (type & T_DATAHANDLE && pdmhd->cbData) {
  749. wsprintf(pstr, pro.fTerse ?
  750. RefString(IDS_FMT_TRS_STATUSIS) : RefString(IDS_FMT_STATUSIS),
  751. LOWORD(pdmhd->Data[0]));
  752. pstr += lstrlen(pstr);
  753. if (LOWORD(pdmhd->Data[0]) & DDE_FRELEASE) {
  754. lstrcpy(pstr, RefString(IDS_FRELEASE));
  755. pstr += lstrlen(pstr);
  756. }
  757. if (LOWORD(pdmhd->Data[0]) & DDE_FREQUESTED) {
  758. lstrcpy(pstr, RefString(IDS_FREQUESTED));
  759. pstr += lstrlen(pstr);
  760. }
  761. *pstr++ = TEXT(')');
  762. *pstr++ = TEXT(' ');
  763. pstr = DumpFormat(HIWORD(pdmhd->Data[0]), pstr);
  764. lstrcpy(pstr, pro.fTerse ? RefString(IDS_FMT_TRS_DATAIS1) : RefString(IDS_FMT_DATAIS1));
  765. pstr += lstrlen(pstr);
  766. pstr = DumpData((LPBYTE)&pdmhd->Data[1], min(28, pdmhd->cbData - 4),
  767. pstr, HIWORD(pdmhd->Data[0]));
  768. }
  769. return(pstr);
  770. }
  771. LPTSTR pdf(UINT fmt)
  772. {
  773. INT i;
  774. static struct {
  775. UINT fmt;
  776. LPTSTR psz;
  777. } fmts[] = {
  778. { CF_TEXT , TEXT("CF_TEXT") } ,
  779. { CF_UNICODETEXT , TEXT("CF_UNICODETEXT") } ,
  780. { CF_BITMAP , TEXT("CF_BITMAP") } ,
  781. { CF_METAFILEPICT , TEXT("CF_METAFILEPICT") } ,
  782. { CF_ENHMETAFILE , TEXT("CF_ENHMETAFILE") } ,
  783. { CF_SYLK , TEXT("CF_SYLK") } ,
  784. { CF_DIF , TEXT("CF_DIF") } ,
  785. { CF_TIFF , TEXT("CF_TIFF") } ,
  786. { CF_OEMTEXT , TEXT("CF_OEMTEXT") } ,
  787. { CF_DIB , TEXT("CF_DIB") } ,
  788. { CF_PALETTE , TEXT("CF_PALETTE") } ,
  789. };
  790. for (i = 0; i < 10; i++)
  791. if (fmts[i].fmt == fmt)
  792. return(fmts[i].psz);
  793. return(RefString(IDS_HUH));
  794. }
  795. LPTSTR DumpFormat(UINT fmt, LPTSTR pstr)
  796. {
  797. UINT cb;
  798. wsprintf(pstr, TEXT("fmt=0x%x(\""), (WORD)fmt);
  799. pstr += lstrlen(pstr);
  800. if (cb = GetClipboardFormatName(fmt, pstr, 25)) {
  801. pstr += cb;
  802. *pstr++ = TEXT('\"');
  803. *pstr++ = TEXT(')');
  804. } else {
  805. wsprintf(pstr, TEXT("%s\")"), (LPTSTR)pdf(fmt));
  806. pstr += lstrlen(pstr);
  807. }
  808. return(pstr);
  809. }
  810. LPTSTR DumpData(LPBYTE pData, UINT cb, TCHAR *szBuf, UINT fmt)
  811. {
  812. register INT i;
  813. LPTSTR psz = szBuf;
  814. while (cb) {
  815. if (fmt == CF_TEXT || fmt == CF_UNICODETEXT) {
  816. *szBuf++ = TEXT('\t');
  817. if (fmt == CF_UNICODETEXT) {
  818. *szBuf++ = TEXT('U');
  819. }
  820. *szBuf++ = TEXT('\"');
  821. if (fmt == CF_UNICODETEXT) {
  822. memcpy(szBuf, pData, cb);
  823. } else {
  824. MultiByteToWideChar(CP_ACP, 0, pData, cb, szBuf, cb / sizeof(TCHAR));
  825. }
  826. szBuf[cb - 2] = TEXT('\0');
  827. lstrcat(szBuf, TEXT("\""));
  828. cb = 0;
  829. } else {
  830. for (i = 0; i < 80 ; i++) {
  831. szBuf[i] = TEXT(' ');
  832. }
  833. szBuf[0] = TEXT('\t');
  834. i = 0;
  835. while (cb && (i < 16)) {
  836. wsprintf(&szBuf[i * 3 + 1], TEXT("%02x "), pData[0]);
  837. wsprintf(&szBuf[17 * 3 + i + 1], TEXT("%c"), MPRT(pData[0]));
  838. pData++;
  839. cb--;
  840. i++;
  841. }
  842. szBuf[i * 3 + 1] = TEXT(' ');
  843. szBuf[17 * 3 + i + 1] = TEXT(' ');
  844. szBuf[68] = TEXT('\0');
  845. }
  846. szBuf += lstrlen(szBuf);
  847. }
  848. return(szBuf);
  849. }
  850. LPTSTR Error2String(UINT error)
  851. {
  852. static TCHAR szErr[23];
  853. if (error == 0) {
  854. lstrcpy(szErr, RefString(IDS_ZERO));
  855. } else if (error > DMLERR_LAST || error < DMLERR_FIRST) {
  856. lstrcpy(szErr, RefString(IDS_HUH));
  857. } else {
  858. lstrcpy(szErr, apszResources[IDS_ERRST0 + error - DMLERR_FIRST]);
  859. }
  860. return(szErr);
  861. }
  862. LPTSTR DdeMsg2String(UINT msg)
  863. {
  864. static TCHAR szBadMsg[10];
  865. if (msg < WM_DDE_FIRST || msg > WM_DDE_LAST) {
  866. wsprintf (szBadMsg, TEXT("%ld"), szBadMsg);
  867. return (szBadMsg);
  868. // return((LPTSTR)itoa(msg, szBadMsg, 10));
  869. } else {
  870. return(apszResources[IDS_MSG0 + msg - WM_DDE_FIRST]);
  871. }
  872. }
  873. VOID OutputString(LPTSTR pstr)
  874. {
  875. DWORD cbWritten;
  876. if (pro.fOutput[IO_FILE] && fhOutput != NULL) {
  877. static CHAR szT[200];
  878. WideCharToMultiByte(
  879. CP_ACP,
  880. 0,
  881. pstr,
  882. -1,
  883. szT,
  884. 200,
  885. NULL,
  886. NULL);
  887. WriteFile(fhOutput, (LPCSTR) szT, lstrlenA(szT), &cbWritten, NULL);
  888. WriteFile(fhOutput, (LPCSTR) "\r\n", 2, &cbWritten, NULL);
  889. FlushFileBuffers(fhOutput);
  890. }
  891. if (pro.fOutput[IO_DEBUG]) {
  892. OutputDebugString((LPTSTR)pstr);
  893. OutputDebugString(RefString(IDS_CRLF));
  894. }
  895. if (pro.fOutput[IO_SCREEN]) {
  896. if (IsWindow(hWndString))
  897. DrawString(hWndString, pstr);
  898. }
  899. }
  900. BOOL SetFilters()
  901. {
  902. UINT cbf;
  903. cbf = 0;
  904. if (pro.fTrack[IT_HSZS] || pro.fFilter[IF_HSZ])
  905. cbf |= MF_HSZ_INFO;
  906. if (pro.fTrack[IT_LINKS])
  907. cbf |= MF_LINKS;
  908. if (pro.fTrack[IT_CONVS])
  909. cbf |= MF_CONV;
  910. if (pro.fFilter[IF_SEND])
  911. cbf |= MF_SENDMSGS;
  912. if (pro.fFilter[IF_POST])
  913. cbf |= MF_POSTMSGS;
  914. if (pro.fFilter[IF_CB])
  915. cbf |= MF_CALLBACKS;
  916. if (pro.fFilter[IF_ERR])
  917. cbf |= MF_ERRORS;
  918. return((BOOL)DdeInitialize(&idInst, pfnDdeCallback, APPCLASS_MONITOR | cbf, 0));
  919. }
  920. /*
  921. * This dialog returns a file handle to the opened file name given or NULL
  922. * if cancel.
  923. */
  924. BOOL CALLBACK OpenDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  925. {
  926. HANDLE fh;
  927. lParam;
  928. switch (message) {
  929. case WM_INITDIALOG:
  930. SetDlgItemText(hDlg, IDC_EDIT, (LPTSTR)OpenName);
  931. SendDlgItemMessage(hDlg, IDC_EDIT, EM_SETSEL,
  932. GET_EM_SETSEL_MPS(0, 0x7fff));
  933. SetFocus(GetDlgItem(hDlg, IDC_EDIT));
  934. return (FALSE); /* Indicates the focus is set to a control */
  935. break;
  936. case WM_COMMAND:
  937. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  938. case IDOK:
  939. GetDlgItemText(hDlg, IDC_EDIT, TBuf, MAX_FNAME);
  940. GetFullPathName(TBuf, sizeof(OpenName), OpenName, (LPTSTR *)TBuf2);
  941. fh = CreateFile(
  942. OpenName,
  943. GENERIC_WRITE,
  944. FILE_SHARE_READ,
  945. (PSECURITY_ATTRIBUTES)NULL,
  946. CREATE_ALWAYS,
  947. FILE_ATTRIBUTE_NORMAL,
  948. NULL);
  949. if (fh == INVALID_HANDLE_VALUE) {
  950. MessageBox(hDlg, RefString(IDS_INVALID_FNAME),
  951. NULL, MB_OK | MB_ICONHAND);
  952. return (TRUE);
  953. }
  954. EndDialog(hDlg, (INT_PTR)fh);
  955. return (TRUE);
  956. case IDCANCEL:
  957. EndDialog(hDlg, 0);
  958. return (FALSE);
  959. }
  960. break;
  961. }
  962. return FALSE;
  963. }
  964. BOOL CALLBACK FilterDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  965. {
  966. int i;
  967. lParam;
  968. switch (message) {
  969. case WM_INITDIALOG:
  970. for (i = IDRB_WM_DDE_INITIATE; i <= IDRB_WM_DDE_EXECUTE; i++) {
  971. CheckDlgButton(hDlg, i, !fBlockMsg[i - IDRB_WM_DDE_INITIATE]);
  972. }
  973. for (i = IDRB_XTYP_ERROR; i <= IDRB_XTYP_WILDCONNECT; i++) {
  974. CheckDlgButton(hDlg, i, !fBlockCb[i - IDRB_XTYP_ERROR]);
  975. }
  976. CheckDlgButton(hDlg, IDRB_TERSE, pro.fTerse);
  977. return TRUE;
  978. break;
  979. case WM_COMMAND:
  980. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  981. case IDOK:
  982. for (i = IDRB_WM_DDE_INITIATE; i <= IDRB_WM_DDE_EXECUTE; i++) {
  983. fBlockMsg[i - IDRB_WM_DDE_INITIATE] = !IsDlgButtonChecked(hDlg, i);
  984. }
  985. for (i = IDRB_XTYP_ERROR; i <= IDRB_XTYP_WILDCONNECT; i++) {
  986. fBlockCb[i - IDRB_XTYP_ERROR] = !IsDlgButtonChecked(hDlg, i);
  987. }
  988. pro.fTerse = IsDlgButtonChecked(hDlg, IDRB_TERSE);
  989. EndDialog(hDlg, TRUE);
  990. break;
  991. case IDCANCEL:
  992. EndDialog(hDlg, 0);
  993. break;
  994. }
  995. break;
  996. }
  997. return FALSE;
  998. }
  999. VOID GetProfile()
  1000. {
  1001. pro.fOutput[IO_FILE] = GetProfileBoolean(RefString(IDS_PROF_OUT_FILE),FALSE);
  1002. pro.fOutput[IO_DEBUG] = GetProfileBoolean(RefString(IDS_PROF_OUT_DEBUG),FALSE);
  1003. pro.fOutput[IO_SCREEN] = GetProfileBoolean(RefString(IDS_PROF_OUT_SCREEN),FALSE);
  1004. pro.fFilter[IF_HSZ] = GetProfileBoolean(RefString(IDS_PROF_MONITOR_STRINGHANDLES),FALSE);
  1005. pro.fFilter[IF_SEND] = GetProfileBoolean(RefString(IDS_PROF_MONITOR_INITIATES), FALSE);
  1006. pro.fFilter[IF_POST] = GetProfileBoolean(RefString(IDS_PROF_MONITOR_DDE_MESSAGES), FALSE);
  1007. pro.fFilter[IF_CB] = GetProfileBoolean(RefString(IDS_PROF_MONITOR_CALLBACKS), FALSE);
  1008. pro.fFilter[IF_ERR] = GetProfileBoolean(RefString(IDS_PROF_MONITOR_ERRORS),FALSE);
  1009. pro.fTrack[IT_HSZS] = GetProfileBoolean(RefString(IDS_PROF_TRACK_STRINGHANDLES), FALSE);
  1010. pro.fTrack[IT_LINKS] = GetProfileBoolean(RefString(IDS_PROF_TRACK_LINKS), FALSE);
  1011. pro.fTrack[IT_CONVS] = GetProfileBoolean(RefString(IDS_PROF_TRACK_CONVERSATIONS), FALSE);
  1012. pro.fTrack[IT_SVRS] = GetProfileBoolean(RefString(IDS_PROF_TRACK_SERVICES), FALSE);
  1013. pro.fTerse = GetProfileBoolean(RefString(IDS_PROF_TERSE), FALSE);
  1014. }
  1015. VOID SaveProfile()
  1016. {
  1017. SetProfileBoolean(RefString(IDS_PROF_OUT_FILE), pro.fOutput[IO_FILE] );
  1018. SetProfileBoolean(RefString(IDS_PROF_OUT_DEBUG), pro.fOutput[IO_DEBUG] );
  1019. SetProfileBoolean(RefString(IDS_PROF_OUT_SCREEN), pro.fOutput[IO_SCREEN]);
  1020. SetProfileBoolean(RefString(IDS_PROF_MONITOR_STRINGHANDLES), pro.fFilter[IF_HSZ] );
  1021. SetProfileBoolean(RefString(IDS_PROF_MONITOR_INITIATES), pro.fFilter[IF_SEND] );
  1022. SetProfileBoolean(RefString(IDS_PROF_MONITOR_DDE_MESSAGES), pro.fFilter[IF_POST] );
  1023. SetProfileBoolean(RefString(IDS_PROF_MONITOR_CALLBACKS), pro.fFilter[IF_CB] );
  1024. SetProfileBoolean(RefString(IDS_PROF_MONITOR_ERRORS), pro.fFilter[IF_ERR] );
  1025. SetProfileBoolean(RefString(IDS_PROF_TRACK_STRINGHANDLES), pro.fTrack[IT_HSZS] );
  1026. SetProfileBoolean(RefString(IDS_PROF_TRACK_LINKS), pro.fTrack[IT_LINKS] );
  1027. SetProfileBoolean(RefString(IDS_PROF_TRACK_CONVERSATIONS), pro.fTrack[IT_CONVS] );
  1028. SetProfileBoolean(RefString(IDS_PROF_TRACK_SERVICES), pro.fTrack[IT_SVRS] );
  1029. SetProfileBoolean(RefString(IDS_PROF_TERSE), pro.fTerse );
  1030. }
  1031. BOOL GetProfileBoolean(LPTSTR pszKey, BOOL fDefault)
  1032. {
  1033. GetPrivateProfileString(RefString(IDS_TITLE), pszKey,
  1034. fDefault ? RefString(IDS_YES) : RefString(IDS_NO), TBuf,
  1035. sizeof(TBuf), RefString(IDS_INIFNAME));
  1036. return(lstrcmpi(RefString(IDS_NO), TBuf));
  1037. }
  1038. VOID SetProfileBoolean(LPTSTR pszKey, BOOL fSet)
  1039. {
  1040. WritePrivateProfileString(RefString(IDS_TITLE), pszKey,
  1041. fSet ? RefString(IDS_YES) : RefString(IDS_NO),
  1042. RefString(IDS_INIFNAME));
  1043. }
  1044. /*
  1045. * Generic dialog invocation routine. Handles procInstance stuff and param
  1046. * passing.
  1047. */
  1048. INT_PTR FAR
  1049. DoDialog(
  1050. LPTSTR lpTemplateName,
  1051. DLGPROC lpDlgProc,
  1052. UINT param,
  1053. BOOL fRememberFocus,
  1054. HWND hwndParent,
  1055. HANDLE hInst
  1056. )
  1057. {
  1058. UINT wRet;
  1059. HWND hwndFocus;
  1060. if (fRememberFocus)
  1061. hwndFocus = GetFocus();
  1062. lpDlgProc = (DLGPROC)MakeProcInstance(lpDlgProc, hInst);
  1063. wRet = (UINT)DialogBoxParam(hInst, (LPCTSTR)lpTemplateName, hwndParent, lpDlgProc, param);
  1064. FreeProcInstance((FARPROC)lpDlgProc);
  1065. if (fRememberFocus)
  1066. SetFocus(hwndFocus);
  1067. return wRet;
  1068. }
  1069. BOOL CALLBACK MarkDlgProc(
  1070. HWND hwnd,
  1071. UINT msg,
  1072. WPARAM wParam,
  1073. LPARAM lParam)
  1074. {
  1075. TCHAR szT[MAX_MARK + 1];
  1076. lParam;
  1077. switch (msg){
  1078. case WM_INITDIALOG:
  1079. SetWindowText(hwnd, RefString(IDS_MARKDLGTITLE));
  1080. SendDlgItemMessage(hwnd, IDEF_VALUE, EM_LIMITTEXT, MAX_MARK, 0);
  1081. SetDlgItemText(hwnd, IDEF_VALUE, RefString(IDS_SEPERATOR));
  1082. SetDlgItemText(hwnd, IDTX_VALUE, RefString(IDS_MARKTEXT));
  1083. return(1);
  1084. break;
  1085. case WM_COMMAND:
  1086. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  1087. case IDOK:
  1088. GetDlgItemText(hwnd, IDEF_VALUE, szT, MAX_MARK);
  1089. OutputString(szT);
  1090. // fall through
  1091. case IDCANCEL:
  1092. EndDialog(hwnd, 0);
  1093. break;
  1094. default:
  1095. return(FALSE);
  1096. }
  1097. break;
  1098. }
  1099. return(FALSE);
  1100. }
  1101. #ifdef DBCS
  1102. /****************************************************************************
  1103. My_mbschr: strchr() DBCS version
  1104. ****************************************************************************/
  1105. LPTSTR __cdecl My_mbschr(
  1106. LPTSTR psz, TCHAR uiSep)
  1107. {
  1108. while (*psz != '\0' && *psz != uiSep) {
  1109. psz = CharNext(psz);
  1110. }
  1111. if (*psz == '\0' && uiSep != '\0') {
  1112. return NULL;
  1113. } else {
  1114. return psz;
  1115. }
  1116. }
  1117. #endif