Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
3.8 KiB

  1. //-----------------------------------------------------------------------------
  2. // File: flexMsgBox.cpp
  3. //
  4. // Desc: Implements a message box control similar to Windows message box
  5. // without the button. CFlexMsgBox is derived from CFlexWnd.
  6. //
  7. // Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  8. //-----------------------------------------------------------------------------
  9. #include "common.hpp"
  10. CFlexMsgBox::CFlexMsgBox() :
  11. m_hWndNotify(NULL),
  12. m_rgbText(RGB(255,255,255)),
  13. m_rgbBk(RGB(0,0,0)),
  14. m_rgbSelText(RGB(0,0,255)),
  15. m_rgbSelBk(RGB(0,0,0)),
  16. m_rgbFill(RGB(0,0,255)),
  17. m_rgbLine(RGB(0,255,255)),
  18. m_hFont(NULL),
  19. m_tszText(NULL)
  20. {
  21. }
  22. CFlexMsgBox::~CFlexMsgBox()
  23. {
  24. delete[] m_tszText;
  25. }
  26. HWND CFlexMsgBox::Create(HWND hParent, const RECT &rect, BOOL bVisible)
  27. {
  28. m_bSent = FALSE;
  29. return CFlexWnd::Create(hParent, rect, bVisible);
  30. }
  31. void CFlexMsgBox::SetText(LPCTSTR tszText)
  32. {
  33. LPTSTR tszTempText = NULL;
  34. if (tszText)
  35. {
  36. tszTempText = new TCHAR[_tcslen(tszText) + 1];
  37. if (!tszTempText) return;
  38. _tcscpy(tszTempText, tszText);
  39. }
  40. delete[] m_tszText;
  41. m_tszText = tszTempText;
  42. }
  43. void CFlexMsgBox::SetFont(HFONT hFont)
  44. {
  45. m_hFont = hFont;
  46. if (m_hWnd == NULL)
  47. return;
  48. Invalidate();
  49. }
  50. void CFlexMsgBox::SetColors(COLORREF text, COLORREF bk, COLORREF seltext, COLORREF selbk, COLORREF fill, COLORREF line)
  51. {
  52. m_rgbText = text;
  53. m_rgbBk = bk;
  54. m_rgbSelText = seltext;
  55. m_rgbSelBk = selbk;
  56. m_rgbFill = fill;
  57. m_rgbLine = line;
  58. Invalidate();
  59. }
  60. void CFlexMsgBox::SetRect()
  61. {
  62. if (m_hWnd == NULL)
  63. return;
  64. RECT rect = GetRect();
  65. SetWindowPos(m_hWnd, NULL, rect.left, rect.top, rect.right, rect.bottom, SWP_NOZORDER | SWP_NOMOVE);
  66. }
  67. RECT CFlexMsgBox::GetRect(const RECT &rect)
  68. {
  69. int h = GetTextHeight(m_hFont);
  70. RECT ret = {rect.left, rect.top, rect.right, rect.top + h + 2};
  71. return ret;
  72. }
  73. RECT CFlexMsgBox::GetRect()
  74. {
  75. RECT rect;
  76. GetClientRect(&rect);
  77. return GetRect(rect);
  78. }
  79. void CFlexMsgBox::OnPaint(HDC hDC)
  80. {
  81. HDC hBDC = NULL, hODC = NULL;
  82. CBitmap *pbm = NULL;
  83. if (!InRenderMode())
  84. {
  85. hODC = hDC;
  86. pbm = CBitmap::Create(GetClientSize(), RGB(0,0,0), hDC);
  87. if (pbm != NULL)
  88. {
  89. hBDC = pbm->BeginPaintInto();
  90. if (hBDC != NULL)
  91. {
  92. hDC = hBDC;
  93. }
  94. }
  95. }
  96. InternalPaint(hDC);
  97. if (!InRenderMode())
  98. {
  99. if (pbm != NULL)
  100. {
  101. if (hBDC != NULL)
  102. {
  103. pbm->EndPaintInto(hBDC);
  104. pbm->Draw(hODC);
  105. }
  106. delete pbm;
  107. }
  108. }
  109. // Post reset message to config window now that the msg window is shown, if
  110. // we haven't done so.
  111. if (!m_bSent)
  112. {
  113. HWND hParentWnd = GetParent(m_hWnd);
  114. PostMessage(hParentWnd, WM_CFGUIRESET, 0, 0);
  115. }
  116. // Flag it that we've sent the message.
  117. m_bSent = TRUE;
  118. }
  119. void CFlexMsgBox::InternalPaint(HDC hDC)
  120. {
  121. HGDIOBJ hBrush = (HGDIOBJ)CreateSolidBrush(m_rgbBk);
  122. if (hBrush != NULL)
  123. {
  124. HGDIOBJ hOldBrush = SelectObject(hDC, hBrush);
  125. // Create pen for check box
  126. HGDIOBJ hPen = (HGDIOBJ)CreatePen(PS_SOLID, 1, m_rgbLine);
  127. if (hPen != NULL)
  128. {
  129. HGDIOBJ hOldPen = SelectObject(hDC, hPen);
  130. // Erase the background and also draw border
  131. RECT client;
  132. GetClientRect(&client);
  133. Rectangle(hDC, client.left, client.top, client.right, client.bottom);
  134. InflateRect(&client, -1, -1);
  135. // SetBkMode(hDC, TRANSPARENT);
  136. // Draw the message text
  137. SetTextColor(hDC, m_rgbText);
  138. SetBkColor(hDC, m_rgbBk);
  139. DrawText(hDC, m_tszText, -1, &client, DT_CENTER|DT_VCENTER|DT_NOPREFIX|DT_SINGLELINE);
  140. SelectObject(hDC, hOldPen);
  141. DeleteObject(hPen);
  142. }
  143. SelectObject(hDC, hOldBrush);
  144. DeleteObject(hBrush);
  145. }
  146. }
  147. void CFlexMsgBox::Notify(int code)
  148. {
  149. if (!m_hWndNotify)
  150. return;
  151. PostMessage(m_hWndNotify, WM_FLEXCHECKBOX,
  152. (WPARAM)code, (LPARAM)(LPVOID)this);
  153. }