| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- #include "../pch/pch.h"
- #include "CjiajiaWnd.h"
- LRESULT CjiajiaWnd::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 CjiajiaWnd::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 CjiajiaWnd::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 CjiajiaWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
- {
- if (uMsg == WM_KEYDOWN)
- {
- if (wParam == VK_RETURN)
- {
- StartYanzheng();
- return true;
- }
- else if (wParam == VK_ESCAPE)
- {
- Close(IDCANCEL);
- return true;
- }
- }
- return false;
- }
- LRESULT CjiajiaWnd::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("jiajia_input_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 CjiajiaWnd::Notify(TNotifyUI& msg)
- {
- if (msg.sType == _T("click"))
- {
- DuiLib::CDuiString senderName = msg.pSender->GetName();
- if (senderName == _T("closebtn"))
- {
- Close(IDCANCEL);
- return;
- }
- else if (senderName == _T("save"))
- {
- StartYanzheng();
- }
- else if (senderName == L"jianpan_1")
- {
- CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
- wstring wsReason = pContent->GetText();
- wsReason += L"1";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_2")
- {
- CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
- wstring wsReason = pContent->GetText();
- wsReason += L"2";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_3")
- {
- CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
- wstring wsReason = pContent->GetText();
- wsReason += L"3";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_4")
- {
- CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
- wstring wsReason = pContent->GetText();
- wsReason += L"4";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_5")
- {
- CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
- wstring wsReason = pContent->GetText();
- wsReason += L"5";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_6")
- {
- CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
- wstring wsReason = pContent->GetText();
- wsReason += L"6";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_7")
- {
- CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
- wstring wsReason = pContent->GetText();
- wsReason += L"7";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_8")
- {
- CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
- wstring wsReason = pContent->GetText();
- wsReason += L"8";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_9")
- {
- CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
- wstring wsReason = pContent->GetText();
- wsReason += L"9";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_0")
- {
- CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
- wstring wsReason = pContent->GetText();
- wsReason += L"0";
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_x")
- {
- CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
- wstring wsReason = pContent->GetText();
- wsReason = wsReason.substr(0, wsReason.length() - 1);
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- else if (senderName == L"jianpan_qingkong")
- {
- CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
- wstring wsReason = pContent->GetText();
- wsReason.clear();
- pContent->SetText(wsReason.c_str());
- pContent->SetFocus();
- }
- }
- else if (msg.sType == _T("textchanged"))
- {
- //只能输入数字,其他的全部删除
- CEditUI* m_pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
- if (!m_pEdit->GetText().IsEmpty())
- {
- wstring ws_Value = m_pEdit->GetText();
- string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
- for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
- {
- unsigned char tmp = strValue.at(nIndex);
- if (tmp > 57 || tmp < 48)
- {
- //ASCII码不是数字的都过滤掉
- strValue = strValue.substr(0, nIndex);
- m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
- m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
- break;
- }
- }
- }
- }
- else if (msg.sType == L"windowinit")
- {
- m_pm.SetNextTabControl(false);
- CEditUI* pFukuanEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
- pFukuanEdit->SetFocus();
- }
- }
- void CjiajiaWnd::Init()
- {
- }
- std::string CjiajiaWnd::getContent()
- {
- return m_content;
- }
- void CjiajiaWnd::SetTitle(std::wstring title)
- {
- CLabelUI* pLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("memo_dlg_title")));
- pLabel->SetText(title.c_str());
- }
- void CjiajiaWnd::StartYanzheng()
- {
- CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
- wstring wsReason = pContent->GetText();
- m_content = CLewaimaiString::UnicodeToUTF8(wsReason);
- int zhekou = atoi(m_content.c_str());
- if (zhekou > 100 || zhekou < 0)
- {
- CLabelUI* pErrorInfo = static_cast<CLabelUI*>(m_pm.FindControl(_T("errinfo")));
- pErrorInfo->SetText(L"加价金额只能为0到100之间的整数");
- pErrorInfo->SetVisible(true);
- return;
- }
- Close(IDOK);
- }
|