DittoPopupWindow.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #include "stdafx.h"
  2. #include "CP_Main.h"
  3. #include "DittoPopupWindow.h"
  4. CDittoPopupWindow::CDittoPopupWindow()
  5. {
  6. m_groupId = -1;
  7. }
  8. CDittoPopupWindow::~CDittoPopupWindow()
  9. {
  10. }
  11. BEGIN_MESSAGE_MAP(CDittoPopupWindow, CWndEx)
  12. ON_WM_CREATE()
  13. ON_WM_SIZE()
  14. ON_WM_CTLCOLOR()
  15. ON_WM_LBUTTONUP()
  16. END_MESSAGE_MAP()
  17. int CDittoPopupWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
  18. {
  19. if (CWndEx::OnCreate(lpCreateStruct) == -1)
  20. {
  21. return -1;
  22. }
  23. CWndEx::SetCaptionOn(CAPTION_TOP, false, g_Opt.m_Theme.GetCaptionSize(), g_Opt.m_Theme.GetCaptionFontSize());
  24. m_font.CreateFont(-m_DittoWindow.m_dpi.Scale(12), 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 3, 2, 1, 34, _T("MS Sans Serif"));
  25. m_textLabel.Create(_T("test"), WS_CHILD | WS_VISIBLE, CRect(0, 0, 0, 0), this);
  26. m_textLabel.SetFont(&m_font);
  27. m_progressWnd.Create(WS_CHILD|PBS_SMOOTH, CRect(0, 0, 0, 0), this, 2);
  28. m_progressWnd.SetRange(0, 100);
  29. SetWindowText(_T("Running Ditto Updates"));
  30. //m_textLabel.SetWindowText(_T("test"));
  31. return 0;
  32. }
  33. void CDittoPopupWindow::UpdateText(CString text)
  34. {
  35. m_textLabel.SetWindowText(text);
  36. CRect rect;
  37. m_textLabel.GetWindowRect(&rect);
  38. ScreenToClient(&rect);
  39. InvalidateRect(&rect);
  40. UpdateWindow();
  41. PumpMessages();
  42. }
  43. void CDittoPopupWindow::SetProgressBarPercent(int percent)
  44. {
  45. if(::IsWindowVisible(m_progressWnd.m_hWnd) == FALSE)
  46. {
  47. m_progressWnd.ShowWindow(SW_SHOW);
  48. CRect size;
  49. GetClientRect(size);
  50. DoSize(size.Width(), size.Height());
  51. }
  52. m_progressWnd.SetPos(percent);
  53. PumpMessages();
  54. }
  55. void CDittoPopupWindow::HideProgressBar()
  56. {
  57. m_progressWnd.ShowWindow(SW_HIDE);
  58. PumpMessages();
  59. CRect size;
  60. GetClientRect(size);
  61. DoSize(size.Width(), size.Height());
  62. }
  63. void CDittoPopupWindow::OnSize(UINT nType, int cx, int cy)
  64. {
  65. CWndEx::OnSize(nType, cx, cy);
  66. DoSize(cx, cy);
  67. }
  68. void CDittoPopupWindow::DoSize(int cx, int cy)
  69. {
  70. if(m_textLabel.m_hWnd != NULL)
  71. {
  72. int bottom = 0;
  73. if(::IsWindowVisible(m_progressWnd.m_hWnd))
  74. {
  75. bottom = 50;
  76. }
  77. m_textLabel.MoveWindow(10, 10, cx-20, cy-bottom);
  78. this->Invalidate();
  79. }
  80. if(m_progressWnd.m_hWnd != NULL)
  81. {
  82. m_progressWnd.MoveWindow(10, cy-40, cx-20, 30);
  83. }
  84. }
  85. HBRUSH CDittoPopupWindow::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  86. {
  87. if (pWnd->GetDlgCtrlID() == 0xffff)
  88. {
  89. pDC->SetBkMode(TRANSPARENT);
  90. return reinterpret_cast<HBRUSH>(::GetStockObject(NULL_BRUSH));
  91. }
  92. else
  93. return CWndEx::OnCtlColor(pDC, pWnd, nCtlColor);
  94. }
  95. void CDittoPopupWindow::PumpMessages()
  96. {
  97. int nLoops = 0;
  98. MSG msg;
  99. while (::PeekMessage(&msg, m_hWnd, 0, 0, PM_REMOVE))
  100. {
  101. TranslateMessage(&msg);
  102. DispatchMessage(&msg);
  103. nLoops++;
  104. if (nLoops > 100)
  105. break;
  106. }
  107. }
  108. void CDittoPopupWindow::OnLButtonUp(UINT nFlags, CPoint point)
  109. {
  110. if(m_groupId > 0)
  111. {
  112. CWnd *pParent = this->GetParent();
  113. if(pParent)
  114. {
  115. pParent->PostMessageW(WM_SHOW_DITTO_GROUP, m_groupId, 0);
  116. }
  117. }
  118. }