home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / ctlrefl.cpp < prev    next >
C/C++ Source or Header  |  1998-06-16  |  4KB  |  158 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef AFXCTL_CORE2_SEG
  14. #pragma code_seg(AFXCTL_CORE2_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. #define new DEBUG_NEW
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CReflectorWnd
  26.  
  27. BOOL CReflectorWnd::Create(const CRect& rect, HWND hWndParent)
  28. {
  29.     // make sure the default window class is registered
  30.     VERIFY(AfxDeferRegisterClass(AFX_WNDOLECONTROL_REG));
  31.     return CreateEx(0, AFX_WNDOLECONTROL, NULL,
  32.         WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS, rect.left, rect.top,
  33.         rect.right - rect.left, rect.bottom - rect.top, hWndParent, 0);
  34. }
  35.  
  36. void CReflectorWnd::PostNcDestroy()
  37. {
  38.     if (m_pCtrl != NULL)
  39.         m_pCtrl->OnReflectorDestroyed();
  40.     delete this;
  41. }
  42.  
  43. LRESULT CReflectorWnd::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  44. {
  45.     switch (uMsg)
  46.     {
  47.     case WM_COMMAND:
  48.     case WM_NOTIFY:
  49.     case WM_CTLCOLORBTN:
  50.     case WM_CTLCOLORDLG:
  51.     case WM_CTLCOLOREDIT:
  52.     case WM_CTLCOLORLISTBOX:
  53.     case WM_CTLCOLORMSGBOX:
  54.     case WM_CTLCOLORSCROLLBAR:
  55.     case WM_CTLCOLORSTATIC:
  56.     case WM_DRAWITEM:
  57.     case WM_MEASUREITEM:
  58.     case WM_DELETEITEM:
  59.     case WM_VKEYTOITEM:
  60.     case WM_CHARTOITEM:
  61.     case WM_COMPAREITEM:
  62.     case WM_HSCROLL:
  63.     case WM_VSCROLL:
  64.     case WM_PARENTNOTIFY:
  65.         if (m_pCtrl != NULL)
  66.             return m_pCtrl->SendMessage(OCM__BASE + uMsg, wParam, lParam);
  67.         break;
  68.  
  69.     case WM_SETFOCUS:
  70.         if (m_pCtrl != NULL)
  71.         {
  72.             m_pCtrl->SetFocus();
  73.             return 0;
  74.         }
  75.         break;
  76.     }
  77.  
  78.     return CWnd::WindowProc(uMsg, wParam, lParam);
  79. }
  80.  
  81. void CReflectorWnd::SetControl(COleControl* pCtrl)
  82. {
  83.     m_pCtrl = pCtrl;
  84. }
  85.  
  86. LRESULT CParkingWnd::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  87. {
  88.     HWND hWndSource = NULL;
  89.  
  90.     switch (uMsg)
  91.     {
  92.     case WM_COMMAND:
  93.     case WM_CTLCOLORBTN:
  94.     case WM_CTLCOLORDLG:
  95.     case WM_CTLCOLOREDIT:
  96.     case WM_CTLCOLORLISTBOX:
  97.     case WM_CTLCOLORMSGBOX:
  98.     case WM_CTLCOLORSCROLLBAR:
  99.     case WM_CTLCOLORSTATIC:
  100.     case WM_VKEYTOITEM:
  101.     case WM_CHARTOITEM:
  102.     case WM_HSCROLL:
  103.     case WM_VSCROLL:
  104.         hWndSource = (HWND)lParam;
  105.         break;
  106.  
  107.     case WM_NOTIFY:
  108.         hWndSource = ((NMHDR*)lParam)->hwndFrom;
  109.         break;
  110.  
  111.     case WM_DRAWITEM:
  112.         hWndSource = ((DRAWITEMSTRUCT*)lParam)->hwndItem;
  113.         break;
  114.  
  115.     case WM_MEASUREITEM:
  116.         m_idMap.Lookup((void*)(DWORD)HIWORD(wParam), (void*&)hWndSource);
  117.         break;
  118.  
  119.     case WM_DELETEITEM:
  120.         hWndSource = ((DELETEITEMSTRUCT*)lParam)->hwndItem;
  121.         break;
  122.  
  123.     case WM_COMPAREITEM:
  124.         hWndSource = ((COMPAREITEMSTRUCT*)lParam)->hwndItem;
  125.         break;
  126.  
  127.     case WM_PARENTNOTIFY:
  128.         switch (LOWORD(wParam))
  129.         {
  130.         case WM_CREATE:
  131.             m_idMap.SetAt((void*)(DWORD)HIWORD(wParam), (HWND)lParam);
  132.             hWndSource = (HWND)lParam;
  133.             break;
  134.  
  135.         case WM_DESTROY:
  136.             m_idMap.RemoveKey((void*)(DWORD)HIWORD(wParam));
  137.             hWndSource = (HWND)lParam;
  138.             break;
  139.  
  140.         default:
  141.             m_idMap.Lookup((void*)(DWORD)HIWORD(wParam), (void*&)hWndSource);
  142.             break;
  143.         }
  144.     }
  145.  
  146.     if (hWndSource != NULL)
  147.         return ::SendMessage(hWndSource, OCM__BASE + uMsg, wParam, lParam);
  148.     else
  149.         return CWnd::WindowProc(uMsg, wParam, lParam);
  150. }
  151.  
  152. /////////////////////////////////////////////////////////////////////////////
  153. // Force any extra compiler-generated code into AFX_INIT_SEG
  154.  
  155. #ifdef AFX_INIT_SEG
  156. #pragma code_seg(AFX_INIT_SEG)
  157. #endif
  158.