home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / MFC / SRC / AFXTRACE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-30  |  10.8 KB  |  369 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1997 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. #ifndef _MAC
  229. static void AFXAPI TraceDDE(LPCTSTR lpszPrefix, const MSG* pMsg)
  230. {
  231.     if (pMsg->message == WM_DDE_EXECUTE)
  232.     {
  233.         UINT nDummy;
  234.         HGLOBAL hCommands;
  235.         if (!UnpackDDElParam(WM_DDE_EXECUTE, pMsg->lParam,
  236.             &nDummy, (PUINT)&hCommands))
  237.         {
  238.             TRACE1("Warning: Unable to unpack WM_DDE_EXECUTE lParam %08lX.\n",
  239.                 pMsg->lParam);
  240.             return;
  241.         }
  242.         ASSERT(hCommands != NULL);
  243.  
  244.         LPCTSTR lpszCommands = (LPCTSTR)::GlobalLock(hCommands);
  245.         ASSERT(lpszCommands != NULL);
  246.         TRACE2("%s: Execute '%s'.\n", lpszPrefix, lpszCommands);
  247.         ::GlobalUnlock(hCommands);
  248.     }
  249.     else if (pMsg->message == WM_DDE_ADVISE)
  250.     {
  251.         ATOM aItem;
  252.         HGLOBAL hAdvise;
  253.         if (!UnpackDDElParam(WM_DDE_ADVISE, pMsg->lParam,
  254.             (PUINT)&hAdvise, (PUINT)&aItem))
  255.         {
  256.             TRACE1("Warning: Unable to unpack WM_DDE_ADVISE lParam %08lX.\n",
  257.                 pMsg->lParam);
  258.             return;
  259.         }
  260.         ASSERT(aItem != NULL);
  261.         ASSERT(hAdvise != NULL);
  262.  
  263.         DDEADVISE* lpAdvise = (DDEADVISE*)::GlobalLock(hAdvise);
  264.         ASSERT(lpAdvise != NULL);
  265.         TCHAR szItem[80];
  266.         szItem[0] = '\0';
  267.  
  268.         if (aItem != 0)
  269.             ::GlobalGetAtomName(aItem, szItem, _countof(szItem));
  270.  
  271.         TCHAR szFormat[80];
  272.         szFormat[0] = '\0';
  273.         if (((UINT)0xC000 <= (UINT)lpAdvise->cfFormat) &&
  274.                 ((UINT)lpAdvise->cfFormat <= (UINT)0xFFFF))
  275.         {
  276.             ::GetClipboardFormatName(lpAdvise->cfFormat,
  277.                 szFormat, _countof(szFormat));
  278.  
  279.             // User defined clipboard formats have a range of 0xC000->0xFFFF
  280.             // System clipboard formats have other ranges, but no printable
  281.             // format names.
  282.         }
  283.  
  284.         AfxTrace(
  285.             _T("%s: Advise item='%s', Format='%s', Ack=%d, Defer Update= %d\n"),
  286.              lpszPrefix, szItem, szFormat, lpAdvise->fAckReq,
  287.             lpAdvise->fDeferUpd);
  288.         ::GlobalUnlock(hAdvise);
  289.     }
  290. }
  291. #endif
  292.  
  293. /////////////////////////////////////////////////////////////////////////////
  294.  
  295. void AFXAPI _AfxTraceMsg(LPCTSTR lpszPrefix, const MSG* pMsg)
  296. {
  297.     ASSERT(lpszPrefix != NULL);
  298.     ASSERT(pMsg != NULL);
  299.  
  300.     if (pMsg->message == WM_MOUSEMOVE || pMsg->message == WM_NCMOUSEMOVE ||
  301.         pMsg->message == WM_NCHITTEST || pMsg->message == WM_SETCURSOR ||
  302.         pMsg->message == WM_CTLCOLORBTN ||
  303.         pMsg->message == WM_CTLCOLORDLG ||
  304.         pMsg->message == WM_CTLCOLOREDIT ||
  305.         pMsg->message == WM_CTLCOLORLISTBOX ||
  306.         pMsg->message == WM_CTLCOLORMSGBOX ||
  307.         pMsg->message == WM_CTLCOLORSCROLLBAR ||
  308.         pMsg->message == WM_CTLCOLORSTATIC ||
  309.         pMsg->message == WM_ENTERIDLE || pMsg->message == WM_CANCELMODE ||
  310.         pMsg->message == 0x0118)    // WM_SYSTIMER (caret blink)
  311.     {
  312.         // don't report very frequently sent messages
  313.         return;
  314.     }
  315.  
  316.     LPCSTR lpszMsgName = NULL;
  317.     char szBuf[80];
  318.  
  319.     // find message name
  320.     if (pMsg->message >= 0xC000)
  321.     {
  322.         // Window message registered with 'RegisterWindowMessage'
  323.         //  (actually a USER atom)
  324.         if (::GetClipboardFormatNameA(pMsg->message, szBuf, _countof(szBuf)))
  325.             lpszMsgName = szBuf;
  326.     }
  327.     else if (pMsg->message >= WM_USER)
  328.     {
  329.         // User message
  330.         wsprintfA(szBuf, "WM_USER+0x%04X", pMsg->message - WM_USER);
  331.         lpszMsgName = szBuf;
  332.     }
  333.     else
  334.     {
  335.         // a system windows message
  336.         const AFX_MAP_MESSAGE* pMapMsg = allMessages;
  337.         for (/*null*/; pMapMsg->lpszMsg != NULL; pMapMsg++)
  338.         {
  339.             if (pMapMsg->nMsg == pMsg->message)
  340.             {
  341.                 lpszMsgName = pMapMsg->lpszMsg;
  342.                 break;
  343.             }
  344.         }
  345.     }
  346.  
  347.     if (lpszMsgName != NULL)
  348.     {
  349.         AfxTrace(_T("%s: hwnd=0x%04X, msg = %hs (0x%04X, 0x%08lX)\n"),
  350.             lpszPrefix, (UINT)pMsg->hwnd, lpszMsgName,
  351.             pMsg->wParam, pMsg->lParam);
  352.     }
  353.     else
  354.     {
  355.         AfxTrace(_T("%s: hwnd=0x%04X, msg = 0x%04X (0x%04X, 0x%08lX)\n"),
  356.             lpszPrefix, (UINT)pMsg->hwnd, pMsg->message,
  357.             pMsg->wParam, pMsg->lParam);
  358.     }
  359.  
  360. #ifndef _MAC
  361.     if (pMsg->message >= WM_DDE_FIRST && pMsg->message <= WM_DDE_LAST)
  362.         TraceDDE(lpszPrefix, pMsg);
  363. #endif
  364. }
  365.  
  366. /////////////////////////////////////////////////////////////////////////////
  367.  
  368. #endif // _DEBUG (entire file)
  369.