home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / tutsamp / conclien / guiball.h < prev    next >
C/C++ Source or Header  |  1997-08-05  |  5KB  |  128 lines

  1. /*+==========================================================================
  2.   File:      GUIBALL.H
  3.  
  4.   Summary:   Include file for the CGuiBall C++ class. A GuiBall is a C++
  5.              object that moves and displays a bouncing ball in the client
  6.              area of a designated window. GuiBall is anchored to the
  7.              Windows GUI (Graphical User Interface) environment. This
  8.              GuiBall object continuously paints a ball image based on data
  9.              it obtains from a virtual ball object. This virtual ball
  10.              object is instantiated as a COM object (a COBall) in a
  11.              separate In-process server, CONSERVE.
  12.  
  13.              GuiBall uses the system timer to issue WM_TIMER messages that
  14.              cause a continuous moving and displaying of the ball. GuiBall
  15.              provides methods to initialize the GuiBall, paint the ball
  16.              image, and restart the motion.
  17.  
  18.              For a comprehensive tutorial code tour of GUIBALL's contents
  19.              and offerings see the tutorial CONCLIEN.HTM file. For more
  20.              specific technical details on the internal workings see the
  21.              comments dispersed throughout the GUIBALL source code.
  22.  
  23.   Classes:   CGuiBall
  24.  
  25.   Origin:    5-30-96: atrent - Editor inheritance from GUIBALL.H in the
  26.              FRECLIEN source.
  27. ----------------------------------------------------------------------------
  28.   This file is part of the Microsoft COM Tutorial Code Samples.
  29.  
  30.   Copyright (C) Microsoft Corporation, 1997.  All rights reserved.
  31.  
  32.   This source code is intended only as a supplement to Microsoft
  33.   Development Tools and/or on-line documentation.  See these other
  34.   materials for detailed information regarding Microsoft code samples.
  35.  
  36.   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  37.   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  38.   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  39.   PARTICULAR PURPOSE.
  40. ==========================================================================+*/
  41.  
  42. #if !defined(GUIBALL_H)
  43. #define GUIBALL_H
  44.  
  45. #if defined(__cplusplus)
  46.  
  47.  
  48. // Here are constants for the delays in milliseconds that control
  49. // the incremental motion of the ball and how often a snapshot of
  50. // the ball image is painted. Other constants are for the ball's
  51. // bounce sound.
  52. enum
  53. {
  54.   BALL_PAINT_DELAY  = 30,
  55.   BALL_MOVE_DELAY = 100,
  56.   BOUNCE_SOUND_DURATION = 30,
  57.   BOUNCE_BOTTOM_FREQUENCY = 800,
  58.   BOUNCE_SIDE_FREQUENCY = 2400,
  59.   BOUNCE_TOP_FREQUENCY = 4800
  60. };
  61.  
  62.  
  63. /*C+C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C
  64.   Class:    CGuiBall
  65.  
  66.   Summary:  Class to encapsulate the displayable Graphical User
  67.             Interface GUI Ball object.
  68.  
  69.   Methods:  CGuiBall
  70.               Constructor.
  71.             ~CGuiBall
  72.               Destructor.
  73.             BOOL Init(HWND hWnd);
  74.               Initialize the GuiBall.
  75.             void PaintBall(void);
  76.               Paint one image of the Ball.
  77.             void Restart(void);
  78.               Restart the process including clear window, move ball to
  79.               start position, restart motion.
  80.             void PaintWin(void);
  81.               Repaint the window but don't restart motion.
  82.             void BounceBottom(void);
  83.             void BounceSide(void);
  84.             void BounceTop(void);
  85.               Perform GUI acton associated with these bounce events.
  86.             HRESULT ConnectBallSink(void);
  87.               Connect the BallSink to the server COBall source.
  88.             HRESULT DisconnectBallSink(void);
  89.               Disconnect the BallSink from the server COBall source.
  90.             IConnectionPoint* GetConnectionPoint(REFIID riid);
  91.               Private method to obtain a connection point interface.
  92. C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C-C*/
  93. class CGuiBall
  94. {
  95.   public:
  96.     CGuiBall(void);
  97.     ~CGuiBall(void);
  98.     BOOL Init(HWND hWnd);
  99.     void PaintBall(void);
  100.     void Restart(void);
  101.     void PaintWin(void);
  102.     void BounceBottom(void);
  103.     void BounceSide(void);
  104.     void BounceTop(void);
  105.     HRESULT ConnectBallSink(void);
  106.     HRESULT DisconnectBallSink(void);
  107.  
  108.   private:
  109.     HWND       m_hWnd;
  110.     IBall*     m_pIBall;
  111.     COLORREF   m_crColor;
  112.     POINT      m_OldPos;
  113.     POINT      m_OldExt;
  114.     IUnknown*  m_pCOBallSink;
  115.     DWORD      m_dwBallSink;
  116.     DWORD      m_dwBounceSndDur;
  117.     DWORD      m_dwBounceBotFreq;
  118.     DWORD      m_dwBounceSideFreq;
  119.     DWORD      m_dwBounceTopFreq;
  120.  
  121.     IConnectionPoint* GetConnectionPoint(REFIID riid);
  122. };
  123.  
  124.  
  125. #endif // __cplusplus
  126.  
  127. #endif
  128.