home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / MFC / SRC / AFXTRACE.CP_ / AFXTRACE.CP
Encoding:
Text File  |  1993-02-08  |  4.6 KB  |  173 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 and/or WinHelp documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11.  
  12. #include "stdafx.h"
  13.  
  14. #ifdef AFX_DBG1_SEG
  15. #pragma code_seg(AFX_DBG1_SEG)
  16. #endif
  17.  
  18. #ifdef _DEBUG       // entire file for debugging
  19.  
  20. #include "dde.h"
  21.  
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // Build data tables by including data file three times
  29.  
  30. #define DO(WM_FOO)  static char BASED_CODE sz##WM_FOO[] = #WM_FOO;
  31. #include "tracedat.h"
  32. #undef DO
  33.  
  34. static UINT BASED_CODE allMessages[] =
  35. {
  36. #define DO(WM_FOO)  WM_FOO,
  37. #include "tracedat.h"
  38. #undef DO
  39.     0   // end of table
  40. };
  41.  
  42. static LPCSTR BASED_CODE allMessageNames[] =
  43. {
  44. #define DO(WM_FOO)  sz##WM_FOO,
  45. #include "tracedat.h"
  46. #undef DO
  47.     NULL    // end of table
  48. };
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // DDE special case
  52.  
  53. static void PASCAL TraceDDE(LPCSTR lpszPrefix, const MSG* pMsg)
  54. {
  55.     if (pMsg->message == WM_DDE_EXECUTE)
  56.     {
  57.         HGLOBAL hCommands = (HGLOBAL)HIWORD(pMsg->lParam);
  58.         ASSERT(hCommands != NULL);
  59.  
  60.         LPCSTR lpszCommands = (LPCSTR)::GlobalLock(hCommands);
  61.         ASSERT(lpszCommands != NULL);
  62.         TRACE2("%Fs: Execute '%Fs'\n", lpszPrefix, lpszCommands);
  63.         ::GlobalUnlock(hCommands);
  64.     }
  65.     else if (pMsg->message == WM_DDE_ADVISE)
  66.     {
  67.         ATOM aItem = HIWORD(pMsg->lParam);
  68.         HGLOBAL hAdvise = (HGLOBAL)LOWORD(pMsg->lParam);
  69.         ASSERT(aItem != NULL);
  70.         ASSERT(hAdvise != NULL);
  71.  
  72.         DDEADVISE FAR* lpAdvise = (DDEADVISE FAR*)::GlobalLock(hAdvise);
  73.         ASSERT(lpAdvise != NULL);                   
  74.         char szItem[80];
  75.         szItem[0] = '\0';
  76.  
  77.         if (aItem != 0)
  78.             ::GlobalGetAtomName(aItem, szItem, sizeof(szItem));
  79.  
  80.         char szFormat[80];
  81.         szFormat[0] = '\0';
  82.         if (((short)0xC000 <= lpAdvise->cfFormat) && 
  83.                 (lpAdvise->cfFormat <= (short)0xFFFF))
  84.             ::GetClipboardFormatName(lpAdvise->cfFormat,
  85.                 szFormat, sizeof(szFormat));
  86.  
  87.             // User defined clipboard formats have a range of 0xC000->0xFFFF
  88.             // System clipboard formats have other ranges, but no printable
  89.             // format names.
  90.  
  91.         static char BASED_DEBUG _sz[] =
  92.             "%Fs: Advise item='%s', Format='%s', Ack=%d, Defer Update= %d\n";
  93.         AfxTrace(_sz, lpszPrefix, szItem, szFormat, lpAdvise->fAckReq,
  94.             lpAdvise->fDeferUpd);
  95.         ::GlobalUnlock(hAdvise);
  96.     }
  97. }
  98.  
  99. /////////////////////////////////////////////////////////////////////////////
  100.  
  101. void AFXAPI _AfxTraceMsg(LPCSTR lpszPrefix, const MSG* pMsg)
  102. {
  103.     ASSERT(lpszPrefix != NULL);
  104.     ASSERT(pMsg != NULL);
  105.  
  106.     if (pMsg->message == WM_MOUSEMOVE || pMsg->message == WM_NCMOUSEMOVE ||
  107.        pMsg->message == WM_NCHITTEST ||
  108.        pMsg->message == WM_SETCURSOR ||
  109.        pMsg->message == WM_CTLCOLOR ||
  110.        pMsg->message == WM_ENTERIDLE ||
  111.        pMsg->message == WM_CANCELMODE)
  112.     {
  113.         // don't report very frequently sent messages
  114.         return;
  115.     }
  116.  
  117.     LPCSTR lpszMsgName = NULL;
  118.     char szBuf[80];
  119.  
  120.     // find message name
  121.     if (pMsg->message >= 0xC000)
  122.     {
  123.         // Window message registered with 'RegisterWindowMessage'
  124.         //  (actually a USER atom)
  125.         if (::GetClipboardFormatName(pMsg->message, szBuf, sizeof(szBuf)) != 0)
  126.             lpszMsgName = szBuf;
  127.     }
  128.     else if (pMsg->message >= WM_USER)
  129.     {
  130.         // User message
  131.         sprintf(szBuf, "WM_USER+0x%04X", pMsg->message - WM_USER);
  132.         lpszMsgName = szBuf;
  133.     }
  134.     else
  135.     {
  136.         // a system windows message
  137.         const UINT FAR* lpMessage;
  138.         for (lpMessage = allMessages; *lpMessage != 0; lpMessage++)
  139.         {
  140.             if (*lpMessage == pMsg->message)
  141.             {
  142.                 int iMsg = (int)(lpMessage - (const UINT FAR*)allMessages);
  143.                 lpszMsgName = allMessageNames[iMsg];
  144.                 break;
  145.             }
  146.         }
  147.     }
  148.  
  149.     if (lpszMsgName != NULL)
  150.     {
  151.         static char BASED_DEBUG _sz[] =
  152.             "%Fs: hwnd=0x%04X, msg = %Fs (0x%04X, 0x%08lX)\n";
  153.         AfxTrace(_sz, lpszPrefix, (UINT)pMsg->hwnd, lpszMsgName,
  154.             pMsg->wParam, pMsg->lParam);
  155.     }
  156.     else
  157.     {
  158.         static char BASED_DEBUG _sz[] =
  159.             "%Fs: hwnd=0x%04X, msg = 0x%04X (0x%04X, 0x%08lX)\n";
  160.         AfxTrace(_sz, lpszPrefix, (UINT)pMsg->hwnd, pMsg->message,
  161.             pMsg->wParam, pMsg->lParam);
  162.     }
  163.  
  164.     if (pMsg->message >= WM_DDE_FIRST && pMsg->message <= WM_DDE_LAST)
  165.     {
  166.         TraceDDE(lpszPrefix, pMsg);
  167.     }
  168. }
  169.  
  170. /////////////////////////////////////////////////////////////////////////////
  171.  
  172. #endif // _DEBUG (entire file)
  173.