| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- #include "../pch/pch.h"
- #include "CMemoWnd.h"
- LRESULT CMemoWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- 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_pm.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_pm.FindControl(pt));
- if (pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0)
- {
- return HTCAPTION;
- }
- }
- return HTCLIENT;
- }
- LRESULT CMemoWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- SIZE szRoundCorner = m_pm.GetRoundCorner();
- if (!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0))
- {
- CDuiRect rcWnd;
- ::GetWindowRect(*this, &rcWnd);
- rcWnd.Offset(-rcWnd.left, -rcWnd.top);
- rcWnd.right++;
- rcWnd.bottom++;
- HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
- ::SetWindowRgn(*this, hRgn, TRUE);
- ::DeleteObject(hRgn);
- }
- bHandled = FALSE;
- return 0;
- }
- LRESULT CMemoWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- LRESULT lRes = 0;
- BOOL bHandled = TRUE;
- switch (uMsg)
- {
- case WM_CREATE:
- lRes = OnCreate(uMsg, wParam, lParam, bHandled);
- break;
- case WM_NCACTIVATE:
- lRes = OnNcActivate(uMsg, wParam, lParam, bHandled);
- break;
- case WM_NCCALCSIZE:
- lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled);
- break;
- case WM_NCPAINT:
- lRes = OnNcPaint(uMsg, wParam, lParam, bHandled);
- break;
- case WM_NCHITTEST:
- lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled);
- break;
- case WM_SIZE:
- lRes = OnSize(uMsg, wParam, lParam, bHandled);
- break;
- default:
- bHandled = FALSE;
- }
- if (bHandled)
- {
- return lRes;
- }
- if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes))
- {
- return lRes;
- }
- return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
- }
- LRESULT CMemoWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
- {
- if (uMsg == WM_KEYDOWN)
- {
- if (wParam == VK_RETURN)
- {
- return true;
- }
- else if (wParam == VK_ESCAPE)
- {
- return true;
- }
- }
- return false;
- }
- LRESULT CMemoWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
- styleValue &= ~WS_CAPTION;
- ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
- // 把自己的窗口句柄与窗口绘制管理器挂接在一起
- m_pm.Init(m_hWnd);
- m_pm.AddPreMessageFilter(this);
- CDialogBuilder builder;
- CControlUI* pRoot = builder.Create(_T("memo_edit_dlg.xml"), (UINT)0, NULL, &m_pm);
- ASSERT(pRoot && "Failed to parse XML");
- // 把这些控件绘制到本窗口上
- m_pm.AttachDialog(pRoot);
- // 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数
- m_pm.AddNotifier(this);
- Init();
- return 0;
- }
- void CMemoWnd::Notify(TNotifyUI& msg)
- {
- if (msg.sType == _T("click"))
- {
- DuiLib::CDuiString senderName = msg.pSender->GetName();
- if (senderName == _T("quit"))
- {
- Close(IDCANCEL);
- return;
- }
- else if (senderName == _T("save"))
- {
- //开始保存厨房打印机的数据
- CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
- wstring wsReason = pContent->GetText();
- m_memo = CLewaimaiString::UnicodeToUTF8(wsReason);
- Close(IDOK);
- return;
- }
- }
- }
- void CMemoWnd::Init()
- {
- }
|