home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / chap04 / connect / connect.h < prev    next >
C/C++ Source or Header  |  1995-05-03  |  3KB  |  125 lines

  1. /*
  2.  * CONNECT.H
  3.  * Connectable Object Sample, Chapter 4
  4.  *
  5.  * Definitions, classes, and prototypes
  6.  *
  7.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Microsoft
  10.  * Internet  :  kraigb@microsoft.com
  11.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  12.  */
  13.  
  14.  
  15. #ifndef _QUERY_H_
  16. #define _QUERY_H_
  17.  
  18. #define CHAPTER4
  19. #define INC_CONTROLS
  20. #include <inole.h>
  21.  
  22. #ifndef RC_INVOKED
  23. #include "interfac.h"
  24. #include "object.h"
  25. #endif
  26.  
  27. //Menu Resource ID and Commands
  28. #define IDR_MENU                    1
  29.  
  30. #define IDM_OBJECTCREATE            100
  31. #define IDM_OBJECTRELEASE           101
  32. #define IDM_OBJECTSINK1CONNECT      102
  33. #define IDM_OBJECTSINK1DISCONNECT   103
  34. #define IDM_OBJECTSINK2CONNECT      104
  35. #define IDM_OBJECTSINK2DISCONNECT   105
  36. #define IDM_OBJECTEXIT              106
  37.  
  38. #define IDM_TRIGGERQUACK            200
  39. #define IDM_TRIGGERFLAP             201
  40. #define IDM_TRIGGERPADDLE           202
  41.  
  42.  
  43.  
  44. //CONNECT.CPP
  45. LRESULT APIENTRY ConnectWndProc(HWND, UINT, WPARAM, LPARAM);
  46.  
  47. class CDuckEvents;
  48. typedef CDuckEvents *PCDuckEvents;
  49.  
  50. //Identifiers for sinks, indices into m_rgpSink below
  51. enum
  52.     {
  53.     SINK1=0,
  54.     SINK2
  55.     };
  56.  
  57.  
  58. class CApp
  59.     {
  60.     friend LRESULT APIENTRY ConnectWndProc(HWND, UINT, WPARAM, LPARAM);
  61.  
  62.     protected:
  63.         HINSTANCE       m_hInst;            //WinMain parameters
  64.         HINSTANCE       m_hInstPrev;
  65.         UINT            m_nCmdShow;
  66.  
  67.         HWND            m_hWnd;             //Main window handle
  68.         PCDuckEvents    m_rgpSink[2];       //Sinks to connect
  69.  
  70.         /*
  71.          * We need to have a pointer to the full object in
  72.          * this somewhat contrived example because we have to
  73.          * tell it when to fire notifications.  Usually there
  74.          * will be something else besides a menu as used in
  75.          * this sample to trigger those firings.
  76.          */
  77.         PCConnObject    m_pObj;             //Source object
  78.  
  79.     protected:
  80.         void              Connect(UINT);
  81.         void              Disconnect(UINT);
  82.         IConnectionPoint *GetConnectionPoint(void);
  83.  
  84.     public:
  85.         CApp(HINSTANCE, HINSTANCE, UINT);
  86.         ~CApp(void);
  87.         BOOL        Init(void);
  88.         void        Message(LPTSTR);
  89.     };
  90.  
  91.  
  92. typedef CApp *PAPP;
  93.  
  94. #define CBWNDEXTRA          sizeof(PAPP)
  95. #define CONNECTWL_STRUCTURE 0
  96.  
  97.  
  98. class CDuckEvents : public IDuckEvents
  99.     {
  100.     private:
  101.         ULONG       m_cRef;     //Reference count
  102.         PAPP        m_pApp;     //For calling Message
  103.         UINT        m_uID;      //Sink identifier
  104.  
  105.     public:
  106.         //Connection key, public for CApp's usage
  107.         DWORD       m_dwCookie;
  108.  
  109.     public:
  110.         CDuckEvents(PAPP, UINT);
  111.         ~CDuckEvents(void);
  112.  
  113.         //IUnknown members
  114.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  115.         STDMETHODIMP_(DWORD) AddRef(void);
  116.         STDMETHODIMP_(DWORD) Release(void);
  117.  
  118.         //IDuckEvents members
  119.         STDMETHODIMP Quack(void);
  120.         STDMETHODIMP Flap(void);
  121.         STDMETHODIMP Paddle(void);
  122.     };
  123.  
  124. #endif //_CONNECT_H_
  125.