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.

295 lines
7.2 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: DMGMON.C
  3. *
  4. * This module contains functions used for DDE monitor control.
  5. *
  6. * Created: 8/2/88 sanfords
  7. *
  8. * Copyright (c) 1988, 1989 Microsoft Corporation
  9. \***************************************************************************/
  10. #include "ddemlp.h"
  11. long EXPENTRY DdeSendHookProc(
  12. int nCode,
  13. WORD wParam,
  14. LPHMSTRUCT lParam)
  15. {
  16. HDDEDATA hData;
  17. MONMSGSTRUCT FAR *pmsgs;
  18. if (cMonitor && lParam &&
  19. lParam->wMsg >= WM_DDE_FIRST && lParam->wMsg <= WM_DDE_LAST) {
  20. if (hData = allocMonBuf(sizeof(MONMSGSTRUCT), HIWORD(MF_SENDMSGS))) {
  21. pmsgs = (MONMSGSTRUCT FAR *)GlobalLock(HIWORD(hData));
  22. pmsgs->cb = sizeof(MONMSGSTRUCT);
  23. pmsgs->dwTime = GetCurrentTime();
  24. pmsgs->hwndTo = lParam->hWnd;
  25. pmsgs->hTask = GetWindowTask(lParam->hWnd);
  26. pmsgs->wMsg = lParam->wMsg;
  27. pmsgs->wParam = lParam->wParam;
  28. pmsgs->lParam = *(DWORD FAR *)&lParam->hlParam;
  29. MonitorBroadcast(hData, HIWORD(MF_SENDMSGS));
  30. }
  31. }
  32. return DefHookProc(nCode, wParam, (DWORD)lParam, &prevCallHook);
  33. }
  34. long EXPENTRY DdePostHookProc(nCode, wParam, lParam)
  35. int nCode;
  36. WORD wParam;
  37. LPMSG lParam;
  38. {
  39. HDDEDATA hData;
  40. MONMSGSTRUCT FAR *pmsgs;
  41. if (cMonitor && lParam &&
  42. lParam->message >= WM_DDE_FIRST && lParam->message <= WM_DDE_LAST) {
  43. if (hData = allocMonBuf(sizeof(MONMSGSTRUCT), HIWORD(MF_POSTMSGS))) {
  44. pmsgs = (MONMSGSTRUCT FAR *)GlobalLock(HIWORD(hData));
  45. pmsgs->cb = sizeof(MONMSGSTRUCT);
  46. pmsgs->dwTime = lParam->time;
  47. pmsgs->hwndTo = lParam->hwnd;
  48. pmsgs->hTask = GetWindowTask(lParam->hwnd);
  49. pmsgs->wMsg = lParam->message;
  50. pmsgs->wParam = lParam->wParam;
  51. pmsgs->lParam = lParam->lParam;
  52. MonitorBroadcast(hData, HIWORD(MF_POSTMSGS));
  53. }
  54. }
  55. return DefHookProc(nCode, wParam, (DWORD)lParam, &prevMsgHook);
  56. }
  57. VOID MonBrdcastCB(
  58. PAPPINFO pai,
  59. WORD wType,
  60. WORD wFmt,
  61. HCONV hConv,
  62. HSZ hszTopic,
  63. HSZ hszItem,
  64. HDDEDATA hData,
  65. DWORD dwData1,
  66. DWORD dwData2,
  67. DWORD dwRet)
  68. {
  69. MONCBSTRUCT FAR *pcbs;
  70. HDDEDATA hDataBuf;
  71. SEMCHECKOUT();
  72. SEMENTER();
  73. if (pai) {
  74. if (hDataBuf = allocMonBuf(sizeof(MONCBSTRUCT), HIWORD(MF_CALLBACKS))) {
  75. pcbs = (MONCBSTRUCT FAR *)GlobalLock(HIWORD(hDataBuf));
  76. pcbs->cb = sizeof(MONCBSTRUCT);
  77. pcbs->dwTime = GetCurrentTime();
  78. pcbs->hTask = pai->hTask;
  79. pcbs->dwRet = dwRet;
  80. pcbs->wType = wType;
  81. pcbs->wFmt = wFmt;
  82. pcbs->hConv = hConv;
  83. pcbs->hsz1 = hszTopic;
  84. pcbs->hsz2 = hszItem;
  85. pcbs->hData = hData;
  86. pcbs->dwData1 = dwData1;
  87. pcbs->dwData2 = dwData2;
  88. MonitorBroadcast(hDataBuf, HIWORD(MF_CALLBACKS));
  89. }
  90. }
  91. SEMLEAVE();
  92. }
  93. void MonHsz(
  94. ATOM a,
  95. WORD fsAction,
  96. HANDLE hTask)
  97. {
  98. MONHSZSTRUCT FAR *phszs;
  99. HDDEDATA hData;
  100. WORD cb;
  101. if (hData = allocMonBuf(sizeof(MONHSZSTRUCT) + (cb = QueryHszLength((HSZ)a)),
  102. HIWORD(MF_HSZ_INFO))) {
  103. phszs = (MONHSZSTRUCT FAR *)GlobalLock(HIWORD(hData));
  104. phszs->cb = sizeof(MONHSZSTRUCT) + cb + 1;
  105. phszs->dwTime = GetCurrentTime();
  106. phszs->hTask = hTask;
  107. phszs->fsAction = fsAction;
  108. phszs->hsz = (HSZ)a;
  109. QueryHszName((HSZ)a, phszs->str, ++cb);
  110. MonitorBroadcast(hData, HIWORD(MF_HSZ_INFO));
  111. }
  112. }
  113. WORD MonError(
  114. PAPPINFO pai,
  115. WORD error)
  116. {
  117. MONERRSTRUCT FAR *perrs;
  118. HDDEDATA hData;
  119. if (error) {
  120. if (hData = allocMonBuf(sizeof(MONERRSTRUCT), HIWORD(MF_ERRORS))) {
  121. perrs = (MONERRSTRUCT FAR *)GlobalLock(HIWORD(hData));
  122. perrs->cb = sizeof(MONERRSTRUCT);
  123. perrs->dwTime = GetCurrentTime();
  124. perrs->hTask = pai->hTask;
  125. perrs->wLastError = error;
  126. MonitorBroadcast(hData, HIWORD(MF_ERRORS));
  127. }
  128. }
  129. pai->LastError = error;
  130. return(error);
  131. }
  132. VOID MonLink(
  133. PAPPINFO pai,
  134. BOOL fEstablished,
  135. BOOL fNoData,
  136. HSZ hszSvc,
  137. HSZ hszTopic,
  138. HSZ hszItem,
  139. WORD wFmt,
  140. BOOL fServer,
  141. HCONV hConvServer,
  142. HCONV hConvClient)
  143. {
  144. MONLINKSTRUCT FAR *plink;
  145. HDDEDATA hData;
  146. if (hData = allocMonBuf(sizeof(MONLINKSTRUCT), HIWORD(MF_LINKS))) {
  147. plink = (MONLINKSTRUCT FAR *)GlobalLock(HIWORD(hData));
  148. plink->cb = sizeof(MONLINKSTRUCT);
  149. plink->dwTime = GetCurrentTime();
  150. plink->hTask = pai->hTask;
  151. plink->fEstablished = fEstablished;
  152. plink->fNoData = fNoData;
  153. plink->hszSvc = hszSvc;
  154. plink->hszTopic = hszTopic;
  155. plink->hszItem = hszItem;
  156. plink->wFmt = wFmt;
  157. plink->fServer = fServer;
  158. plink->hConvServer = hConvServer;
  159. plink->hConvClient = hConvClient;
  160. MonitorBroadcast(hData, HIWORD(MF_LINKS));
  161. }
  162. }
  163. VOID MonConn(
  164. PAPPINFO pai,
  165. ATOM aApp,
  166. ATOM aTopic,
  167. HWND hwndClient,
  168. HWND hwndServer,
  169. BOOL fConnect)
  170. {
  171. MONCONVSTRUCT FAR *pconv;
  172. HDDEDATA hData;
  173. if (hData = allocMonBuf(sizeof(MONCONVSTRUCT), HIWORD(MF_CONV))) {
  174. pconv = (MONCONVSTRUCT FAR *)GlobalLock(HIWORD(hData));
  175. pconv->cb = sizeof(MONCONVSTRUCT);
  176. pconv->dwTime = GetCurrentTime();
  177. pconv->hTask = pai->hTask;
  178. pconv->hszSvc = (HSZ)aApp;
  179. pconv->hszTopic = (HSZ)aTopic;
  180. pconv->hConvClient = MAKEHCONV(hwndClient);
  181. pconv->hConvServer = MAKEHCONV(hwndServer);
  182. pconv->fConnect = fConnect;
  183. MonitorBroadcast(hData, HIWORD(MF_CONV));
  184. }
  185. }
  186. /*
  187. * This guy sends a UM_MONITOR to all the monitor windows who's filters accept
  188. * the callback.
  189. */
  190. void MonitorBroadcast(
  191. HDDEDATA hData,
  192. WORD filterClass) // set to class of filter or 0
  193. {
  194. PAPPINFO pai;
  195. register WORD i = 0;
  196. SEMCHECKOUT();
  197. SEMENTER();
  198. pai = pAppInfoList;
  199. while (pai && (i < cMonitor)) {
  200. if (pai->hwndMonitor) {
  201. if (filterClass & HIWORD(pai->afCmd)) {
  202. SendMessage(pai->hwndMonitor, UM_MONITOR, filterClass, hData);
  203. }
  204. i++;
  205. }
  206. pai = pai->next;
  207. }
  208. SEMLEAVE();
  209. GlobalUnlock(HIWORD(hData));
  210. GLOBALFREE(HIWORD(hData));
  211. }
  212. HDDEDATA allocMonBuf(
  213. WORD cb,
  214. WORD filter)
  215. {
  216. PAPPINFO pai;
  217. register WORD i;
  218. SEMENTER();
  219. if (cMonitor == 0)
  220. return(FALSE);
  221. pai = pAppInfoList;
  222. i = 0;
  223. while (pai && i < cMonitor) {
  224. if (HIWORD(pai->afCmd) & filter)
  225. return(MAKELONG(HDATA_EXEC, AllocDDESel(0, 0, cb)));
  226. if (pai->afCmd & APPCLASS_MONITOR)
  227. i++;
  228. pai = pai->next;
  229. }
  230. return(NULL);
  231. }
  232. long EXPENTRY MonitorWndProc(hwnd, msg, wP, lP)
  233. HWND hwnd;
  234. WORD msg;
  235. WORD wP;
  236. register DWORD lP;
  237. {
  238. switch (msg) {
  239. case WM_CREATE:
  240. SetWindowWord(hwnd, GWW_PAI, (WORD)LPCREATESTRUCT_GETPAI(lP));
  241. break;
  242. case UM_MONITOR:
  243. /*
  244. * lP = hData
  245. * wP = HIWORD(MF_)
  246. */
  247. DoCallback((PAPPINFO)GetWindowWord(hwnd, GWW_PAI), 0, 0L, 0L, 0, XTYP_MONITOR, lP, 0L, (DWORD)wP << 16);
  248. break;
  249. default:
  250. return(DefWindowProc(hwnd, msg, wP, lP));
  251. break;
  252. }
  253. return(0);
  254. }