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 / chap07 / patron / pages.h < prev    next >
C/C++ Source or Header  |  1995-05-03  |  6KB  |  199 lines

  1. /*
  2.  * PAGES.H
  3.  * Patron Chapter 7
  4.  *
  5.  * Definitions and function prototypes for the Pages window control.
  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 _PAGES_H_
  16. #define _PAGES_H_
  17.  
  18. //Versioning.
  19. #define VERSIONMAJOR                2
  20. #define VERSIONMINOR                0
  21. #define VERSIONCURRENT              0x00020000
  22.  
  23. //Classname
  24. #define SZCLASSPAGES                TEXT("pages")
  25.  
  26. #define HIMETRIC_PER_INCH           2540
  27. #define LOMETRIC_PER_INCH           254
  28. #define LOMETRIC_BORDER             60          //Border around page
  29.  
  30.  
  31. //Window extra bytes and offsets
  32. #define CBPAGESWNDEXTRA             (sizeof(LONG))
  33. #define PAGEWL_STRUCTURE            0
  34.  
  35.  
  36. /*
  37.  * Page class describing an individual page and what things it
  38.  * contains, managing an IStorage for us.
  39.  *
  40.  * A DWORD is used to identify this page as the name of the storage
  41.  * is the string form of this ID.  If we added a page every second,
  42.  * it would take 136 years to overrun this counter, so we can
  43.  * get away with saving it persistently.  I hope this software is
  44.  * obsolete by then.
  45.  */
  46.  
  47. class CPage
  48.     {
  49.     private:
  50.         DWORD       m_dwID;             //Persistent identifier
  51.         //CHAPTER7MOD
  52.         LPSTORAGE   m_pIStorage;        //Substorage for this page
  53.         //End CHAPTER7MOD
  54.  
  55.     public:
  56.         CPage(DWORD);
  57.         ~CPage(void);
  58.  
  59.         DWORD       GetID(void);
  60.         //CHAPTER7MOD
  61.         BOOL        Open(LPSTORAGE);
  62.         void        Close(BOOL);
  63.         BOOL        Update(void);
  64.         void        Destroy(LPSTORAGE);
  65.         UINT        GetStorageName(LPOLESTR);
  66.         //End CHAPTER7MOD
  67.     };
  68.  
  69. typedef CPage *PCPage;
  70.  
  71.  
  72.  
  73. //CHAPTER7MOD
  74.  
  75. /*
  76.  * Structures to save with the document describing the device
  77.  * configuration and pages that we have. This is followed by
  78.  * a list of DWORD IDs for the individual pages.  Note that
  79.  * the strings use TCHAR as a matter of convenience, meaning
  80.  * that non-Unicode files and Unicode files will be incompatible.
  81.  * The same goes for the DEVMODE structure that we store here.
  82.  * If this were a real application that had both types of
  83.  * binaries, then this would be important, but not for this sample.
  84.  */
  85.  
  86. typedef struct tagDEVICECONFIG
  87.     {
  88.     DWORD       cb;                         //Size of structure
  89.     TCHAR       szDriver[CCHDEVICENAME];
  90.     TCHAR       szDevice[CCHDEVICENAME];
  91.     TCHAR       szPort[CCHDEVICENAME];
  92.     DWORD       cbDevMode;                  //Size of actual DEVMODE
  93.     DEVMODE     dm;                         //Variable
  94.     } DEVICECONFIG, *PDEVICECONFIG;
  95.  
  96. //Offset to cbDevMode
  97. #define CBSEEKOFFSETCBDEVMODE  (sizeof(DWORD)   \
  98.                                +(3*CCHDEVICENAME*sizeof(TCHAR)))
  99.  
  100. typedef struct tagPAGELIST
  101.     {
  102.     DWORD       cPages;
  103.     DWORD       iPageCur;
  104.     DWORD       dwIDNext;
  105.     } PAGELIST, *PPAGELIST;
  106.  
  107. //End CHAPTER7MOD
  108.  
  109.  
  110. //PRINT.CPP
  111. BOOL    APIENTRY PrintDlgProc(HWND, UINT, WPARAM, LPARAM);
  112. BOOL    APIENTRY AbortProc(HDC, int);
  113.  
  114.  
  115. //PAGEWIN.CPP
  116. LRESULT APIENTRY PagesWndProc(HWND, UINT, WPARAM, LPARAM);
  117. void             RectConvertMappings(LPRECT, HDC, BOOL);
  118.  
  119.  
  120. class CPages : public CWindow
  121.     {
  122.     friend LRESULT APIENTRY PagesWndProc(HWND, UINT, WPARAM, LPARAM);
  123.     friend BOOL    APIENTRY PrintDlgProc(HWND, UINT, WPARAM, LPARAM);
  124.  
  125.     private:
  126.         UINT        m_iPageCur;             //Current page
  127.         UINT        m_cPages;               //Number of pages
  128.  
  129.         HWND        m_hWndPageList;         //Listbox with page list
  130.         HFONT       m_hFont;                //Page font
  131.         BOOL        m_fSystemFont;          //m_hFont system object?
  132.  
  133.         UINT        m_cx;                   //Page size in LOMETRIC
  134.         UINT        m_cy;
  135.  
  136.         UINT        m_xMarginLeft;          //Unusable margins,
  137.         UINT        m_xMarginRight;         //in LOMETRIC
  138.         UINT        m_yMarginTop;
  139.         UINT        m_yMarginBottom;
  140.  
  141.         UINT        m_xPos;                 //Viewport scroll pos,
  142.         UINT        m_yPos;                 //both in *PIXELS*
  143.  
  144.         DWORD       m_dwIDNext;             //Next ID for a page.
  145.  
  146.         //CHAPTER7MOD
  147.         LPSTORAGE   m_pIStorage;            //Root storage
  148.  
  149.         //m_hDevMode, m_szDriver, m_szDevice, m_szPort removed
  150.         //End CHAPTER7MOD
  151.  
  152.     private:
  153.         void        Draw(HDC, BOOL, BOOL);
  154.         void        UpdateScrollRanges(void);
  155.         BOOL        ConfigureForDevice(void);
  156.         BOOL        PageGet(UINT, PCPage *, BOOL);
  157.         BOOL        PageAdd(UINT, DWORD, BOOL);
  158.  
  159.     public:
  160.         CPages(HINSTANCE);
  161.         ~CPages(void);
  162.  
  163.         BOOL        Init(HWND, LPRECT, DWORD, UINT, LPVOID);
  164.  
  165.         //CHAPTER7MOD
  166.         BOOL        StorageSet(LPSTORAGE, BOOL, BOOL);
  167.         BOOL        StorageUpdate(BOOL);
  168.         //End CHAPTER7MOD
  169.  
  170.         BOOL        Print(HDC, LPTSTR, DWORD, UINT, UINT, UINT);
  171.  
  172.         void        RectGet(LPRECT);
  173.         void        RectSet(LPRECT, BOOL);
  174.         void        SizeGet(LPRECT);
  175.         void        SizeSet(LPRECT, BOOL);
  176.  
  177.         PCPage      ActivePage(void);
  178.         UINT        PageInsert(UINT);
  179.         UINT        PageDelete(UINT);
  180.         UINT        CurPageGet(void);
  181.         UINT        CurPageSet(UINT);
  182.         UINT        NumPagesGet(void);
  183.  
  184.         BOOL        DevModeSet(HGLOBAL, HGLOBAL);
  185.         HGLOBAL     DevModeGet(void);
  186.     };
  187.  
  188. typedef CPages *PCPages;
  189.  
  190.  
  191. //CHAPTER7MOD
  192. //Fixed names of streams in the Pages IStorage
  193. #define SZSTREAMPAGELIST        OLETEXT("Page List")
  194. #define SZSTREAMDEVICECONFIG    OLETEXT("Device Configuration")
  195. //End CHAPTER7MOD
  196.  
  197.  
  198. #endif  //_PAGES_H_
  199.