MFC中的Dump示例

测试代码:

// 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";
}









  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值