测试代码:
// trace.cpp
#include <afxwin.h>
#include <afxcoll.h>
// Define the application class
class CApp : public CWinApp
{
public:
virtual BOOL InitInstance();
};
CApp App;
// Define the window class
class CWindow : public CFrameWnd
{
CUIntArray *array;
public:
CWindow();
};
// The window's constructor
CWindow::CWindow()
{
// Create a window with the new class
Create(NULL, "Drawing Tests", WS_OVERLAPPEDWINDOW,CRect(0,0,250,100));
array = new CUIntArray;
array->Add(5);
array->Add(10);
array->Add(15);
TRACE("Array created\n");
afxDump.SetDepth(1);
#ifdef _DEBUG
TRACE("\n {array->Dump:}\n");
array->Dump(afxDump);
TRACE("\n {CWindow->Dump:}\n");
this->Dump(afxDump);
#endif
}
// Init the application
BOOL CApp::InitInstance()
{
m_pMainWnd = new CWindow();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
===================
调试结果:
{array->Dump:}
a CUIntArray at $3746C8
with 3 elements
[0] = 0x5
[1] = 0xA
[2] = 0xF
{CWindow->Dump:}
a CFrameWnd at $3743A0
----------CWnd::Dump(dc)-----------
m_hWnd = 0x60258 (permanent window)
caption = "Drawing Tests"
class name = "AfxFrameOrView42d"
rect = (L 0, T 0, R 250, B 100)
parent CWnd* = $0
style = $4CF0000
--------------End--------------
--------CFrameWnd::Dump-------------
m_hAccelTable = 0x0
m_nWindow = -1
m_nIDHelp = 0x0
m_nIDTracking = 0x0
m_nIDLastMessage = 0x0
no active view
-------------End----------------
======================================
Dump()和AssertValid()的实现代码一定要包含在#ifdef _DEBUG与#endif //_DEBUG 之间!!!
CUIntArray:
void CUIntArray::Dump(CDumpContext& dc) const
{
CObject::Dump(dc);
dc << "with " << m_nSize << " elements";
if (dc.GetDepth() > 0)
{
for (int i = 0; i < m_nSize; i++)
dc << "\n\t[" << i << "] = " << m_pData[i];
}
dc << "\n";
}
CWindow:
void CFrameWnd::Dump(CDumpContext& dc) const
{
CWnd::Dump(dc);
dc << "m_hAccelTable = " << (UINT)m_hAccelTable;
dc << "\nm_nWindow = " << m_nWindow;
dc << "\nm_nIDHelp = " << m_nIDHelp;
dc << "\nm_nIDTracking = " << m_nIDTracking;
dc << "\nm_nIDLastMessage = " << m_nIDLastMessage;
if (m_pViewActive != NULL)
dc << "\nwith active view: " << m_pViewActive;
else
dc << "\nno active view";
dc << "\n";
}