home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 8090 / ModelEdit.7z / SolidRectWnd.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2006-03-08  |  2.5 KB  |  126 lines

  1. // SolidRectWnd.cpp : implementation file
  2. //
  3.  
  4. #include "precompile.h"
  5. #include "modeledit.h"
  6. #include "SolidRectWnd.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // SolidRectWnd
  16.  
  17. SolidRectWnd::SolidRectWnd()
  18. {
  19.     m_Color = RGB(0,0,0);
  20.     m_hParentWnd = NULL;
  21. }
  22.  
  23. SolidRectWnd::~SolidRectWnd()
  24. {
  25. }
  26.  
  27.  
  28. BEGIN_MESSAGE_MAP(SolidRectWnd, CWnd)
  29.     //{{AFX_MSG_MAP(SolidRectWnd)
  30.     ON_WM_PAINT()
  31.     ON_WM_LBUTTONDOWN()
  32.     ON_WM_LBUTTONUP()
  33.     ON_WM_RBUTTONDOWN()
  34.     ON_WM_RBUTTONUP()
  35.     ON_WM_MOUSEMOVE()
  36.     //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38.  
  39.  
  40. void SolidRectWnd::SetColor(COLORREF color)
  41. {
  42.     if(color != m_Color)
  43.     {
  44.         m_Color = color;
  45.         InvalidateRect(NULL, FALSE);
  46.     }
  47. }
  48.  
  49. void SolidRectWnd::SetForward(BOOL bForward)
  50. {
  51.     m_hParentWnd = NULL;
  52.     if(bForward)
  53.     {
  54.         if(GetParent())
  55.         {
  56.             m_hParentWnd = GetParent()->m_hWnd;
  57.         }
  58.     }
  59. }
  60.  
  61. void SolidRectWnd::SendMouseMessageToParent(UINT msgID, WPARAM nFlags, CPoint point)
  62. {
  63.     if(m_hParentWnd)
  64.     {
  65.         ClientToScreen(&point);
  66.         ::ScreenToClient(m_hParentWnd, &point);
  67.  
  68.         ::SendMessage(m_hParentWnd, msgID, nFlags, MAKELPARAM(point.x, point.y));
  69.     }
  70. }
  71.  
  72.  
  73.  
  74. /////////////////////////////////////////////////////////////////////////////
  75. // SolidRectWnd message handlers
  76.  
  77. void SolidRectWnd::OnPaint() 
  78. {
  79.     CRect clientRect;
  80.     CBrush brush, *pOldBrush;
  81.  
  82.     CPaintDC dc(this); // device context for painting
  83.     
  84.     if(brush.CreateSolidBrush(m_Color))
  85.     {
  86.         if(pOldBrush  = dc.SelectObject(&brush))
  87.         {
  88.             GetClientRect(&clientRect);
  89.             dc.Rectangle(&clientRect);
  90.             dc.SelectObject(pOldBrush);
  91.         }
  92.     
  93.         brush.DeleteObject();
  94.     }
  95. }
  96.  
  97. void SolidRectWnd::OnLButtonDown(UINT nFlags, CPoint point) 
  98. {
  99.     SendMouseMessageToParent(WM_LBUTTONDOWN, nFlags, point);
  100.     CWnd::OnLButtonDown(nFlags, point);
  101. }
  102.  
  103. void SolidRectWnd::OnLButtonUp(UINT nFlags, CPoint point) 
  104. {
  105.     SendMouseMessageToParent(WM_LBUTTONUP, nFlags, point);
  106.     CWnd::OnLButtonUp(nFlags, point);
  107. }
  108.  
  109. void SolidRectWnd::OnRButtonDown(UINT nFlags, CPoint point) 
  110. {
  111.     SendMouseMessageToParent(WM_RBUTTONDOWN, nFlags, point);
  112.     CWnd::OnRButtonDown(nFlags, point);
  113. }
  114.  
  115. void SolidRectWnd::OnRButtonUp(UINT nFlags, CPoint point) 
  116. {
  117.     SendMouseMessageToParent(WM_RBUTTONUP, nFlags, point);
  118.     CWnd::OnRButtonUp(nFlags, point);
  119. }
  120.  
  121. void SolidRectWnd::OnMouseMove(UINT nFlags, CPoint point) 
  122. {
  123.     SendMouseMessageToParent(WM_MOUSEMOVE, nFlags, point);
  124.     CWnd::OnMouseMove(nFlags, point);
  125. }
  126.