home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectInput / DIConfig / viewselwnd.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  2.4 KB  |  114 lines

  1. //-----------------------------------------------------------------------------
  2. // File: viewselwnd.cpp
  3. //
  4. // Desc: Implements CViewSelWnd class (derived from  CFlexWnd).  CViewSelWnd
  5. //       is used by the page object when a device has more than one view.
  6. //       CViewSelWnd displays one thumbnail for each view.  The user can then
  7. //       select which view he/she wants to see with the mouse.
  8. //
  9. // Copyright (C) 1999-2001 Microsoft Corporation. All Rights Reserved.
  10. //-----------------------------------------------------------------------------
  11.  
  12. #include "common.hpp"
  13.  
  14.  
  15. CViewSelWnd::CViewSelWnd() :
  16.     m_pUI(NULL), m_nOver(-1)
  17. {
  18. }
  19.  
  20. CViewSelWnd::~CViewSelWnd()
  21. {
  22. }
  23.  
  24. BOOL CViewSelWnd::Go(HWND hParent, int left, int bottom, CDeviceUI *pUI)
  25. {
  26.     if (pUI == NULL)
  27.     {
  28.         assert(0);
  29.         return FALSE;
  30.     }
  31.     m_pUI = pUI;
  32.  
  33.     int w = 2 + g_sizeThumb.cx * pUI->GetNumViews();
  34.     int h = 2 + g_sizeThumb.cy;
  35.  
  36.     RECT rect = {left, bottom - h, left + w, bottom};
  37.  
  38.     if (!Create(hParent, rect, FALSE))
  39.         return FALSE;
  40.  
  41.     assert(m_hWnd);
  42.     if (!m_hWnd)
  43.         return FALSE;
  44.  
  45.     SetWindowPos(m_hWnd, HWND_TOP, 0, 0, 0, 0,
  46.         SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
  47.     SetCapture();
  48.  
  49.     return TRUE;
  50. }
  51.  
  52. void CViewSelWnd::OnPaint(HDC hDC)
  53. {
  54.     for (int i = 0; i < m_pUI->GetNumViews(); i++)
  55.     {
  56.         CBitmap *pbm = m_pUI->GetViewThumbnail(i, i == m_nOver);
  57.         if (pbm != NULL)
  58.             pbm->Draw(hDC, i * g_sizeThumb.cx + 1, 1);
  59.     }
  60.  
  61.     CPaintHelper ph(m_pUI->m_uig, hDC);
  62.     ph.SetPen(UIP_VIEWSELGRID);
  63.     RECT rect;
  64.     GetClientRect(&rect);
  65.     ph.Rectangle(rect, UIR_OUTLINE);
  66. }
  67.  
  68. void CViewSelWnd::OnMouseOver(POINT point, WPARAM fwKeys)
  69. {
  70.     RECT rect;
  71.     GetClientRect(&rect);
  72.     InflateRect(&rect, -1, -1);
  73.     if (PtInRect(&rect, point))
  74.         m_nOver = point.x / g_sizeThumb.cx;
  75.     else
  76.         m_nOver = -1;
  77.     Invalidate();
  78. }
  79.  
  80. void CViewSelWnd::OnClick(POINT point, WPARAM fwKeys, BOOL bLeft)
  81. {
  82.     if (!bLeft)
  83.         return;
  84.  
  85.     OnMouseOver(point, fwKeys);
  86.  
  87.     if (m_nOver != -1)
  88.     {
  89.         DEVICEUINOTIFY uin;
  90.         uin.msg = DEVUINM_SELVIEW;
  91.         uin.from = DEVUINFROM_SELWND;
  92.         uin.selview.nView = m_nOver;
  93.         m_pUI->Notify(uin);
  94.     }
  95.  
  96.     ReleaseCapture();
  97.  
  98.     Destroy();
  99. }
  100.  
  101. LRESULT CViewSelWnd::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  102. {
  103.     LRESULT lr = CFlexWnd::WndProc(hWnd, msg, wParam, lParam);
  104.  
  105.     switch (msg)
  106.     {
  107.         case WM_CAPTURECHANGED:
  108.             Destroy();
  109.             break;
  110.     }
  111.  
  112.     return lr;
  113. }
  114.