WEB开发网
开发学院软件开发VC MFC程序员的WTL指南(3)WTL 界面基类 阅读

MFC程序员的WTL指南(3)WTL 界面基类

 2006-07-22 22:03:45 来源:WEB开发网   
核心提示: class CMyWindow : public CFrameWindowImpl<CMyWindow>{public: BEGIN_MSG_MAP_EX(CMyWindow) MSG_WM_CREATE(OnCreate) MSG_W
class CMyWindow : public CFrameWindowImpl<CMyWindow>
{
public:
   BEGIN_MSG_MAP_EX(CMyWindow)
     MSG_WM_CREATE(OnCreate)
     MSG_WM_DESTROY(OnDestroy)
     MSG_WM_TIMER(OnTimer)
     MSG_WM_ERASEBKGND(OnEraseBkgnd)
     CHAIN_MSG_MAP(CFrameWindowImpl<CMyWindow>)
   END_MSG_MAP()
   LRESULT OnEraseBkgnd ( HDC hdc )
   {
   CDCHandle dc(hdc);
   CRect   rc;
   SYSTEMTIME st;
   CString  sTime;
     // Get our window''s client area.
     GetClientRect ( rc );
     // Build the string to show in the window.
     GetLocalTime ( &st );
     sTime.Format ( _T("The time is %d:%02d:%02d"),
            st.wHour, st.wMinute, st.wSecond );
     // Set up the DC and draw the text.
     dc.SaveDC();
     dc.SetBkColor ( RGB(255,153,0);
     dc.SetTextColor ( RGB(0,0,0) );
     dc.ExtTextOut ( 0, 0, ETO_OPAQUE, rc, sTime,
             sTime.GetLength(), NULL );
     // Restore the DC.
     dc.RestoreDC(-1);
     return 1;  // We erased the background (ExtTextOut did it)
   }
};

这个消息处理函数不仅使用了CRect和CString类,还使用了一个GDI包装类CDCHandle。对于CString类我想说的是它等同与MFC的CString类,我在后面的文章中还会介绍这些包装类,现在你只需要知道CDCHandle是对HDC的简单封装就行了,使用方法与MFC的CDC类相似,只是CDCHandle的实例在超出作用域后不会销毁它所操作的设备上下文。

上一页  1 2 3 4 5 6 7 8 9 10  下一页

Tags:MFC 程序员 WTL

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接