home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK10 / MFC / SRC / TRACE.CP$ / trace
Encoding:
Text File  |  1992-03-07  |  4.2 KB  |  160 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and Microsoft
  7. // QuickHelp documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11.  
  12. #include "afxwin.h"
  13. #pragma hdrstop
  14.  
  15. #ifdef AFX_CORE_SEG
  16. #pragma code_seg(AFX_CORE_SEG)
  17. #endif
  18.  
  19. #ifdef _DEBUG       // entire file for debugging
  20.  
  21. #include "trace_.h"
  22. #include <dde.h>
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // Build data tables by including data file three times
  26.  
  27. #define DO(WM_FOO)  static char BASED_CODE sz##WM_FOO[] = #WM_FOO;
  28. #include "tracedat.h"
  29. #undef DO
  30.  
  31. static UINT BASED_CODE allMessages[] =
  32. {
  33. #define DO(WM_FOO)  WM_FOO,
  34. #include "tracedat.h"
  35. #undef DO
  36.     0   /* end of table */
  37. };
  38.  
  39. static LPCSTR BASED_CODE allMessageNames[] =
  40. {
  41. #define DO(WM_FOO)  sz##WM_FOO,
  42. #include "tracedat.h"
  43. #undef DO
  44.     NULL    /* end of table */
  45. };
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // DDE special case
  49.  
  50. static void TraceDDE(LPCSTR lpPrefix, const MSG* pMsg)
  51. {
  52.     if (pMsg->message == WM_DDE_EXECUTE)
  53.     {
  54.         HANDLE hCommands = (HANDLE)HIWORD(pMsg->lParam);
  55.         ASSERT(hCommands != NULL);
  56.  
  57.         LPCSTR lpCommands = (LPCSTR)::GlobalLock(hCommands);
  58.         ASSERT(lpCommands != NULL);
  59.         TRACE("%Fs: Execute '%Fs'\n", lpPrefix, lpCommands);
  60.         ::GlobalUnlock(hCommands);
  61.     }
  62.     else if (pMsg->message == WM_DDE_ADVISE)
  63.     {
  64.         ATOM aItem = HIWORD(pMsg->lParam);
  65.         HANDLE hAdvise = (HANDLE)LOWORD(pMsg->lParam);
  66.         ASSERT(hAdvise != NULL);
  67.  
  68.         DDEADVISE FAR* lpAdvise = (DDEADVISE FAR *)::GlobalLock(hAdvise);
  69.         ASSERT(lpAdvise != NULL);                   
  70.         char szItem[80];
  71.         szItem[0] = '\0';
  72.  
  73.         if (aItem != 0)
  74.             ::GlobalGetAtomName(aItem, szItem, sizeof(szItem));
  75.  
  76.         char szFormat[80];
  77.         szFormat[0] = '\0';
  78.         if ((0xC000 <= lpAdvise->cfFormat) && (lpAdvise->cfFormat <= 0xFFFF))
  79.             ::GetClipboardFormatName(lpAdvise->cfFormat,
  80.                 szFormat, sizeof(szFormat));
  81.  
  82.             // User defined clipboard formats have a range of 0xC000->0xFFFF
  83.             // System clipboard formats have other ranges, but no printable
  84.             // format names.
  85.  
  86.  
  87.         TRACE("%Fs: Advise item='%s', Format='%s', Ack=%d, Defer Update= %d\n",
  88.             lpPrefix, szItem, szFormat, lpAdvise->fAckReq, lpAdvise->fDeferUpd);
  89.         ::GlobalUnlock(hAdvise);
  90.     }
  91. }
  92.  
  93. /////////////////////////////////////////////////////////////////////////////
  94.  
  95. void AfxTraceMsg(LPCSTR lpPrefix, const MSG* pMsg)
  96. {
  97.     if (pMsg->message == WM_MOUSEMOVE || pMsg->message == WM_NCMOUSEMOVE ||
  98.        pMsg->message == WM_NCHITTEST ||
  99.        pMsg->message == WM_SETCURSOR ||
  100.        pMsg->message == WM_CTLCOLOR ||
  101.        pMsg->message == WM_ENTERIDLE)
  102.     {
  103.         // never report mouse moves (too frequent) or other messages also
  104.         //   sent as part of mouse movement
  105.         return;
  106.     }
  107.  
  108.     LPCSTR lpMsgName = NULL;
  109.     char szBuf[80];
  110.  
  111.     // find message name
  112.     if (pMsg->message >= 0xC000)
  113.     {
  114.         // Window message registered with 'RegisterWindowMessage'
  115.         //  (actually a USER atom)
  116.         if (::GetClipboardFormatName(pMsg->message, szBuf, sizeof(szBuf)) != 0)
  117.             lpMsgName = szBuf;
  118.     }
  119.     else if (pMsg->message >= WM_USER)
  120.     {
  121.         // User message
  122.         sprintf(szBuf, "WM_USER+0x%04X", pMsg->message - WM_USER);
  123.         lpMsgName = szBuf;
  124.     }
  125.     else
  126.     {
  127.         // a system windows message
  128.         const UINT FAR* lpMessage;
  129.         for (lpMessage = allMessages; *lpMessage != 0; lpMessage++)
  130.         {
  131.             if (*lpMessage == pMsg->message)
  132.             {
  133.                 int iMsg = lpMessage - (const UINT FAR*)allMessages;
  134.                 lpMsgName = allMessageNames[iMsg];
  135.                 break;
  136.             }
  137.         }
  138.     }
  139.  
  140.     if (lpMsgName != NULL)
  141.     {
  142.         TRACE("%Fs: hwnd=0x%04x, msg = %Fs (0x%04x, 0x%08x)\n", lpPrefix,
  143.             pMsg->hwnd, lpMsgName, pMsg->wParam, pMsg->lParam);
  144.     }
  145.     else
  146.     {
  147.         TRACE("%Fs: hwnd=0x%04x, msg = 0x%04x (0x%04x, 0x%08x)\n", lpPrefix,
  148.             pMsg->hwnd, pMsg->message, pMsg->wParam, pMsg->lParam);
  149.     }
  150.  
  151.     if (pMsg->message >= WM_DDE_FIRST && pMsg->message <= WM_DDE_LAST)
  152.     {
  153.         TraceDDE(lpPrefix, pMsg);
  154.     }
  155. }
  156.  
  157. /////////////////////////////////////////////////////////////////////////////
  158.  
  159. #endif // _DEBUG (entire file)
  160.