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 / chap02 / enumrect / enumrect.h < prev    next >
C/C++ Source or Header  |  1995-05-03  |  4KB  |  169 lines

  1. /*
  2.  * ENUMRECT.H
  3.  * C/C++ Enumerator Demonstrtion Chapter 2
  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 _ENUMRECT_H_
  16. #define _ENUMRECT_H_
  17.  
  18. #define CHAPTER2
  19. #include <inole.h>
  20. #ifndef WIN32
  21. #include <malloc.h>
  22. #endif
  23. #include "ienum.h"  //Interface definitions
  24.  
  25.  
  26. //Menu Resource ID and Commands
  27. #define IDR_MENU                    1
  28.  
  29. #define IDM_ENUMCREATEC             100
  30. #define IDM_ENUMCREATECPP           101
  31. #define IDM_ENUMRELEASE             102
  32. #define IDM_ENUMRUNTHROUGH          103
  33. #define IDM_ENUMEVERYTHIRD          104
  34. #define IDM_ENUMRESET               105
  35. #define IDM_ENUMCLONE               106
  36. #define IDM_ENUMEXIT                107
  37.  
  38.  
  39. //Number of rects that objects with IEnumRECT support (for demo)
  40. #define CRECTS      15
  41.  
  42.  
  43. //Skip the C++ stuff when this file is included from ENUMC.C
  44. #ifdef __cplusplus
  45.  
  46. //ENUMRECT.CPP
  47. LRESULT APIENTRY EnumWndProc(HWND, UINT, WPARAM, LPARAM);
  48.  
  49. class CApp
  50.     {
  51.     friend LRESULT APIENTRY EnumWndProc(HWND, UINT, WPARAM, LPARAM);
  52.  
  53.     protected:
  54.         HINSTANCE       m_hInst;            //WinMain parameters
  55.         HINSTANCE       m_hInstPrev;
  56.         UINT            m_nCmdShow;
  57.  
  58.         HWND            m_hWnd;             //Main window handle
  59.         PENUMRECT       m_pIEnumRect;       //Enumerator object
  60.  
  61.     public:
  62.         CApp(HINSTANCE, HINSTANCE, UINT);
  63.         ~CApp(void);
  64.  
  65.         BOOL Init(void);
  66.         void Message(LPTSTR);
  67.     };
  68.  
  69.  
  70. typedef CApp *PAPP;
  71.  
  72. #define CBWNDEXTRA          sizeof(PAPP)
  73. #define ENUMWL_STRUCTURE    0
  74.  
  75.  
  76. //ENUMCPP.CPP
  77.  
  78. /*
  79.  * The class definition for an object that singly implements
  80.  * IEnumRECT in C++.
  81.  */
  82. class CEnumRect : public IEnumRECT
  83.     {
  84.     private:
  85.         DWORD           m_cRef;         //Reference count
  86.         DWORD           m_iCur;         //Current enum position
  87.         RECT            m_rgrc[CRECTS]; //RECTS we enumerate
  88.  
  89.     public:
  90.         CEnumRect(void);
  91.         ~CEnumRect(void);
  92.  
  93.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  94.         STDMETHODIMP_(ULONG) AddRef(void);
  95.         STDMETHODIMP_(ULONG) Release(void);
  96.  
  97.         //IEnumRECT members
  98.         STDMETHODIMP Next(ULONG, LPRECT, ULONG *);
  99.         STDMETHODIMP Skip(ULONG);
  100.         STDMETHODIMP Reset(void);
  101.         STDMETHODIMP Clone(PENUMRECT *);
  102.     };
  103.  
  104.  
  105. typedef CEnumRect *PCEnumRect;
  106.  
  107.  
  108. //Function that creates one of these objects
  109. BOOL CreateRECTEnumeratorCPP(PENUMRECT *);
  110.  
  111.  
  112. //End of __cplusplus
  113.  
  114. #else
  115.  
  116. //Start of non __cplusplus definitions
  117.  
  118. //ENUMC.C
  119.  
  120. /*
  121.  * The structure definition for an object that singly implements
  122.  * IEnumRECT in C.  We make a class by reusing the elements of
  123.  * the IEnumRECT structure thereby inheriting from it, albeit
  124.  * manually.
  125.  */
  126.  
  127. typedef struct tagRECTENUMERATOR
  128.     {
  129.     IEnumRECTVtbl  *lpVtbl;
  130.     DWORD           m_cRef;         //Reference count
  131.     DWORD           m_iCur;         //Current enum position
  132.     RECT            m_rgrc[CRECTS]; //RECTS we enumerate
  133.     } RECTENUMERATOR, *PRECTENUMERATOR;
  134.  
  135.  
  136. /*
  137.  * In C we have to separately declare member functions with
  138.  * globally unique names, so prefixing with the class name
  139.  * should remove any conflicts.
  140.  */
  141.  
  142. PRECTENUMERATOR RECTENUM_Constructor(void);
  143. void            RECTENUM_Destructor(PRECTENUMERATOR);
  144.  
  145. STDMETHODIMP    RECTENUM_QueryInterface(PENUMRECT, REFIID, PPVOID);
  146. STDMETHODIMP_(ULONG) RECTENUM_AddRef(PENUMRECT);
  147. STDMETHODIMP_(ULONG) RECTENUM_Release(PENUMRECT);
  148. STDMETHODIMP    RECTENUM_Next(PENUMRECT, DWORD, LPRECT, LPDWORD);
  149. STDMETHODIMP    RECTENUM_Skip(PENUMRECT, DWORD);
  150. STDMETHODIMP    RECTENUM_Reset(PENUMRECT);
  151. STDMETHODIMP    RECTENUM_Clone(PENUMRECT, PENUMRECT *);
  152.  
  153.  
  154. //End of __cplusplus conditions
  155.  
  156. #endif
  157.  
  158. #ifdef __cplusplus
  159. extern "C"
  160.     {
  161. #endif
  162.     //Function that creates one of these objects
  163.     BOOL CreateRECTEnumeratorC(PENUMRECT *);
  164. #ifdef __cplusplus
  165.     }
  166. #endif
  167.  
  168. #endif //_ENUMRECT_H_
  169.