home *** CD-ROM | disk | FTP | other *** search
/ Beginning Direct3D Game Programming / Direct3D.iso / directx / dxf / samples / multimedia / directinput / diconfig / cdevicecontrol.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  14.6 KB  |  626 lines

  1. //-----------------------------------------------------------------------------
  2. // File: cdevicecontrol.cpp
  3. //
  4. // Desc: CDeviceControl is a class that encapsulate the functionality of a
  5. //       device control (or a callout).  CDeviceView accesses it to retrieve/
  6. //       save information about the control.
  7. //
  8. // Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  9. //-----------------------------------------------------------------------------
  10.  
  11. #include "common.hpp"
  12.  
  13.  
  14. CDeviceControl::CDeviceControl(CDeviceUI &ui, CDeviceView &view) :
  15.     m_ui(ui),
  16.     m_view(view),
  17.     m_bHighlight(FALSE),
  18.     m_ptszCaption(NULL),
  19.     m_dwDrawTextFlags(0),
  20.     m_FontHeight(-1),
  21.     m_bCalledCalcCallout(FALSE),
  22.     m_bPlacedOnlyFirstCorner(FALSE),
  23.     m_bInit(FALSE),
  24.     m_dwCalloutAlign(CAF_TOPLEFT),
  25.     m_nLinePoints(0),
  26.     m_dwDeviceControlOffset((DWORD)-1),
  27.     m_bOffsetAssigned(FALSE),
  28.     m_pbmOverlay(NULL),
  29.     m_pbmHitMask(NULL),
  30.     m_ptszOverlayPath(NULL),
  31.     m_bCaptionClipped(FALSE)
  32. {
  33. }
  34.  
  35. CDeviceControl::~CDeviceControl()
  36. {
  37.     DEVICEUINOTIFY uin;
  38.     uin.from = DEVUINFROM_CONTROL;
  39.     uin.control.pControl = (CDeviceControl *)this;
  40.     uin.msg = DEVUINM_ONCONTROLDESTROY;
  41.     m_ui.Notify(uin);
  42.     if (m_ptszCaption)
  43.         free(m_ptszCaption);
  44.     delete m_pbmOverlay;
  45.     delete m_ptszOverlayPath;
  46. }
  47.  
  48. void CDeviceControl::SetCaption(LPCTSTR tszCaption, BOOL bFixed)
  49. {
  50.     LPTSTR tszNewCaption = NULL;
  51.  
  52.     m_bFixed = bFixed;
  53.  
  54.     if (tszCaption != NULL)
  55.     {
  56.         tszNewCaption = _tcsdup(tszCaption);
  57.  
  58.         if (tszNewCaption == NULL)
  59.             return;
  60.     }
  61.  
  62.     free(m_ptszCaption);
  63.     m_ptszCaption = tszNewCaption;
  64.     tszNewCaption = NULL;
  65.  
  66.     CalcCallout();
  67.     Invalidate();
  68. }
  69.  
  70. LPCTSTR CDeviceControl::GetCaption()
  71. {
  72.     return (LPCTSTR)m_ptszCaption;
  73. }
  74.  
  75. BOOL CDeviceControl::HitControl(POINT point)
  76. {
  77.     return FALSE;
  78. }
  79.  
  80. DEVCTRLHITRESULT CDeviceControl::HitTest(POINT test)
  81. {
  82.     if (!m_bInit)
  83.         return DCHT_NOHIT;
  84.  
  85.     if (m_ui.InEditMode() &&
  86.             PtInRect(&m_rectCalloutMax, test))
  87.         return DCHT_MAXRECT;
  88.  
  89.     PrepCallout();
  90.  
  91.     if (PtInRect(&m_rectCallout, test))
  92.         return DCHT_CAPTION;
  93.  
  94.     if (HitControl(test))
  95.         return DCHT_CONTROL;
  96.  
  97.     return DCHT_NOHIT;
  98. }
  99.  
  100. void CDeviceControl::Init()
  101. {
  102.     m_uin.from = DEVUINFROM_CONTROL;
  103.     m_uin.control.pControl = this;
  104.  
  105.     CalcCallout();
  106.  
  107.     m_bInit = TRUE;
  108. }
  109.  
  110. // We will have to know the view's scrolling offset to adjust the tooltip's position.
  111. void CDeviceControl::OnMouseOver(POINT point)
  112. {
  113.     // Tooltip only if the callout text is clipped.
  114.     if (m_bCaptionClipped)
  115.     {
  116.         TOOLTIPINITPARAM ttip;
  117.         ttip.hWndParent = m_view.m_hWnd;
  118.         ttip.iSBWidth = 0;
  119.         ttip.dwID = m_dwDeviceControlOffset;
  120.         ttip.hWndNotify = m_view.m_hWnd;
  121.         ttip.tszCaption = GetCaption();
  122.         CFlexToolTip::UpdateToolTipParam(ttip);
  123.     } else
  124.         CFlexWnd::s_ToolTip.SetToolTipParent(NULL);
  125.  
  126.     m_uin.msg = DEVUINM_MOUSEOVER;
  127.     m_ui.Notify(m_uin);
  128. }
  129.  
  130. void CDeviceControl::OnClick(POINT point, BOOL bLeft, BOOL bDoubleClick)
  131. {
  132.  
  133.     m_uin.msg = bDoubleClick ? DEVUINM_DOUBLECLICK : DEVUINM_CLICK;
  134.     m_uin.click.bLeftButton = bLeft;
  135.     m_ui.Notify(m_uin);
  136. }
  137.  
  138. void CDeviceControl::Unpopulate()
  139. {
  140. }
  141.  
  142. void CDeviceControl::Highlight(BOOL bHighlight)
  143. {
  144.     if (m_bHighlight == bHighlight)
  145.         return;
  146.  
  147.     m_bHighlight = bHighlight;
  148.  
  149.     // If the view has scrolling enabled, we need to adjust the scroll
  150.     // bar position to make this callout visible.
  151.     if (bHighlight)
  152.         m_view.ScrollToMakeControlVisible(m_rectCalloutMax);
  153.  
  154.     CalcCallout();
  155.  
  156.     // We do not invalidate rectangle if we are unhighlighting.  Let CDeviceView handle that.
  157.     if (bHighlight) Invalidate();
  158. }
  159.  
  160. void CDeviceControl::GetInfo(GUID &rGuid, DWORD &rdwOffset)
  161. {
  162.     m_ui.GetDeviceInstanceGuid(rGuid);
  163.     rdwOffset = m_dwDeviceControlOffset;
  164. }
  165.  
  166. BOOL CDeviceControl::PrepCaption()
  167. {
  168.     if (m_ptszCaption != NULL)
  169.         return TRUE;
  170.     m_ptszCaption = _tcsdup(g_tszUnassignedControlCaption);
  171.     return m_ptszCaption != NULL;
  172. }
  173.  
  174. void CDeviceControl::PrepLinePoints()
  175. {
  176.     if (m_nLinePoints > 0)
  177.         return;
  178.     m_nLinePoints = 1;
  179.     POINT pt = {0, 0};
  180.     if (m_dwCalloutAlign & CAF_LEFT)
  181.         pt.x = m_rectCalloutMax.left;
  182.     if (m_dwCalloutAlign & CAF_RIGHT)
  183.         pt.x = m_rectCalloutMax.right - 1;
  184.     if (m_dwCalloutAlign & CAF_TOP)
  185.         pt.y = m_rectCalloutMax.top;
  186.     if (m_dwCalloutAlign & CAF_BOTTOM)
  187.         pt.y = m_rectCalloutMax.bottom - 1;
  188.     if (!(m_dwCalloutAlign & (CAF_LEFT | CAF_RIGHT)))
  189.         pt.x = (m_rectCalloutMax.left + m_rectCalloutMax.right - 1) / 2;
  190.     if (!(m_dwCalloutAlign & (CAF_BOTTOM | CAF_TOP)))
  191.         pt.y = (m_rectCalloutMax.top + m_rectCalloutMax.bottom - 1) / 2;
  192.     m_rgptLinePoint[0] = pt;
  193. }
  194.  
  195. void CDeviceControl::PrepCallout()
  196. {
  197.     if (m_bCalledCalcCallout)
  198.         return;
  199.     CalcCallout();
  200. }
  201.  
  202. void CDeviceControl::PrepFont()
  203. {
  204.     if (m_FontHeight != -1)
  205.         return;
  206.  
  207.     HDC hDC = CreateCompatibleDC(NULL);
  208.     if (hDC != NULL)
  209.     {
  210.         RECT rect = {0, 0, 500, 1};
  211.         {
  212.             CPaintHelper ph(m_ui.m_uig, hDC);
  213.             ph.SetFont(UIF_CALLOUT);
  214.             m_FontHeight = DrawText(hDC, _T("Testify"), -1, &rect, m_dwDrawTextFlags);
  215.         }
  216.         DeleteDC(hDC);
  217.     }
  218. }
  219.  
  220. void CDeviceControl::CalcCallout()
  221. {
  222.     m_bCalledCalcCallout = TRUE;
  223.  
  224.     RECT max = m_rectCalloutMax;
  225.     InflateRect(&max, -1, -1);
  226.     RECT rect = max;
  227.     rect.bottom = rect.top + 1;
  228.  
  229.     m_dwDrawTextFlags = DT_WORDBREAK | DT_CALCRECT | DT_NOPREFIX | DT_END_ELLIPSIS | DT_EDITCONTROL;
  230.  
  231.     PrepFont();
  232.  
  233.     HDC hDC = CreateCompatibleDC(NULL);
  234.  
  235.     {
  236.         CPaintHelper ph(m_ui.m_uig, hDC);
  237.         ph.SetFont(UIF_CALLOUT);
  238.  
  239.         // first, drawtext/calcrect into the temporary rect
  240.         if (!PrepCaption())
  241.         {
  242.             return;
  243.         }
  244.  
  245.         int th = DrawText(hDC, m_ptszCaption, -1, &rect, m_dwDrawTextFlags);
  246.  
  247.         m_bCaptionClipped = rect.bottom > max.bottom || rect.right > max.right;  // Set clipped flag.
  248.         
  249.         BOOL bSingleTextLine = th <= m_FontHeight;
  250.  
  251.         if (rect.right > max.right)
  252.         {
  253.             bSingleTextLine = TRUE;
  254.             rect.right = max.right;
  255.         }
  256.  
  257.         if (bSingleTextLine)
  258.             m_dwDrawTextFlags &= ~DT_WORDBREAK;
  259.  
  260.         m_dwDrawTextFlags &= ~DT_CALCRECT;
  261.  
  262.         RECT rect2 = rect;
  263.         if (rect2.bottom > max.bottom)
  264.             rect2.bottom = max.bottom;
  265.         th = DrawText(hDC, m_ptszCaption, -1, &rect2, m_dwDrawTextFlags);
  266.         int ith = (th / m_FontHeight) * m_FontHeight;
  267.         rect.bottom = rect.top + ith + 1;
  268.     }
  269.  
  270.     DeleteDC(hDC);
  271.     hDC = NULL;
  272.  
  273.     if (rect.bottom > max.bottom)
  274.         rect.bottom = max.bottom;
  275.  
  276.     assert(rect.right <= max.right);
  277.     assert(rect.bottom <= max.bottom);
  278.  
  279.     PrepLinePoints();
  280.     POINT adj = {0, 0};
  281.  
  282.     assert(rect.left == max.left);
  283.     assert(rect.top == max.top);
  284.  
  285.     int w = rect.right - rect.left;
  286.     int h = rect.bottom - rect.top;
  287.     int mw = max.right - max.left;
  288.     int mh = max.bottom - max.top;
  289.     int dw = mw - w, dh = mh - h;
  290.     int cx = mw / 2 + max.left, cy = mh / 2 + max.top;
  291.     int cl = cx - w / 2, ct = cy - h / 2;
  292.  
  293.     assert(dw >= 0);
  294.     assert(dh >= 0);
  295.  
  296.     if (m_dwCalloutAlign & CAF_RIGHT && rect.right < max.right)
  297.         adj.x = max.right - rect.right;
  298.     if (m_dwCalloutAlign & CAF_BOTTOM && rect.bottom < max.bottom)
  299.         adj.y = max.bottom - rect.bottom;
  300.     if (!(m_dwCalloutAlign & (CAF_RIGHT | CAF_LEFT)) && w < mw && rect.left != cl)
  301.         adj.x = cl - rect.left;
  302.     if (!(m_dwCalloutAlign & (CAF_BOTTOM | CAF_TOP)) && h < mh && rect.top != ct)
  303.         adj.y = ct - rect.top;
  304.  
  305.     OffsetRect(&rect, adj.x, adj.y);
  306.  
  307.     InflateRect(&rect, 1, 1);
  308.  
  309.     m_rectCallout = rect;
  310. }
  311.  
  312. BOOL CDeviceControl::DrawOverlay(HDC hDC)
  313. {
  314.     if (m_pbmOverlay == NULL)
  315.         return FALSE;
  316.  
  317.     return m_pbmOverlay->Blend(hDC, m_ptOverlay);
  318. }
  319.  
  320. void CDeviceControl::OnPaint(HDC hDC)
  321. {
  322.     if (!m_bInit)
  323.         return;
  324.  
  325.     // If we are in view mode and the callout is not assigned, don't draw anything.
  326.     if (!m_ui.m_uig.InEditMode() && !lstrcmp(m_ptszCaption, g_tszUnassignedControlCaption))
  327.         return;
  328.  
  329.     PrepCallout();
  330.  
  331.     CPaintHelper ph(m_ui.m_uig, hDC);
  332.     UIELEMENT eCallout = m_bHighlight ? UIE_CALLOUTHIGH : UIE_CALLOUT;
  333.  
  334.     // draw lines...
  335.     if (m_nLinePoints > 1)
  336.     {
  337.         ph.SetElement(UIE_CALLOUTSHADOW);
  338.         PolyLineArrowShadow(hDC, m_rgptLinePoint, m_nLinePoints);
  339.         ph.SetElement(eCallout);
  340.         PolyLineArrow(hDC, m_rgptLinePoint, m_nLinePoints);
  341.     }
  342.  
  343.     // draw text
  344.     ph.SetElement(eCallout);
  345.     RECT rect = m_rectCallout;
  346.     InflateRect(&rect, -1, -1);
  347.  
  348.     // If this control is assigned an action with DIA_FIXED (m_bFixed), use gray color for text.
  349.     COLORREF OldColor;
  350.     if (m_bFixed)
  351.     {
  352.         OldColor = ::SetTextColor(hDC, 0);  // Set an arbitrary color to find out what we are currently using.
  353.         ::SetTextColor(hDC, RGB(GetRValue(OldColor) >> 1, GetGValue(OldColor) >> 1, GetBValue(OldColor) >> 1));
  354.     }
  355.     DrawText(hDC, m_ptszCaption, -1, &rect, m_dwDrawTextFlags);
  356.  
  357.     if (m_bFixed)
  358.         ::SetTextColor(hDC, OldColor);
  359. }
  360.  
  361. void CDeviceControl::Invalidate()
  362. {
  363.     m_view.Invalidate();
  364. }
  365.  
  366. void MakeRect(RECT &rect, POINT a, POINT b)
  367. {
  368.     rect.left = min(a.x, b.x);
  369.     rect.right = max(a.x, b.x);
  370.     rect.top = min(a.y, b.y);
  371.     rect.bottom = max(a.y, b.y);
  372. }
  373.  
  374. void CDeviceControl::PlaceCalloutMaxCorner(int nCorner, POINT point)
  375. {
  376.     switch (nCorner)
  377.     {
  378.         case 0:
  379.             m_ptFirstCorner = point;
  380.             m_bPlacedOnlyFirstCorner = TRUE;
  381.             Invalidate();
  382.             break;
  383.  
  384.         case 1:
  385.             MakeRect(m_rectCalloutMax, m_ptFirstCorner, point);
  386.             m_bPlacedOnlyFirstCorner = FALSE;
  387.             if (!m_bInit)
  388.                 Init();
  389.             else
  390.                 CalcCallout();
  391.             Invalidate();
  392.             break;
  393.  
  394.         default:
  395.             assert(0);
  396.             break;
  397.     }
  398. }
  399.  
  400. void CDeviceControl::SetLastLinePoint(int nPoint, POINT point, BOOL bShiftDown)
  401. {
  402.     if (!(nPoint >= 0 && nPoint < MAX_DEVICECONTROL_LINEPOINTS))
  403.         return;
  404.  
  405.     // Check for SHIFT key state
  406.     if (nPoint && bShiftDown)  // SHIFT key only makes a difference if we are setting 2nd and subsequent points.
  407.     {
  408.         // SHIFT key down.  Need to draw controlled line.
  409.         if (labs(m_rgptLinePoint[nPoint-1].x - point.x) > labs(m_rgptLinePoint[nPoint-1].y - point.y))
  410.         {
  411.             // Wider. Draw horizontal.
  412.             m_rgptLinePoint[nPoint].x = point.x;
  413.             m_rgptLinePoint[nPoint].y = m_rgptLinePoint[nPoint-1].y;
  414.         } else
  415.         {
  416.             // Taller. Draw vertical
  417.             m_rgptLinePoint[nPoint].x = m_rgptLinePoint[nPoint-1].x;
  418.             m_rgptLinePoint[nPoint].y = point.y;
  419.         }
  420.     } else
  421.         m_rgptLinePoint[nPoint] = point; // SHIFT key not down.  Draw line as usual.
  422.     m_nLinePoints = nPoint + 1;
  423.     Invalidate();
  424.  
  425.     if (m_nLinePoints < 2)
  426.         return;
  427.  
  428.     POINT prev = m_rgptLinePoint[m_nLinePoints - 2];
  429.  
  430.     // remove identical points
  431.     if (point.x == prev.x && point.y == prev.y)
  432.     {
  433.         m_nLinePoints--;
  434.         return;
  435.     }
  436. }
  437.  
  438. void PlaceRectCenter(RECT &rect, POINT point)
  439. {
  440.     POINT center = {
  441.         (rect.left + rect.right) / 2,
  442.         (rect.top + rect.bottom) / 2};
  443.  
  444.     OffsetRect(&rect, point.x - center.x, point.y - center.y);
  445. }
  446.  
  447. void OffsetRectToWithin(RECT &rect, const RECT &bounds)
  448. {
  449.     POINT adj = {0, 0};
  450.  
  451.     if (rect.left < bounds.left)
  452.         adj.x = bounds.left - rect.left;
  453.     if (rect.right > bounds.right)
  454.         adj.x = bounds.right - rect.right;
  455.     if (rect.top < bounds.top)
  456.         adj.y = bounds.top - rect.top;
  457.     if (rect.bottom > bounds.bottom)
  458.         adj.y = bounds.bottom - rect.bottom;
  459.  
  460.     OffsetRect(&rect, adj.x, adj.y);
  461. }
  462.  
  463. void CDeviceControl::Position(POINT point)
  464. {
  465.     PlaceRectCenter(m_rectCalloutMax, point);
  466.     RECT client;
  467.     m_view.GetClientRect(&client);
  468.     OffsetRectToWithin(m_rectCalloutMax, client);
  469.     CalcCallout();
  470.     Invalidate();
  471. }
  472.  
  473. void CDeviceControl::ConsiderAlignment(POINT point)
  474. {
  475.     POINT center = {
  476.         (m_rectCalloutMax.right + m_rectCalloutMax.left) / 2,
  477.         (m_rectCalloutMax.bottom + m_rectCalloutMax.top) / 2};
  478.     SIZE dim = {
  479.         m_rectCalloutMax.right - m_rectCalloutMax.left,
  480.         m_rectCalloutMax.bottom - m_rectCalloutMax.top};
  481.     SIZE delta = {point.x - center.x, point.y - center.y};
  482.     int MININ = m_FontHeight;
  483.     SIZE in = {max(dim.cx / 4, MININ), max(dim.cy / 4, MININ)};
  484.     DWORD align = 0;
  485.     if (delta.cx < -in.cx)
  486.         align |= CAF_LEFT;
  487.     if (delta.cx > in.cx)
  488.         align |= CAF_RIGHT;
  489.     if (delta.cy < -in.cy)
  490.         align |= CAF_TOP;
  491.     if (delta.cy > in.cy)
  492.         align |= CAF_BOTTOM;
  493.     m_dwCalloutAlign = align;
  494.     CalcCallout();
  495.     Invalidate();
  496. }
  497.  
  498. void CDeviceControl::ReselectControl()
  499. {
  500.     SelectControl(TRUE);
  501. }
  502.  
  503. void CDeviceControl::SelectControl(BOOL bReselect)
  504. {
  505.     CSelControlDlg dlg(m_view, *this, bReselect, m_dwDeviceControlOffset, m_ui.m_didi);
  506.  
  507.     switch (dlg.DoModal(m_view.m_hWnd))
  508.     {
  509.         case SCDR_OK:
  510.             m_dwDeviceControlOffset = dlg.GetOffset();
  511.             m_bOffsetAssigned = TRUE;
  512.             Invalidate();
  513.             break;
  514.  
  515.         case SCDR_CANCEL:
  516.             break;
  517.  
  518.         case SCDR_NOFREE:
  519.             MessageBox(m_view.m_hWnd, _T("All device controls have been assigned for this view."),
  520.                        _T("Can't reselect control."), MB_OK);
  521.             break;
  522.  
  523.         case -1:
  524.             MessageBox(m_view.m_hWnd, _T("CSelControlDlg.DoModal() failed."), _T("oops"), MB_OK);
  525.             break;
  526.  
  527.         default:
  528.             assert(0);
  529.             break;
  530.     }
  531. }
  532.  
  533. DWORD CDeviceControl::GetOffset()
  534. {
  535.     if (m_bOffsetAssigned)
  536.         return m_dwDeviceControlOffset;
  537.  
  538.     return (DWORD)-1;
  539. }
  540.  
  541. BOOL CDeviceControl::IsOffsetAssigned()
  542. {
  543.     return m_bOffsetAssigned;
  544. }
  545.  
  546. void CDeviceControl::FillImageInfo(DIDEVICEIMAGEINFOW *pImgInfo)
  547. {
  548.     if (!pImgInfo) return;
  549.  
  550.     if (m_ptszOverlayPath != NULL)
  551.         CopyStr(pImgInfo->tszImagePath, m_ptszOverlayPath, MAX_PATH);
  552.     else
  553.         wcscpy(pImgInfo->tszImagePath, L"");  // Overlay Image not yet supported
  554.  
  555.     SIZE size = {0, 0};
  556.     if (m_pbmOverlay != NULL)
  557.         m_pbmOverlay->GetSize(&size);
  558.     RECT rect = {m_ptOverlay.x, m_ptOverlay.y,
  559.         m_ptOverlay.x + size.cx, m_ptOverlay.y + size.cy};
  560.  
  561.     pImgInfo->dwFlags = DIDIFT_OVERLAY;  // This is an overlay
  562.     pImgInfo->rcOverlay = rect;
  563.     pImgInfo->dwObjID = GetOffset();
  564.     pImgInfo->dwcValidPts = m_nLinePoints;
  565.     DWORD dwPtsToCopy = m_nLinePoints > 5 ? 5 : m_nLinePoints;
  566.     for (DWORD i = 0; i < dwPtsToCopy; ++i)
  567.         pImgInfo->rgptCalloutLine[i] = m_rgptLinePoint[i];
  568.     pImgInfo->rcCalloutRect = m_rectCalloutMax;
  569.     pImgInfo->dwTextAlign = m_dwCalloutAlign;
  570. }
  571.  
  572.  
  573. BOOL CDeviceControl::IsMapped()
  574. {
  575.     return m_ui.IsControlMapped(this);
  576. }
  577.  
  578. int CDeviceControl::GetControlIndex()
  579. {
  580.     for (int i = 0; i < m_view.GetNumControls(); i++)
  581.         if (m_view.GetControl(i) == this)
  582.             return i;
  583.  
  584.     return -1;
  585. }
  586.  
  587. void CDeviceControl::SetLinePoints(int n, POINT *rgpt)
  588. {
  589.     assert(n >= 0 && n <= MAX_DEVICECONTROL_LINEPOINTS && rgpt);
  590.  
  591.     if (n < 0)
  592.         n = 0;
  593.     if (n > MAX_DEVICECONTROL_LINEPOINTS)
  594.         n = MAX_DEVICECONTROL_LINEPOINTS;
  595.  
  596.     if (!rgpt)
  597.         n = 0;
  598.  
  599.     m_nLinePoints = n;
  600.  
  601.     for (int i = 0; i < n; i++)
  602.         m_rgptLinePoint[i] = rgpt[i];
  603. }
  604.  
  605. void CDeviceControl::SetOverlayPath(LPCTSTR tszPath)
  606. {
  607.     if (m_ptszOverlayPath)
  608.         free(m_ptszOverlayPath);
  609.     m_ptszOverlayPath = NULL;
  610.  
  611.     if (tszPath)
  612.         m_ptszOverlayPath = _tcsdup(tszPath);
  613.  
  614.     delete m_pbmOverlay;
  615.     m_pbmOverlay = NULL;
  616.  
  617.     if (m_ptszOverlayPath)
  618.         m_pbmOverlay = CBitmap::CreateViaD3DX(m_ptszOverlayPath, m_ui.m_uig.GetSurface3D());
  619. }
  620.  
  621. void CDeviceControl::SetOverlayRect(const RECT &r)
  622. {
  623.     m_ptOverlay.x = r.left;
  624.     m_ptOverlay.y = r.top;
  625. }
  626.