标签:des style blog class c code
稍微修改了下QQ示例里面的聊天界面界面,然后把代码扣过来完成了QQ聊天界面部分,效果还可以。
// QQTalk.h文件 #ifndef __QQ_TALK_H__ #define __QQ_TALK_H__ #include <DuiLib/DuiLibEnv.h> #include <DuiLib/UIlib.h> using namespace DuiLib; #define QQ_TALK_XML _T("chatbox.xml") class CQQTalk : public CWindowWnd, public INotifyUI { public: virtual LPCTSTR GetWindowClassName() const; // CWindowWnd的纯虚函数,必须实现 virtual void Notify( TNotifyUI& msg ); // INotifyUI的纯虚函数,必须实现 // 窗口消息处理回调函数 virtual LRESULT HandleMessage( UINT uMsg, WPARAM wParam, LPARAM lParam ); private: // 消息处理函数 LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandle); LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandle); LRESULT OnNCActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandle); LRESULT OnNCCalcsize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandle); LRESULT OnNCPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandle); LRESULT OnDestory(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandle); // 控件消息处理函数 void OnNotifyClick(TNotifyUI& msg); // 获取窗口控件 void GetCtrlFromRes(); protected: CPaintManagerUI m_paintManager; // 窗口消息类管理对象 private: // 窗口控件列表 CButtonUI* m_pbtnClose; CButtonUI* m_pbtnFontBar; private: static LPCTSTR m_lpszWndClsName; // 窗口类名 }; #endif
// QQTalk.cpp文件 #include "QQTalk.h" #include <exception> LPCTSTR CQQTalk::m_lpszWndClsName = _T("QQTalk"); LPCTSTR CQQTalk::GetWindowClassName() const { return m_lpszWndClsName; } void CQQTalk::Notify( TNotifyUI& msg ) { if(msg.sType == _T("click")) { OnNotifyClick(msg); } } LRESULT CQQTalk::HandleMessage( UINT uMsg, WPARAM wParam, LPARAM lParam ) { LRESULT lRes = 0; BOOL bHandle = FALSE; switch(uMsg) { case WM_CREATE: lRes = OnCreate(uMsg, wParam, lParam, bHandle);break; case WM_NCHITTEST: lRes = OnNcHitTest(uMsg, wParam, lParam, bHandle);break; case WM_NCACTIVATE: lRes = OnNCActivate(uMsg, wParam, lParam, bHandle);break; case WM_NCCALCSIZE: lRes = OnNCCalcsize(uMsg, wParam, lParam, bHandle);break; case WM_NCPAINT: lRes = OnNCPaint(uMsg, wParam, lParam, bHandle);break; case WM_DESTROY: lRes = OnDestory(uMsg, wParam, lParam, bHandle);break; default: lRes = FALSE;break; } if(bHandle) { return lRes; } else { if( m_paintManager.MessageHandler(uMsg, wParam, lParam, lRes) ) { return lRes; } else { return CWindowWnd::HandleMessage(uMsg, wParam, lParam); } } } LRESULT CQQTalk::OnCreate( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandle ) { m_paintManager.Init(m_hWnd); CDialogBuilder builder; CControlUI* pRoot = builder.Create(QQ_TALK_XML, (UINT)0, NULL, &m_paintManager); ASSERT(pRoot && "Failed to parse XML"); m_paintManager.AttachDialog(pRoot); bool bRet = m_paintManager.AddNotifier(this); GetCtrlFromRes(); bHandle = TRUE; return 0; } LRESULT CQQTalk::OnNCActivate( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandle ) { bHandle = TRUE; return 0; } LRESULT CQQTalk::OnNCCalcsize( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandle ) { bHandle = TRUE; return 0; } LRESULT CQQTalk::OnNCPaint( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandle ) { bHandle = TRUE; return 0; } // 实现窗口可拖拽 LRESULT CQQTalk::OnNcHitTest( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandle ) { bHandle = TRUE; POINT pt; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam); ::ScreenToClient(*this, &pt); RECT rcClient; ::GetClientRect(*this, &rcClient); RECT rcCaption = m_paintManager.GetCaptionRect(); if( pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right && pt.y >= rcCaption.top && pt.y < rcCaption.bottom ) { CControlUI* pControl = static_cast<CControlUI*>(m_paintManager.FindControl(pt)); if( pControl && _tcscmp(pControl->GetClass(), _T("ButtonUI")) != 0 && _tcscmp(pControl->GetClass(), _T("OptionUI")) != 0 && _tcscmp(pControl->GetClass(), _T("TextUI")) != 0 ) return HTCAPTION; } return HTCLIENT; } LRESULT CQQTalk::OnDestory( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandle ) { ::PostQuitMessage(0L); bHandle = TRUE; return 0; } void CQQTalk::GetCtrlFromRes() { m_pbtnClose = static_cast<CButtonUI*>(m_paintManager.FindControl(_T("closebtn"))); } void CQQTalk::OnNotifyClick( TNotifyUI& msg ) { if( msg.pSender == m_pbtnClose ) { PostQuitMessage(0); } }
// main.cpp // 测试文件 #include "QQTalk.h" int WINAPI wWinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in LPWSTR lpCmdLine, __in int nShowCmd ) { // 初始化CPaintManagerUI CPaintManagerUI::SetInstance(hInstance); CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath() + _T("skin")); CPaintManagerUI::SetResourceZip(_T("MyQQRes.zip")); // 这一步可选 // CoInitialize是Windows提供的API函数 // 用来告诉 Windows以单线程的方式创建com对象 HRESULT Hr = ::CoInitialize(NULL); if( FAILED(Hr) ) return 0; // 创建一个QQ对话界面 CQQTalk* pQQTalkDlg = new CQQTalk(); pQQTalkDlg->Create(NULL, _T("和XXX的对话"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE); pQQTalkDlg->CenterWindow(); pQQTalkDlg->ShowModal(); CPaintManagerUI::MessageLoop(); delete pQQTalkDlg; pQQTalkDlg = NULL; // 逆初始化 ::CoUninitialize(); return 0; }
标签:des style blog class c code
原文地址:http://blog.csdn.net/arbboter/article/details/26282717