CMsgWnd.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #include "CMsgWnd.h"
  2. #include <string>
  3. DUI_BEGIN_MESSAGE_MAP(CMsgWnd, WindowImplBase)
  4. DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK, OnClick)
  5. DUI_END_MESSAGE_MAP()
  6. CMsgWnd::CMsgWnd(void)
  7. {
  8. }
  9. CMsgWnd::~CMsgWnd(void)
  10. {
  11. }
  12. void CMsgWnd::SetTitle(LPCTSTR lpstrTitle)
  13. {
  14. if (lstrlen(lpstrTitle) <= 0) return;
  15. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("MessageTitle")));
  16. if (pControl) pControl->SetText(lpstrTitle);
  17. }
  18. void CMsgWnd::SetMsg(LPCTSTR lpstrMsg)
  19. {
  20. if (lstrlen(lpstrMsg) <= 0) return;
  21. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("MessageText")));
  22. if (pControl)
  23. {
  24. wstring str(lpstrMsg);
  25. auto count = str.find(L"\n", 0);//存在换行
  26. if (lstrlen(lpstrMsg) > 140 || count != -1)
  27. {
  28. RECT rect;
  29. rect.left = 0;
  30. rect.top = 30;
  31. rect.right = 0;
  32. rect.bottom = 0;
  33. pControl->SetPadding(rect);
  34. }
  35. pControl->SetText(lpstrMsg);
  36. }
  37. }
  38. void CMsgWnd::SetConfirmBtn(LPCTSTR lpstrConfirmBtn,bool isOnlyConfirmBtn)
  39. {
  40. if (isOnlyConfirmBtn)
  41. {
  42. CControlUI* confirm_btn = static_cast<CControlUI*>(m_pm.FindControl(_T("confirm_btn")));
  43. if (confirm_btn) confirm_btn->SetVisible(false);
  44. CControlUI* paddControl = static_cast<CControlUI*>(m_pm.FindControl(_T("paddControl")));
  45. if (paddControl) paddControl->SetVisible(false);
  46. CControlUI* questionIcon = static_cast<CControlUI*>(m_pm.FindControl(_T("questionIcon")));
  47. if (questionIcon) questionIcon->SetVisible(false);
  48. CControlUI* warningIcon = static_cast<CControlUI*>(m_pm.FindControl(_T("warningIcon")));
  49. if (warningIcon) warningIcon->SetVisible(true);
  50. return;
  51. }
  52. if (lstrlen(lpstrConfirmBtn) <= 0) return;
  53. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("confirm_btn")));
  54. if (pControl) pControl->SetText(lpstrConfirmBtn);
  55. }
  56. void CMsgWnd::SetCancelBtn(LPCTSTR lpstrCancelBtn)
  57. {
  58. if (lstrlen(lpstrCancelBtn) <= 0) return;
  59. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("cancel_btn")));
  60. if (pControl)
  61. {
  62. if (lstrlen(lpstrCancelBtn) > 16)
  63. {
  64. pControl->SetFixedWidth(150);
  65. }
  66. pControl->SetText(lpstrCancelBtn);
  67. }
  68. }
  69. void CMsgWnd::SetCancelBtn(LPCTSTR lpstrCancelBtn, UINT_PTR Tag)
  70. {
  71. if (lstrlen(lpstrCancelBtn) <= 0) return;
  72. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("cancel_btn")));
  73. if (pControl)
  74. {
  75. if (lstrlen(lpstrCancelBtn) > 16)
  76. {
  77. pControl->SetFixedWidth(150);
  78. }
  79. pControl->SetTag(Tag);
  80. pControl->SetText(lpstrCancelBtn);
  81. }
  82. }
  83. void CMsgWnd::OnFinalMessage(HWND hWnd)
  84. {
  85. __super::OnFinalMessage(hWnd);
  86. delete this;
  87. }
  88. DuiLib::CDuiString CMsgWnd::GetSkinFile()
  89. {
  90. return _T("msg.xml");
  91. }
  92. LPCTSTR CMsgWnd::GetWindowClassName(void) const
  93. {
  94. return _T("MsgWnd");
  95. }
  96. void CMsgWnd::OnClick(TNotifyUI& msg)
  97. {
  98. CDuiString sName = msg.pSender->GetName();
  99. sName.MakeLower();
  100. if (msg.pSender == m_pCloseBtn) {
  101. Close(MSGID_CANCEL);
  102. return;
  103. }
  104. else if (msg.pSender == m_pMinBtn) {
  105. SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0); return;
  106. }
  107. else if (msg.pSender == m_pMaxBtn) {
  108. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0); return;
  109. }
  110. else if (msg.pSender == m_pRestoreBtn) {
  111. SendMessage(WM_SYSCOMMAND, SC_RESTORE, 0); return;
  112. }
  113. else if (msg.pSender == m_pMenuBtn) {
  114. }
  115. else if (sName.CompareNoCase(_T("confirm_btn")) == 0)
  116. {
  117. Close(MSGID_OK);
  118. }
  119. else if (sName.CompareNoCase(_T("cancel_btn")) == 0)
  120. {
  121. if (msg.pSender->GetTag()==1)/*临时的补丁,因为打开安装文件所在目录的按钮被定义为取消按钮*/
  122. {
  123. Close(MSGID_OK);
  124. }
  125. else
  126. {
  127. Close(MSGID_CANCEL);
  128. }
  129. }
  130. }
  131. LRESULT CMsgWnd::HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  132. {
  133. bHandled = FALSE;
  134. return 0;
  135. }
  136. void CMsgWnd::Notify(TNotifyUI& msg)
  137. {
  138. return WindowImplBase::Notify(msg);
  139. }
  140. LRESULT CMsgWnd::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  141. {
  142. bHandled = FALSE;
  143. return 0L;
  144. }
  145. void CMsgWnd::InitWindow()
  146. {
  147. m_pCloseBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("closebtn")));
  148. }