home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / afxtrace.cpp < prev    next >
C/C++ Source or Header  |  1998-06-16  |  11KB  |  365 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 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 related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef _DEBUG       // entire file for debugging
  14.  
  15. #ifdef AFX_DBG1_SEG
  16. #pragma code_seg(AFX_DBG1_SEG)
  17. #endif
  18.  
  19. #include "dde.h"
  20.  
  21. #ifdef _DEBUG
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // Build data tables by including data file three times
  28.  
  29. struct AFX_MAP_MESSAGE
  30. {
  31.     UINT    nMsg;
  32.     LPCSTR  lpszMsg;
  33. };
  34.  
  35. #define DEFINE_MESSAGE(wm)  { wm, #wm }
  36.  
  37. static const AFX_MAP_MESSAGE allMessages[] =
  38. {
  39.     DEFINE_MESSAGE(WM_CREATE),
  40.     DEFINE_MESSAGE(WM_DESTROY),
  41.     DEFINE_MESSAGE(WM_MOVE),
  42.     DEFINE_MESSAGE(WM_SIZE),
  43.     DEFINE_MESSAGE(WM_ACTIVATE),
  44.     DEFINE_MESSAGE(WM_SETFOCUS),
  45.     DEFINE_MESSAGE(WM_KILLFOCUS),
  46.     DEFINE_MESSAGE(WM_ENABLE),
  47.     DEFINE_MESSAGE(WM_SETREDRAW),
  48.     DEFINE_MESSAGE(WM_SETTEXT),
  49.     DEFINE_MESSAGE(WM_GETTEXT),
  50.     DEFINE_MESSAGE(WM_GETTEXTLENGTH),
  51.     DEFINE_MESSAGE(WM_PAINT),
  52.     DEFINE_MESSAGE(WM_CLOSE),
  53.     DEFINE_MESSAGE(WM_QUERYENDSESSION),
  54.     DEFINE_MESSAGE(WM_QUIT),
  55.     DEFINE_MESSAGE(WM_QUERYOPEN),
  56.     DEFINE_MESSAGE(WM_ERASEBKGND),
  57.     DEFINE_MESSAGE(WM_SYSCOLORCHANGE),
  58.     DEFINE_MESSAGE(WM_ENDSESSION),
  59.     DEFINE_MESSAGE(WM_SHOWWINDOW),
  60.     DEFINE_MESSAGE(WM_CTLCOLORMSGBOX),
  61.     DEFINE_MESSAGE(WM_CTLCOLOREDIT),
  62.     DEFINE_MESSAGE(WM_CTLCOLORLISTBOX),
  63.     DEFINE_MESSAGE(WM_CTLCOLORBTN),
  64.     DEFINE_MESSAGE(WM_CTLCOLORDLG),
  65.     DEFINE_MESSAGE(WM_CTLCOLORSCROLLBAR),
  66.     DEFINE_MESSAGE(WM_CTLCOLORSTATIC),
  67.     DEFINE_MESSAGE(WM_WININICHANGE),
  68.     DEFINE_MESSAGE(WM_SETTINGCHANGE),
  69.     DEFINE_MESSAGE(WM_DEVMODECHANGE),
  70.     DEFINE_MESSAGE(WM_ACTIVATEAPP),
  71.     DEFINE_MESSAGE(WM_FONTCHANGE),
  72.     DEFINE_MESSAGE(WM_TIMECHANGE),
  73.     DEFINE_MESSAGE(WM_CANCELMODE),
  74.     DEFINE_MESSAGE(WM_SETCURSOR),
  75.     DEFINE_MESSAGE(WM_MOUSEACTIVATE),
  76.     DEFINE_MESSAGE(WM_CHILDACTIVATE),
  77.     DEFINE_MESSAGE(WM_QUEUESYNC),
  78.     DEFINE_MESSAGE(WM_GETMINMAXINFO),
  79.     DEFINE_MESSAGE(WM_ICONERASEBKGND),
  80.     DEFINE_MESSAGE(WM_NEXTDLGCTL),
  81.     DEFINE_MESSAGE(WM_SPOOLERSTATUS),
  82.     DEFINE_MESSAGE(WM_DRAWITEM),
  83.     DEFINE_MESSAGE(WM_MEASUREITEM),
  84.     DEFINE_MESSAGE(WM_DELETEITEM),
  85.     DEFINE_MESSAGE(WM_VKEYTOITEM),
  86.     DEFINE_MESSAGE(WM_CHARTOITEM),
  87.     DEFINE_MESSAGE(WM_SETFONT),
  88.     DEFINE_MESSAGE(WM_GETFONT),
  89.     DEFINE_MESSAGE(WM_QUERYDRAGICON),
  90.     DEFINE_MESSAGE(WM_COMPAREITEM),
  91.     DEFINE_MESSAGE(WM_COMPACTING),
  92.     DEFINE_MESSAGE(WM_NCCREATE),
  93.     DEFINE_MESSAGE(WM_NCDESTROY),
  94.     DEFINE_MESSAGE(WM_NCCALCSIZE),
  95.     DEFINE_MESSAGE(WM_NCHITTEST),
  96.     DEFINE_MESSAGE(WM_NCPAINT),
  97.     DEFINE_MESSAGE(WM_NCACTIVATE),
  98.     DEFINE_MESSAGE(WM_GETDLGCODE),
  99.     DEFINE_MESSAGE(WM_NCMOUSEMOVE),
  100.     DEFINE_MESSAGE(WM_NCLBUTTONDOWN),
  101.     DEFINE_MESSAGE(WM_NCLBUTTONUP),
  102.     DEFINE_MESSAGE(WM_NCLBUTTONDBLCLK),
  103.     DEFINE_MESSAGE(WM_NCRBUTTONDOWN),
  104.     DEFINE_MESSAGE(WM_NCRBUTTONUP),
  105.     DEFINE_MESSAGE(WM_NCRBUTTONDBLCLK),
  106.     DEFINE_MESSAGE(WM_NCMBUTTONDOWN),
  107.     DEFINE_MESSAGE(WM_NCMBUTTONUP),
  108.     DEFINE_MESSAGE(WM_NCMBUTTONDBLCLK),
  109.     DEFINE_MESSAGE(WM_KEYDOWN),
  110.     DEFINE_MESSAGE(WM_KEYUP),
  111.     DEFINE_MESSAGE(WM_CHAR),
  112.     DEFINE_MESSAGE(WM_DEADCHAR),
  113.     DEFINE_MESSAGE(WM_SYSKEYDOWN),
  114.     DEFINE_MESSAGE(WM_SYSKEYUP),
  115.     DEFINE_MESSAGE(WM_SYSCHAR),
  116.     DEFINE_MESSAGE(WM_SYSDEADCHAR),
  117.     DEFINE_MESSAGE(WM_KEYLAST),
  118.     DEFINE_MESSAGE(WM_INITDIALOG),
  119.     DEFINE_MESSAGE(WM_COMMAND),
  120.     DEFINE_MESSAGE(WM_SYSCOMMAND),
  121.     DEFINE_MESSAGE(WM_TIMER),
  122.     DEFINE_MESSAGE(WM_HSCROLL),
  123.     DEFINE_MESSAGE(WM_VSCROLL),
  124.     DEFINE_MESSAGE(WM_INITMENU),
  125.     DEFINE_MESSAGE(WM_INITMENUPOPUP),
  126.     DEFINE_MESSAGE(WM_MENUSELECT),
  127.     DEFINE_MESSAGE(WM_MENUCHAR),
  128.     DEFINE_MESSAGE(WM_ENTERIDLE),
  129.     DEFINE_MESSAGE(WM_MOUSEWHEEL),
  130.     DEFINE_MESSAGE(WM_MOUSEMOVE),
  131.     DEFINE_MESSAGE(WM_LBUTTONDOWN),
  132.     DEFINE_MESSAGE(WM_LBUTTONUP),
  133.     DEFINE_MESSAGE(WM_LBUTTONDBLCLK),
  134.     DEFINE_MESSAGE(WM_RBUTTONDOWN),
  135.     DEFINE_MESSAGE(WM_RBUTTONUP),
  136.     DEFINE_MESSAGE(WM_RBUTTONDBLCLK),
  137.     DEFINE_MESSAGE(WM_MBUTTONDOWN),
  138.     DEFINE_MESSAGE(WM_MBUTTONUP),
  139.     DEFINE_MESSAGE(WM_MBUTTONDBLCLK),
  140.     DEFINE_MESSAGE(WM_PARENTNOTIFY),
  141.     DEFINE_MESSAGE(WM_MDICREATE),
  142.     DEFINE_MESSAGE(WM_MDIDESTROY),
  143.     DEFINE_MESSAGE(WM_MDIACTIVATE),
  144.     DEFINE_MESSAGE(WM_MDIRESTORE),
  145.     DEFINE_MESSAGE(WM_MDINEXT),
  146.     DEFINE_MESSAGE(WM_MDIMAXIMIZE),
  147.     DEFINE_MESSAGE(WM_MDITILE),
  148.     DEFINE_MESSAGE(WM_MDICASCADE),
  149.     DEFINE_MESSAGE(WM_MDIICONARRANGE),
  150.     DEFINE_MESSAGE(WM_MDIGETACTIVE),
  151.     DEFINE_MESSAGE(WM_MDISETMENU),
  152.     DEFINE_MESSAGE(WM_CUT),
  153.     DEFINE_MESSAGE(WM_COPYDATA),
  154.     DEFINE_MESSAGE(WM_COPY),
  155.     DEFINE_MESSAGE(WM_PASTE),
  156.     DEFINE_MESSAGE(WM_CLEAR),
  157.     DEFINE_MESSAGE(WM_UNDO),
  158.     DEFINE_MESSAGE(WM_RENDERFORMAT),
  159.     DEFINE_MESSAGE(WM_RENDERALLFORMATS),
  160.     DEFINE_MESSAGE(WM_DESTROYCLIPBOARD),
  161.     DEFINE_MESSAGE(WM_DRAWCLIPBOARD),
  162.     DEFINE_MESSAGE(WM_PAINTCLIPBOARD),
  163.     DEFINE_MESSAGE(WM_VSCROLLCLIPBOARD),
  164.     DEFINE_MESSAGE(WM_SIZECLIPBOARD),
  165.     DEFINE_MESSAGE(WM_ASKCBFORMATNAME),
  166.     DEFINE_MESSAGE(WM_CHANGECBCHAIN),
  167.     DEFINE_MESSAGE(WM_HSCROLLCLIPBOARD),
  168.     DEFINE_MESSAGE(WM_QUERYNEWPALETTE),
  169.     DEFINE_MESSAGE(WM_PALETTEISCHANGING),
  170.     DEFINE_MESSAGE(WM_PALETTECHANGED),
  171.     DEFINE_MESSAGE(WM_DDE_INITIATE),
  172.     DEFINE_MESSAGE(WM_DDE_TERMINATE),
  173.     DEFINE_MESSAGE(WM_DDE_ADVISE),
  174.     DEFINE_MESSAGE(WM_DDE_UNADVISE),
  175.     DEFINE_MESSAGE(WM_DDE_ACK),
  176.     DEFINE_MESSAGE(WM_DDE_DATA),
  177.     DEFINE_MESSAGE(WM_DDE_REQUEST),
  178.     DEFINE_MESSAGE(WM_DDE_POKE),
  179.     DEFINE_MESSAGE(WM_DDE_EXECUTE),
  180.     DEFINE_MESSAGE(WM_DROPFILES),
  181.     DEFINE_MESSAGE(WM_POWER),
  182.     DEFINE_MESSAGE(WM_WINDOWPOSCHANGED),
  183.     DEFINE_MESSAGE(WM_WINDOWPOSCHANGING),
  184. // MFC specific messages
  185.     DEFINE_MESSAGE(WM_SIZEPARENT),
  186.     DEFINE_MESSAGE(WM_SETMESSAGESTRING),
  187.     DEFINE_MESSAGE(WM_IDLEUPDATECMDUI),
  188.     DEFINE_MESSAGE(WM_INITIALUPDATE),
  189.     DEFINE_MESSAGE(WM_COMMANDHELP),
  190.     DEFINE_MESSAGE(WM_HELPHITTEST),
  191.     DEFINE_MESSAGE(WM_EXITHELPMODE),
  192.     DEFINE_MESSAGE(WM_HELP),
  193.     DEFINE_MESSAGE(WM_NOTIFY),
  194.     DEFINE_MESSAGE(WM_CONTEXTMENU),
  195.     DEFINE_MESSAGE(WM_TCARD),
  196.     DEFINE_MESSAGE(WM_MDIREFRESHMENU),
  197.     DEFINE_MESSAGE(WM_MOVING),
  198.     DEFINE_MESSAGE(WM_STYLECHANGED),
  199.     DEFINE_MESSAGE(WM_STYLECHANGING),
  200.     DEFINE_MESSAGE(WM_SIZING),
  201.     DEFINE_MESSAGE(WM_SETHOTKEY),
  202.     DEFINE_MESSAGE(WM_PRINT),
  203.     DEFINE_MESSAGE(WM_PRINTCLIENT),
  204.     DEFINE_MESSAGE(WM_POWERBROADCAST),
  205.     DEFINE_MESSAGE(WM_HOTKEY),
  206.     DEFINE_MESSAGE(WM_GETICON),
  207.     DEFINE_MESSAGE(WM_EXITMENULOOP),
  208.     DEFINE_MESSAGE(WM_ENTERMENULOOP),
  209.     DEFINE_MESSAGE(WM_DISPLAYCHANGE),
  210.     DEFINE_MESSAGE(WM_STYLECHANGED),
  211.     DEFINE_MESSAGE(WM_STYLECHANGING),
  212.     DEFINE_MESSAGE(WM_GETICON),
  213.     DEFINE_MESSAGE(WM_SETICON),
  214.     DEFINE_MESSAGE(WM_SIZING),
  215.     DEFINE_MESSAGE(WM_MOVING),
  216.     DEFINE_MESSAGE(WM_CAPTURECHANGED),
  217.     DEFINE_MESSAGE(WM_DEVICECHANGE),
  218.     DEFINE_MESSAGE(WM_PRINT),
  219.     DEFINE_MESSAGE(WM_PRINTCLIENT),
  220.     { 0, NULL, }    // end of message list
  221. };
  222.  
  223. #undef DEFINE_MESSAGE
  224.  
  225. /////////////////////////////////////////////////////////////////////////////
  226. // DDE special case
  227.  
  228. static void AFXAPI TraceDDE(LPCTSTR lpszPrefix, const MSG* pMsg)
  229. {
  230.     if (pMsg->message == WM_DDE_EXECUTE)
  231.     {
  232.         UINT nDummy;
  233.         HGLOBAL hCommands;
  234.         if (!UnpackDDElParam(WM_DDE_EXECUTE, pMsg->lParam,
  235.             &nDummy, (PUINT)&hCommands))
  236.         {
  237.             TRACE1("Warning: Unable to unpack WM_DDE_EXECUTE lParam %08lX.\n",
  238.                 pMsg->lParam);
  239.             return;
  240.         }
  241.         ASSERT(hCommands != NULL);
  242.  
  243.         LPCTSTR lpszCommands = (LPCTSTR)::GlobalLock(hCommands);
  244.         ASSERT(lpszCommands != NULL);
  245.         TRACE2("%s: Execute '%s'.\n", lpszPrefix, lpszCommands);
  246.         ::GlobalUnlock(hCommands);
  247.     }
  248.     else if (pMsg->message == WM_DDE_ADVISE)
  249.     {
  250.         ATOM aItem;
  251.         HGLOBAL hAdvise;
  252.         if (!UnpackDDElParam(WM_DDE_ADVISE, pMsg->lParam,
  253.             (PUINT)&hAdvise, (PUINT)&aItem))
  254.         {
  255.             TRACE1("Warning: Unable to unpack WM_DDE_ADVISE lParam %08lX.\n",
  256.                 pMsg->lParam);
  257.             return;
  258.         }
  259.         ASSERT(aItem != NULL);
  260.         ASSERT(hAdvise != NULL);
  261.  
  262.         DDEADVISE* lpAdvise = (DDEADVISE*)::GlobalLock(hAdvise);
  263.         ASSERT(lpAdvise != NULL);
  264.         TCHAR szItem[80];
  265.         szItem[0] = '\0';
  266.  
  267.         if (aItem != 0)
  268.             ::GlobalGetAtomName(aItem, szItem, _countof(szItem));
  269.  
  270.         TCHAR szFormat[80];
  271.         szFormat[0] = '\0';
  272.         if (((UINT)0xC000 <= (UINT)lpAdvise->cfFormat) &&
  273.                 ((UINT)lpAdvise->cfFormat <= (UINT)0xFFFF))
  274.         {
  275.             ::GetClipboardFormatName(lpAdvise->cfFormat,
  276.                 szFormat, _countof(szFormat));
  277.  
  278.             // User defined clipboard formats have a range of 0xC000->0xFFFF
  279.             // System clipboard formats have other ranges, but no printable
  280.             // format names.
  281.         }
  282.  
  283.         AfxTrace(
  284.             _T("%s: Advise item='%s', Format='%s', Ack=%d, Defer Update= %d\n"),
  285.              lpszPrefix, szItem, szFormat, lpAdvise->fAckReq,
  286.             lpAdvise->fDeferUpd);
  287.         ::GlobalUnlock(hAdvise);
  288.     }
  289. }
  290.  
  291. /////////////////////////////////////////////////////////////////////////////
  292.  
  293. void AFXAPI _AfxTraceMsg(LPCTSTR lpszPrefix, const MSG* pMsg)
  294. {
  295.     ASSERT(lpszPrefix != NULL);
  296.     ASSERT(pMsg != NULL);
  297.  
  298.     if (pMsg->message == WM_MOUSEMOVE || pMsg->message == WM_NCMOUSEMOVE ||
  299.         pMsg->message == WM_NCHITTEST || pMsg->message == WM_SETCURSOR ||
  300.         pMsg->message == WM_CTLCOLORBTN ||
  301.         pMsg->message == WM_CTLCOLORDLG ||
  302.         pMsg->message == WM_CTLCOLOREDIT ||
  303.         pMsg->message == WM_CTLCOLORLISTBOX ||
  304.         pMsg->message == WM_CTLCOLORMSGBOX ||
  305.         pMsg->message == WM_CTLCOLORSCROLLBAR ||
  306.         pMsg->message == WM_CTLCOLORSTATIC ||
  307.         pMsg->message == WM_ENTERIDLE || pMsg->message == WM_CANCELMODE ||
  308.         pMsg->message == 0x0118)    // WM_SYSTIMER (caret blink)
  309.     {
  310.         // don't report very frequently sent messages
  311.         return;
  312.     }
  313.  
  314.     LPCSTR lpszMsgName = NULL;
  315.     char szBuf[80];
  316.  
  317.     // find message name
  318.     if (pMsg->message >= 0xC000)
  319.     {
  320.         // Window message registered with 'RegisterWindowMessage'
  321.         //  (actually a USER atom)
  322.         if (::GetClipboardFormatNameA(pMsg->message, szBuf, _countof(szBuf)))
  323.             lpszMsgName = szBuf;
  324.     }
  325.     else if (pMsg->message >= WM_USER)
  326.     {
  327.         // User message
  328.         wsprintfA(szBuf, "WM_USER+0x%04X", pMsg->message - WM_USER);
  329.         lpszMsgName = szBuf;
  330.     }
  331.     else
  332.     {
  333.         // a system windows message
  334.         const AFX_MAP_MESSAGE* pMapMsg = allMessages;
  335.         for (/*null*/; pMapMsg->lpszMsg != NULL; pMapMsg++)
  336.         {
  337.             if (pMapMsg->nMsg == pMsg->message)
  338.             {
  339.                 lpszMsgName = pMapMsg->lpszMsg;
  340.                 break;
  341.             }
  342.         }
  343.     }
  344.  
  345.     if (lpszMsgName != NULL)
  346.     {
  347.         AfxTrace(_T("%s: hwnd=0x%04X, msg = %hs (0x%04X, 0x%08lX)\n"),
  348.             lpszPrefix, (UINT)pMsg->hwnd, lpszMsgName,
  349.             pMsg->wParam, pMsg->lParam);
  350.     }
  351.     else
  352.     {
  353.         AfxTrace(_T("%s: hwnd=0x%04X, msg = 0x%04X (0x%04X, 0x%08lX)\n"),
  354.             lpszPrefix, (UINT)pMsg->hwnd, pMsg->message,
  355.             pMsg->wParam, pMsg->lParam);
  356.     }
  357.  
  358.     if (pMsg->message >= WM_DDE_FIRST && pMsg->message <= WM_DDE_LAST)
  359.         TraceDDE(lpszPrefix, pMsg);
  360. }
  361.  
  362. /////////////////////////////////////////////////////////////////////////////
  363.  
  364. #endif // _DEBUG (entire file)
  365.