home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 16.ddi / MFC / INCLUDE / AFXWIN.H_ / AFXWIN.H
Encoding:
C/C++ Source or Header  |  1993-02-08  |  89.3 KB  |  2,864 lines

  1. // Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992 Microsoft Corporation,
  3. // All rights reserved.
  4.  
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and Microsoft
  7. // QuickHelp and/or WinHelp documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #ifndef __AFXWIN_H__
  12. #ifndef RC_INVOKED
  13. #define __AFXWIN_H__
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // Make sure 'afx.h' is included first
  17.  
  18. #ifndef __AFX_H__
  19. #ifndef _WINDOWS
  20. #define _WINDOWS
  21. #endif
  22. #include "afx.h"
  23. #else
  24. #ifndef _WINDOWS
  25.     #error Please #define _WINDOWS before including afx.h
  26. #endif
  27. #endif
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // Classes declared in this file
  31.  
  32. class CSize;
  33. class CPoint;
  34. class CRect;
  35.  
  36. //CObject
  37.     //CException
  38.         class CResourceException;// Win resource failure exception
  39.         class CUserException;    // Message Box alert and stop operation
  40.  
  41.     class CGdiObject;            // CDC drawing tool
  42.         class CPen;              // a pen / HPEN wrapper
  43.         class CBrush;            // a brush / HBRUSH wrapper
  44.         class CFont;             // a font / HFONT wrapper
  45.         class CBitmap;           // a bitmap / HBITMAP wrapper
  46.         class CPalette;          // a palette / HPALLETE wrapper
  47.         class CRgn;              // a region / HRGN wrapper
  48.  
  49.     class CDC;                   // a Display Context / HDC wrapper
  50.         class CClientDC;         // CDC for client of window
  51.         class CWindowDC;         // CDC for entire window
  52.         class CPaintDC;          // embeddable BeginPaint struct helper
  53.  
  54.     class CMenu;                 // a menu / HMENU wrapper
  55.  
  56.     class CCmdTarget;            // a target for user commands
  57.         class CWnd;                  // a window / HWND wrapper
  58.             class CDialog;           // a dialog
  59.  
  60.             // standard windows controls
  61.             class CStatic;           // Static control
  62.             class CButton;           // Button control
  63.             class CListBox;          // ListBox control
  64.             class CComboBox;         // ComboBox control
  65.             class CEdit;             // Edit control
  66.             class CScrollBar;        // ScrollBar control
  67.  
  68.             // frame windows
  69.             class CFrameWnd;         // standard SDI frame
  70.                 class CMDIFrameWnd;  // standard MDI frame
  71.                 class CMDIChildWnd;  // standard MDI child
  72.  
  73.             // views on a document
  74.             class CView;             // a view on a document
  75.                 class CScrollView;   // a scrolling view
  76.  
  77.         class CWinApp;               // application base class
  78.  
  79.         class CDocTemplate;          // template for document creation
  80.             class CSingleDocTemplate;// SDI support
  81.             class CMultiDocTemplate; // MDI support
  82.  
  83.         class CDocument;             // main document abstraction
  84.  
  85.  
  86. // Helper classes
  87. class CCmdUI;                    // Menu/button enabling
  88. class AFX_STACK_DATA CDataExchange;     // Data exchange and validation context
  89.  
  90. /////////////////////////////////////////////////////////////////////////////
  91.  
  92. // we must include certain parts of Windows.h
  93. #undef NOKERNEL
  94. #undef NOGDI
  95. #undef NOUSER
  96. #undef NOSOUND
  97. #undef NOCOMM
  98. #undef NODRIVERS
  99. #undef NOLOGERROR
  100. #undef NOPROFILER
  101. #undef NOMEMMGR
  102. #undef NOLFILEIO
  103. #undef NOOPENFILE
  104. #undef NORESOURCE
  105. #undef NOATOM
  106. #undef NOLANGUAGE
  107. #undef NOLSTRING
  108. #undef NODBCS
  109. #undef NOKEYBOARDINFO
  110. #undef NOGDICAPMASKS
  111. #undef NOCOLOR
  112. #undef NOGDIOBJ
  113. #undef NODRAWTEXT
  114. #undef NOTEXTMETRIC
  115. #undef NOSCALABLEFONT
  116. #undef NOBITMAP
  117. #undef NORASTEROPS
  118. #undef NOMETAFILE
  119. #undef NOSYSMETRICS
  120. #undef NOSYSTEMPARAMSINFO
  121. #undef NOMSG
  122. #undef NOWINSTYLES
  123. #undef NOWINOFFSETS
  124. #undef NOSHOWWINDOW
  125. #undef NODEFERWINDOWPOS
  126. #undef NOVIRTUALKEYCODES
  127. #undef NOKEYSTATES
  128. #undef NOWH
  129. #undef NOMENUS
  130. #undef NOSCROLL
  131. #undef NOCLIPBOARD
  132. #undef NOICONS
  133. #undef NOMB
  134. #undef NOSYSCOMMANDS
  135. #undef NOMDI
  136. #undef NOCTLMGR
  137. #undef NOWINMESSAGES
  138.  
  139. // MFC applications may be built with WINVER == 0x300 (Win 3.0 only)
  140. // or WINVER == 0x030A (Win 3.1/3.0)
  141.  
  142. #include "windows.h"
  143.  
  144. #ifndef WINVER
  145.     #error Please include a more recent WINDOWS.H
  146. #endif
  147.  
  148.  
  149. #if (WINVER >= 0x030a)
  150. #include "shellapi.h"
  151. #endif
  152.  
  153. #ifndef __AFXRES_H__
  154. #include "afxres.h"     // standard resource IDs
  155. #endif
  156.  
  157. #ifndef __AFXCOLL_H__
  158. #include "afxcoll.h"    // standard collections
  159. #endif
  160.  
  161. #ifndef _INC_PRINT
  162. #include "print.h"      // needed for ResetDC and DEVMODE definitions
  163. #endif
  164.  
  165. #ifdef _INC_WINDOWSX
  166. // The following names from WINDOWSX.H collide with names in this header
  167. #undef SubclassWindow
  168. #undef CopyRgn
  169. #endif
  170.  
  171. // Type modifier for message handlers
  172. #define afx_msg         // intentional placeholder
  173.  
  174. // AFXDLL support
  175. #undef AFXAPP_DATA
  176. #define AFXAPP_DATA     AFXAPI_DATA
  177.  
  178. /////////////////////////////////////////////////////////////////////////////
  179. // Win 3.1 types provided for Win3.0 as well
  180.  
  181. #if (WINVER < 0x030a)
  182. typedef struct tagSIZE
  183. {
  184.     int cx;
  185.     int cy;
  186. } SIZE;
  187. typedef SIZE*       PSIZE;
  188. typedef SIZE NEAR* NPSIZE;
  189. typedef SIZE FAR*  LPSIZE;
  190.  
  191. typedef struct
  192. {
  193.     int     cbSize;
  194.     LPCSTR  lpszDocName;
  195.     LPCSTR  lpszOutput;
  196. }   DOCINFO;
  197. typedef DOCINFO FAR* LPDOCINFO;
  198. #define HDROP   HANDLE
  199. #endif // WINVER < 0x030a
  200.  
  201. /////////////////////////////////////////////////////////////////////////////
  202. // CSize - An extent, similar to Windows SIZE structure.
  203.  
  204. class CSize : public tagSIZE
  205. {
  206. public:
  207.  
  208. // Constructors
  209.     CSize();
  210.     CSize(int initCX, int initCY);
  211.     CSize(SIZE initSize);
  212.     CSize(POINT initPt);
  213.     CSize(DWORD dwSize);
  214.  
  215. // Operations
  216.     BOOL operator==(SIZE size) const;
  217.     BOOL operator!=(SIZE size) const;
  218.     void operator+=(SIZE size);
  219.     void operator-=(SIZE size);
  220.  
  221. // Operators returning CSize values
  222.     CSize operator+(SIZE size) const;
  223.     CSize operator-(SIZE size) const;
  224.     CSize operator-() const;
  225. };
  226.  
  227. /////////////////////////////////////////////////////////////////////////////
  228. // CPoint - A 2-D point, similar to Windows POINT structure.
  229.  
  230. class CPoint : public tagPOINT
  231. {
  232. public:
  233.  
  234. // Constructors
  235.     CPoint();
  236.     CPoint(int initX, int initY);
  237.     CPoint(POINT initPt);
  238.     CPoint(SIZE initSize);
  239.     CPoint(DWORD dwPoint);
  240.  
  241. // Operations
  242.     void Offset(int xOffset, int yOffset);
  243.     void Offset(POINT point);
  244.     void Offset(SIZE size);
  245.     BOOL operator==(POINT point) const;
  246.     BOOL operator!=(POINT point) const;
  247.     void operator+=(SIZE size);
  248.     void operator-=(SIZE size);
  249.  
  250. // Operators returning CPoint values
  251.     CPoint operator+(SIZE size) const;
  252.     CPoint operator-(SIZE size) const;
  253.     CPoint operator-() const;
  254.  
  255. // Operators returning CSize values
  256.     CSize operator-(POINT point) const;
  257. };
  258.  
  259. /////////////////////////////////////////////////////////////////////////////
  260. // CRect - A 2-D rectangle, similar to Windows RECT structure.
  261.  
  262. typedef const RECT FAR* LPCRECT;       // far pointer to read/only RECT
  263.  
  264. class CRect : public tagRECT
  265. {
  266. public:
  267.  
  268. // Constructors
  269.     CRect();
  270.     CRect(int l, int t, int r, int b);
  271.     CRect(const RECT& srcRect);
  272.     CRect(LPCRECT lpSrcRect);
  273.     CRect(POINT point, SIZE size);
  274.  
  275. // Attributes (in addition to RECT members)
  276.     int Width() const;
  277.     int Height() const;
  278.     CSize Size() const;
  279.     CPoint& TopLeft();
  280.     CPoint& BottomRight();
  281.  
  282.     // convert between CRect and LPRECT/LPCRECT (no need for &)
  283.     operator LPRECT();
  284.     operator LPCRECT() const;
  285.  
  286.     BOOL IsRectEmpty() const;
  287.     BOOL IsRectNull() const;
  288.     BOOL PtInRect(POINT point) const;
  289.  
  290. // Operations
  291.     void SetRect(int x1, int y1, int x2, int y2);
  292.     void SetRectEmpty();
  293.     void CopyRect(LPCRECT lpSrcRect);
  294.     BOOL EqualRect(LPCRECT lpRect) const;
  295.  
  296.     void InflateRect(int x, int y);
  297.     void InflateRect(SIZE size);
  298.     void OffsetRect(int x, int y);
  299.     void OffsetRect(SIZE size);
  300.     void OffsetRect(POINT point);
  301.  
  302.     // operations that fill '*this' with result
  303.     BOOL IntersectRect(LPCRECT lpRect1, LPCRECT lpRect2);
  304.     BOOL UnionRect(LPCRECT lpRect1, LPCRECT lpRect2);
  305. #if (WINVER >= 0x030a)
  306.     BOOL SubtractRect(LPCRECT lpRectSrc1, LPCRECT lpRectSrc2);
  307. #endif
  308.  
  309. // Additional Operations
  310.     void operator=(const RECT& srcRect);
  311.     BOOL operator==(const RECT& rect) const;
  312.     BOOL operator!=(const RECT& rect) const;
  313.     void operator+=(POINT point);
  314.     void operator-=(POINT point);
  315.     void operator&=(const RECT& rect);
  316.     void operator|=(const RECT& rect);
  317.  
  318. // Operators returning CRect values
  319.     CRect operator+(POINT point) const;
  320.     CRect operator-(POINT point) const;
  321.     CRect operator&(const RECT& rect2) const;
  322.     CRect operator|(const RECT& rect2) const;
  323. };
  324.  
  325. #ifdef _DEBUG
  326. // Diagnostic Output
  327. CDumpContext& AFXAPI operator<<(CDumpContext& dc, SIZE size);
  328. CDumpContext& AFXAPI operator<<(CDumpContext& dc, POINT point);
  329. CDumpContext& AFXAPI operator<<(CDumpContext& dc, const RECT& rect);
  330. #endif //_DEBUG
  331.  
  332. // Serialization
  333. CArchive& AFXAPI operator<<(CArchive& ar, SIZE size);
  334. CArchive& AFXAPI operator<<(CArchive& ar, POINT point);
  335. CArchive& AFXAPI operator<<(CArchive& ar, const RECT& rect);
  336. CArchive& AFXAPI operator>>(CArchive& ar, SIZE& size);
  337. CArchive& AFXAPI operator>>(CArchive& ar, POINT& point);
  338. CArchive& AFXAPI operator>>(CArchive& ar, RECT& rect);
  339.  
  340. /////////////////////////////////////////////////////////////////////////////
  341. // Standard exceptions
  342.  
  343. class CResourceException : public CException    // resource failure
  344. {
  345.     DECLARE_DYNAMIC(CResourceException)
  346. public:
  347.     CResourceException();
  348. };
  349.  
  350. class CUserException : public CException   // general user visible alert
  351. {
  352.     DECLARE_DYNAMIC(CUserException)
  353. public:
  354.     CUserException();
  355. };
  356.  
  357. void AFXAPI AfxThrowResourceException();
  358. void AFXAPI AfxThrowUserException();
  359.  
  360. /////////////////////////////////////////////////////////////////////////////
  361. // CGdiObject abstract class for CDC SelectObject
  362.  
  363. class CGdiObject : public CObject
  364. {
  365.     DECLARE_DYNCREATE(CGdiObject)
  366. public:
  367.  
  368. // Attributes
  369.     HGDIOBJ m_hObject;                  // must be first data member
  370.     HGDIOBJ GetSafeHandle() const;
  371.  
  372.     static CGdiObject* PASCAL FromHandle(HGDIOBJ hObject);
  373.     static void PASCAL DeleteTempMap();
  374.     BOOL Attach(HGDIOBJ hObject);
  375.     HGDIOBJ Detach();
  376.  
  377. // Constructors
  378.     CGdiObject(); // must Create a derived class object
  379.     BOOL DeleteObject();
  380.  
  381. // Operations
  382.     int GetObject(int nCount, LPVOID lpObject) const;
  383.     BOOL CreateStockObject(int nIndex);
  384.     BOOL UnrealizeObject();
  385.  
  386. // Implementation
  387. public:
  388.     virtual ~CGdiObject();
  389. #ifdef _DEBUG
  390.     virtual void Dump(CDumpContext& dc) const;
  391.     virtual void AssertValid() const;
  392. #endif
  393. };
  394.  
  395. /////////////////////////////////////////////////////////////////////////////
  396. // CGdiObject subclasses (drawing tools)
  397.  
  398. class CPen : public CGdiObject
  399. {
  400.     DECLARE_DYNAMIC(CPen)
  401.  
  402. public:
  403.     static CPen* PASCAL FromHandle(HPEN hPen);
  404.  
  405. // Constructors
  406.     CPen();
  407.     CPen(int nPenStyle, int nWidth, COLORREF crColor);
  408.     BOOL CreatePen(int nPenStyle, int nWidth, COLORREF crColor);
  409.     BOOL CreatePenIndirect(LPLOGPEN lpLogPen);
  410.  
  411. // Implementation
  412. public:
  413. #ifdef _DEBUG
  414.     virtual void Dump(CDumpContext& dc) const;
  415. #endif
  416. };
  417.  
  418. class CBrush : public CGdiObject
  419. {
  420.     DECLARE_DYNAMIC(CBrush)
  421.  
  422. public:
  423.     static CBrush* PASCAL FromHandle(HBRUSH hBrush);
  424.  
  425. // Constructors
  426.     CBrush();
  427.     CBrush(COLORREF crColor);             // CreateSolidBrush
  428.     CBrush(int nIndex, COLORREF crColor); // CreateHatchBrush
  429.     CBrush(CBitmap* pBitmap);          // CreatePatternBrush
  430.  
  431.     BOOL CreateSolidBrush(COLORREF crColor);
  432.     BOOL CreateHatchBrush(int nIndex, COLORREF crColor);
  433.     BOOL CreateBrushIndirect(LPLOGBRUSH lpLogBrush);
  434.     BOOL CreatePatternBrush(CBitmap* pBitmap);
  435.     BOOL CreateDIBPatternBrush(HGLOBAL hPackedDIB, UINT nUsage);
  436.  
  437. // Implementation
  438. public:
  439. #ifdef _DEBUG
  440.     virtual void Dump(CDumpContext& dc) const;
  441. #endif
  442. };
  443.  
  444. class CFont : public CGdiObject
  445. {
  446.     DECLARE_DYNAMIC(CFont)
  447.  
  448. public:
  449.     static CFont* PASCAL FromHandle(HFONT hFont);
  450.  
  451. // Constructors
  452.     CFont();
  453.     BOOL CreateFontIndirect(const LOGFONT FAR* lpLogFont);
  454.     BOOL CreateFont(int nHeight, int nWidth, int nEscapement,
  455.             int nOrientation, int nWeight, BYTE bItalic, BYTE bUnderline,
  456.             BYTE cStrikeOut, BYTE nCharSet, BYTE nOutPrecision,
  457.             BYTE nClipPrecision, BYTE nQuality, BYTE nPitchAndFamily,
  458.             LPCSTR lpszFacename);
  459. // Implementation
  460. public:
  461. #ifdef _DEBUG
  462.     virtual void Dump(CDumpContext& dc) const;
  463. #endif
  464. };
  465.  
  466.  
  467. class CBitmap : public CGdiObject
  468. {
  469.     DECLARE_DYNAMIC(CBitmap)
  470.  
  471. public:
  472.     static CBitmap* PASCAL FromHandle(HBITMAP hBitmap);
  473.  
  474. // Constructors
  475.     CBitmap();
  476.  
  477.     BOOL LoadBitmap(LPCSTR lpszResourceName);
  478.     BOOL LoadBitmap(UINT nIDResource);
  479.     BOOL LoadOEMBitmap(UINT nIDBitmap); // for OBM_/OCR_/OIC_
  480.     BOOL CreateBitmap(int nWidth, int nHeight, UINT nPlanes, UINT nBitcount,
  481.             const void FAR* lpBits);
  482.     BOOL CreateBitmapIndirect(LPBITMAP lpBitmap);
  483.     BOOL CreateCompatibleBitmap(CDC* pDC, int nWidth, int nHeight);
  484.     BOOL CreateDiscardableBitmap(CDC* pDC, int nWidth, int nHeight);
  485.  
  486. // Operations
  487.     DWORD SetBitmapBits(DWORD dwCount, const void FAR* lpBits);
  488.     DWORD GetBitmapBits(DWORD dwCount, LPVOID lpBits) const;
  489.     CSize SetBitmapDimension(int nWidth, int nHeight);
  490.     CSize GetBitmapDimension() const;
  491.  
  492. // Implementation
  493. public:
  494. #ifdef _DEBUG
  495.     virtual void Dump(CDumpContext& dc) const;
  496. #endif
  497. };
  498.  
  499. class CPalette : public CGdiObject
  500. {
  501.     DECLARE_DYNAMIC(CPalette)
  502.  
  503. public:
  504.     static CPalette* PASCAL FromHandle(HPALETTE hPalette);
  505.  
  506. // Constructors
  507.     CPalette();
  508.     BOOL CreatePalette(LPLOGPALETTE lpLogPalette);
  509.  
  510. // Operations
  511.     UINT GetPaletteEntries(UINT nStartIndex, UINT nNumEntries,
  512.             LPPALETTEENTRY lpPaletteColors) const;
  513.     UINT SetPaletteEntries(UINT nStartIndex, UINT nNumEntries,
  514.             LPPALETTEENTRY lpPaletteColors);
  515.     void AnimatePalette(UINT nStartIndex, UINT nNumEntries,
  516.             LPPALETTEENTRY lpPaletteColors);
  517.     UINT GetNearestPaletteIndex(COLORREF crColor) const;
  518.     BOOL ResizePalette(UINT nNumEntries);
  519. };
  520.  
  521. class CRgn : public CGdiObject
  522. {
  523.     DECLARE_DYNAMIC(CRgn)
  524.  
  525. public:
  526.     static CRgn* PASCAL FromHandle(HRGN hRgn);
  527.  
  528. // Constructors
  529.     CRgn();
  530.     BOOL CreateRectRgn(int x1, int y1, int x2, int y2);
  531.     BOOL CreateRectRgnIndirect(LPCRECT lpRect);
  532.     BOOL CreateEllipticRgn(int x1, int y1, int x2, int y2);
  533.     BOOL CreateEllipticRgnIndirect(LPCRECT lpRect);
  534.     BOOL CreatePolygonRgn(LPPOINT lpPoints, int nCount, int nMode);
  535.     BOOL CreatePolyPolygonRgn(LPPOINT lpPoints, LPINT lpPolyCounts,
  536.             int nCount, int nPolyFillMode);
  537.     BOOL CreateRoundRectRgn(int x1, int y1, int x2, int y2,
  538.             int x3, int y3);
  539.  
  540. // Operations
  541.     void SetRectRgn(int x1, int y1, int x2, int y2);
  542.     void SetRectRgn(LPCRECT lpRect);
  543.     int CombineRgn(CRgn* pRgn1, CRgn* pRgn2, int nCombineMode);
  544.     int CopyRgn(CRgn* pRgnSrc);
  545.     BOOL EqualRgn(CRgn* pRgn) const;
  546.     int OffsetRgn(int x, int y);
  547.     int OffsetRgn(POINT point);
  548.     int GetRgnBox(LPRECT lpRect) const;
  549.     BOOL PtInRegion(int x, int y) const;
  550.     BOOL PtInRegion(POINT point) const;
  551.     BOOL RectInRegion(LPCRECT lpRect) const;
  552. };
  553.  
  554. /////////////////////////////////////////////////////////////////////////////
  555. // The device context
  556.  
  557. class CDC : public CObject
  558. {
  559.     DECLARE_DYNCREATE(CDC)
  560. public:
  561.  
  562. // Attributes
  563.     HDC m_hDC;          // The output DC (must be first data member)
  564.     HDC m_hAttribDC;    // The Attribute DC
  565.     HDC GetSafeHdc() const; // Always returns the Output DC
  566.  
  567.     static CDC* PASCAL FromHandle(HDC hDC);
  568.     static void PASCAL DeleteTempMap();
  569.     BOOL Attach(HDC hDC);   // Attach/Detach affects only the Output DC
  570.     HDC Detach();
  571.  
  572.     virtual void SetAttribDC(HDC hDC);  // Set the Attribute DC
  573.     virtual void SetOutputDC(HDC hDC);  // Set the Output DC
  574.     virtual void ReleaseAttribDC();     // Release the Attribute DC
  575.     virtual void ReleaseOutputDC();     // Release the Output DC
  576.  
  577.     BOOL IsPrinting() const;            // TRUE if being used for printing
  578.  
  579. // Constructors
  580.     CDC();
  581.     BOOL CreateDC(LPCSTR lpszDriverName, LPCSTR lpszDeviceName,
  582.         LPCSTR lpszOutput, const void FAR* lpInitData);
  583.     BOOL CreateIC(LPCSTR lpszDriverName, LPCSTR lpszDeviceName,
  584.         LPCSTR lpszOutput, const void FAR* lpInitData);
  585.     BOOL CreateCompatibleDC(CDC* pDC);
  586.  
  587.     BOOL DeleteDC();
  588.  
  589. // Device-Context Functions
  590.     virtual int SaveDC();
  591.     virtual BOOL RestoreDC(int nSavedDC);
  592.     int GetDeviceCaps(int nIndex) const;
  593.  
  594. // Drawing-Tool Functions
  595.     CPoint GetBrushOrg() const;
  596.     CPoint SetBrushOrg(int x, int y);
  597.     CPoint SetBrushOrg(POINT point);
  598.     int EnumObjects(int nObjectType,
  599.             int (CALLBACK EXPORT* lpfn)(LPVOID, LPARAM), LPARAM lpData);
  600.  
  601. // type-safe selection helpers
  602. public:
  603.     virtual CGdiObject* SelectStockObject(int nIndex);
  604.     CPen* SelectObject(CPen* pPen);
  605.     CBrush* SelectObject(CBrush* pBrush);
  606.     virtual CFont* SelectObject(CFont* pFont);
  607.     CBitmap* SelectObject(CBitmap* pBitmap);
  608.     int SelectObject(CRgn* pRgn);       // special return for regions
  609.  
  610. // Color and Color Palette Functions
  611.     COLORREF GetNearestColor(COLORREF crColor) const;
  612.     CPalette* SelectPalette(CPalette* pPalette, BOOL bForceBackground);
  613.     UINT RealizePalette();
  614.     void UpdateColors();
  615.  
  616. // Drawing-Attribute Functions
  617.     COLORREF GetBkColor() const;
  618.     int GetBkMode() const;
  619.     int GetPolyFillMode() const;
  620.     int GetROP2() const;
  621.     int GetStretchBltMode() const;
  622.     COLORREF GetTextColor() const;
  623.  
  624.     virtual COLORREF SetBkColor(COLORREF crColor);
  625.     int SetBkMode(int nBkMode);
  626.     int SetPolyFillMode(int nPolyFillMode);
  627.     int SetROP2(int nDrawMode);
  628.     int SetStretchBltMode(int nStretchMode);
  629.     virtual COLORREF SetTextColor(COLORREF crColor);
  630.  
  631. // Mapping Functions
  632.     int GetMapMode() const;
  633.     CPoint GetViewportOrg() const;
  634.     virtual int SetMapMode(int nMapMode);
  635.     // Viewport Origin
  636.     virtual CPoint SetViewportOrg(int x, int y);
  637.             CPoint SetViewportOrg(POINT point);
  638.     virtual CPoint OffsetViewportOrg(int nWidth, int nHeight);
  639.  
  640.     // Viewport Extent
  641.     CSize GetViewportExt() const;
  642.     virtual CSize SetViewportExt(int cx, int cy);
  643.             CSize SetViewportExt(SIZE size);
  644.     virtual CSize ScaleViewportExt(int xNum, int xDenom, int yNum, int yDenom);
  645.  
  646.     // Window Origin
  647.     CPoint GetWindowOrg() const;
  648.     CPoint SetWindowOrg(int x, int y);
  649.     CPoint SetWindowOrg(POINT point);
  650.     CPoint OffsetWindowOrg(int nWidth, int nHeight);
  651.  
  652.     // Window extent
  653.     CSize GetWindowExt() const;
  654.     virtual CSize SetWindowExt(int cx, int cy);
  655.             CSize SetWindowExt(SIZE size);
  656.     virtual CSize ScaleWindowExt(int xNum, int xDenom, int yNum, int yDenom);
  657.  
  658. // Coordinate Functions
  659.     void DPtoLP(LPPOINT lpPoints, int nCount = 1) const;
  660.     void DPtoLP(LPRECT lpRect) const;
  661.     void LPtoDP(LPPOINT lpPoints, int nCount = 1) const;
  662.     void LPtoDP(LPRECT lpRect) const;
  663.  
  664. // Region Functions
  665.     BOOL FillRgn(CRgn* pRgn, CBrush* pBrush);
  666.     BOOL FrameRgn(CRgn* pRgn, CBrush* pBrush, int nWidth, int nHeight);
  667.     BOOL InvertRgn(CRgn* pRgn);
  668.     BOOL PaintRgn(CRgn* pRgn);
  669.  
  670. // Clipping Functions
  671.     virtual int GetClipBox(LPRECT lpRect) const;
  672.     virtual BOOL PtVisible(int x, int y) const;
  673.             BOOL PtVisible(POINT point) const;
  674.     virtual BOOL RectVisible(LPCRECT lpRect) const;
  675.             int SelectClipRgn(CRgn* pRgn);
  676.             int ExcludeClipRect(int x1, int y1, int x2, int y2);
  677.             int ExcludeClipRect(LPCRECT lpRect);
  678.             int ExcludeUpdateRgn(CWnd* pWnd);
  679.             int IntersectClipRect(int x1, int y1, int x2, int y2);
  680.             int IntersectClipRect(LPCRECT lpRect);
  681.             int OffsetClipRgn(int x, int y);
  682.             int OffsetClipRgn(SIZE size);
  683.  
  684. // Line-Output Functions
  685.     CPoint GetCurrentPosition() const;
  686.     CPoint MoveTo(int x, int y);
  687.     CPoint MoveTo(POINT point);
  688.     BOOL LineTo(int x, int y);
  689.     BOOL LineTo(POINT point);
  690.     BOOL Arc(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
  691.     BOOL Arc(LPCRECT lpRect, POINT ptStart, POINT ptEnd);
  692.     BOOL Polyline(LPPOINT lpPoints, int nCount);
  693.  
  694. // Simple Drawing Functions
  695.     void FillRect(LPCRECT lpRect, CBrush* pBrush);
  696.     void FrameRect(LPCRECT lpRect, CBrush* pBrush);
  697.     void InvertRect(LPCRECT lpRect);
  698.     BOOL DrawIcon(int x, int y, HICON hIcon);
  699.     BOOL DrawIcon(POINT point, HICON hIcon);
  700.  
  701.  
  702. // Ellipse and Polygon Functions
  703.     BOOL Chord(int x1, int y1, int x2, int y2, int x3, int y3,
  704.         int x4, int y4);
  705.     BOOL Chord(LPCRECT lpRect, POINT ptStart, POINT ptEnd);
  706.     void DrawFocusRect(LPCRECT lpRect);
  707.     BOOL Ellipse(int x1, int y1, int x2, int y2);
  708.     BOOL Ellipse(LPCRECT lpRect);
  709.     BOOL Pie(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
  710.     BOOL Pie(LPCRECT lpRect, POINT ptStart, POINT ptEnd);
  711.     BOOL Polygon(LPPOINT lpPoints, int nCount);
  712.     BOOL PolyPolygon(LPPOINT lpPoints, LPINT lpPolyCounts, int nCount);
  713.     BOOL Rectangle(int x1, int y1, int x2, int y2);
  714.     BOOL Rectangle(LPCRECT lpRect);
  715.     BOOL RoundRect(int x1, int y1, int x2, int y2, int x3, int y3);
  716.     BOOL RoundRect(LPCRECT lpRect, POINT point);
  717.  
  718. // Bitmap Function
  719.     BOOL PatBlt(int x, int y, int nWidth, int nHeight, DWORD dwRop);
  720.     BOOL BitBlt(int x, int y, int nWidth, int nHeight, CDC* pSrcDC,
  721.         int xSrc, int ySrc, DWORD dwRop);
  722.     BOOL StretchBlt(int x, int y, int nWidth, int nHeight, CDC* pSrcDC,
  723.         int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, DWORD dwRop);
  724.     COLORREF GetPixel(int x, int y) const;
  725.     COLORREF GetPixel(POINT point) const;
  726.     COLORREF SetPixel(int x, int y, COLORREF crColor);
  727.     COLORREF SetPixel(POINT point, COLORREF crColor);
  728.     BOOL FloodFill(int x, int y, COLORREF crColor);
  729.     BOOL ExtFloodFill(int x, int y, COLORREF crColor, UINT nFillType);
  730.  
  731. // Text Functions
  732.     virtual BOOL TextOut(int x, int y, LPCSTR lpszString, int nCount);
  733.             BOOL TextOut(int x, int y, const CString& str);
  734.     virtual BOOL ExtTextOut(int x, int y, UINT nOptions, LPCRECT lpRect,
  735.                 LPCSTR lpszString, UINT nCount, LPINT lpDxWidths);
  736.     virtual CSize TabbedTextOut(int x, int y, LPCSTR lpszString, int nCount,
  737.                 int nTabPositions, LPINT lpnTabStopPositions, int nTabOrigin);
  738.     virtual int DrawText(LPCSTR lpszString, int nCount, LPRECT lpRect,
  739.                 UINT nFormat);
  740.     CSize GetTextExtent(LPCSTR lpszString, int nCount) const;
  741.     CSize GetOutputTextExtent(LPCSTR lpszString, int nCount) const;
  742.     CSize GetTabbedTextExtent(LPCSTR lpszString, int nCount,
  743.         int nTabPositions, LPINT lpnTabStopPositions) const;
  744.     CSize GetOutputTabbedTextExtent(LPCSTR lpszString, int nCount,
  745.         int nTabPositions, LPINT lpnTabStopPositions) const;
  746.     virtual BOOL GrayString(CBrush* pBrush,
  747.         BOOL (CALLBACK EXPORT* lpfnOutput)(HDC, LPARAM, int), LPARAM lpData,
  748.             int nCount, int x, int y, int nWidth, int nHeight);
  749.     UINT GetTextAlign() const;
  750.     UINT SetTextAlign(UINT nFlags);
  751.     int GetTextFace(int nCount, LPSTR lpszFacename) const;
  752.     BOOL GetTextMetrics(LPTEXTMETRIC lpMetrics) const;
  753.     BOOL GetOutputTextMetrics(LPTEXTMETRIC lpMetrics) const;
  754.     int SetTextJustification(int nBreakExtra, int nBreakCount);
  755.     int GetTextCharacterExtra() const;
  756.     int SetTextCharacterExtra(int nCharExtra);
  757.  
  758. // Font Functions
  759.     BOOL GetCharWidth(UINT nFirstChar, UINT nLastChar, LPINT lpBuffer) const;
  760.     BOOL GetOutputCharWidth(UINT nFirstChar, UINT nLastChar, LPINT lpBuffer) const;
  761.     DWORD SetMapperFlags(DWORD dwFlag);
  762.     CSize GetAspectRatioFilter() const;
  763.  
  764. // Printer Escape Functions
  765.     virtual int Escape(int nEscape, int nCount,
  766.                     LPCSTR lpszInData, LPVOID lpOutData);
  767.  
  768.     // Escape helpers
  769.     int StartDoc(LPCSTR lpszDocName);  // old Win3.0 version
  770.     int StartDoc(LPDOCINFO lpDocInfo);
  771.     int StartPage();
  772.     int EndPage();
  773.     int SetAbortProc(BOOL (CALLBACK EXPORT* lpfn)(HDC, int));
  774.     int AbortDoc();
  775.     int EndDoc();
  776.  
  777. // Scrolling Functions
  778.     BOOL ScrollDC(int dx, int dy, LPCRECT lpRectScroll, LPCRECT lpRectClip,
  779.         CRgn* pRgnUpdate, LPRECT lpRectUpdate);
  780.  
  781. // MetaFile Functions
  782.     BOOL PlayMetaFile(HMETAFILE hMF);
  783.  
  784. // Windows 3.1 Specific GDI functions
  785. #if (WINVER >= 0x030a)
  786.     BOOL QueryAbort() const;
  787.     UINT SetBoundsRect(LPCRECT lpRectBounds, UINT flags);
  788.     UINT GetBoundsRect(LPRECT lpRectBounds, UINT flags);
  789.  
  790.     BOOL GetCharABCWidths(UINT nFirst, UINT nLast, LPABC lpabc) const;
  791.     DWORD GetFontData(DWORD dwTable, DWORD dwOffset, LPVOID lpData, DWORD cbData) const;
  792.     int GetKerningPairs(int nPairs, LPKERNINGPAIR lpkrnpair) const;
  793.     UINT GetOutlineTextMetrics(UINT cbData, LPOUTLINETEXTMETRIC lpotm) const;
  794.     DWORD GetGlyphOutline(UINT nChar, UINT nFormat, LPGLYPHMETRICS lpgm,
  795.         DWORD cbBuffer, LPVOID lpBuffer, const MAT2 FAR* lpmat2) const;
  796.     BOOL ResetDC(const DEVMODE FAR* lpDevMode);
  797.  
  798. #endif //WIN3.1
  799.  
  800. // Implementation
  801. public:
  802.     virtual ~CDC();
  803. #ifdef _DEBUG
  804.     virtual void AssertValid() const;
  805.     virtual void Dump(CDumpContext& dc) const;
  806. #endif
  807.  
  808.     // advanced use and implementation
  809.     BOOL m_bPrinting;
  810.     HGDIOBJ SelectObject(HGDIOBJ);      // do not use for regions
  811.  
  812. protected:
  813.     // used for implementation of non-virtual SelectObject calls
  814.     static CGdiObject* PASCAL SelectGdiObject(HDC hDC, HGDIOBJ h);
  815. };
  816.  
  817. /////////////////////////////////////////////////////////////////////////////
  818. // CDC Helpers
  819.  
  820. class CPaintDC : public CDC
  821. {
  822.     DECLARE_DYNAMIC(CPaintDC)
  823.  
  824. // Constructors
  825. public:
  826.     CPaintDC(CWnd* pWnd);   // BeginPaint
  827.  
  828. // Attributes
  829. protected:
  830.     HWND m_hWnd;
  831. public:
  832.     PAINTSTRUCT m_ps;       // actual paint struct !
  833.  
  834. // Implementation
  835. public:
  836.     virtual ~CPaintDC();
  837. #ifdef _DEBUG
  838.     virtual void AssertValid() const;
  839.     virtual void Dump(CDumpContext& dc) const;
  840. #endif
  841. };
  842.  
  843. class CClientDC : public CDC
  844. {
  845.     DECLARE_DYNAMIC(CClientDC)
  846.  
  847. // Constructors
  848. public:
  849.     CClientDC(CWnd* pWnd);
  850.  
  851. // Attributes
  852. protected:
  853.     HWND m_hWnd;
  854.  
  855. // Implementation
  856. public:
  857.     virtual ~CClientDC();
  858. #ifdef _DEBUG
  859.     virtual void AssertValid() const;
  860.     virtual void Dump(CDumpContext& dc) const;
  861. #endif
  862. };
  863.  
  864. class CWindowDC : public CDC
  865. {
  866.     DECLARE_DYNAMIC(CWindowDC)
  867.  
  868. // Constructors
  869. public:
  870.  
  871.     CWindowDC(CWnd* pWnd);
  872.  
  873. // Attributes
  874. protected:
  875.     HWND m_hWnd;
  876.  
  877. // Implementation
  878. public:
  879.     virtual ~CWindowDC();
  880. #ifdef _DEBUG
  881.     virtual void AssertValid() const;
  882.     virtual void Dump(CDumpContext& dc) const;
  883. #endif
  884. };
  885.  
  886. /////////////////////////////////////////////////////////////////////////////
  887. // CMenu
  888.  
  889. class CMenu : public CObject
  890. {
  891.     DECLARE_DYNCREATE(CMenu)
  892. public:
  893.  
  894. // Constructors
  895.     CMenu();
  896.  
  897.     BOOL CreateMenu();
  898.     BOOL CreatePopupMenu();
  899.     BOOL LoadMenu(LPCSTR lpszResourceName);
  900.     BOOL LoadMenu(UINT nIDResource);
  901.     BOOL LoadMenuIndirect(const void FAR* lpMenuTemplate);
  902.     BOOL DestroyMenu();
  903.  
  904. // Attributes
  905.     HMENU m_hMenu;          // must be first data member
  906.     HMENU GetSafeHmenu() const;
  907.  
  908.     static CMenu* PASCAL FromHandle(HMENU hMenu);
  909.     static void PASCAL DeleteTempMap();
  910.     BOOL Attach(HMENU hMenu);
  911.     HMENU Detach();
  912.  
  913. // CMenu Operations
  914.     BOOL DeleteMenu(UINT nPosition, UINT nFlags);
  915.     BOOL TrackPopupMenu(UINT nFlags, int x, int y,
  916.                         CWnd* pWnd, LPCRECT lpRect = 0);
  917.  
  918. // CMenuItem Operations
  919.     BOOL AppendMenu(UINT nFlags, UINT nIDNewItem = 0,
  920.                     LPCSTR lpszNewItem = NULL);
  921.     BOOL AppendMenu(UINT nFlags, UINT nIDNewItem, const CBitmap* pBmp);
  922.     UINT CheckMenuItem(UINT nIDCheckItem, UINT nCheck);
  923.     UINT EnableMenuItem(UINT nIDEnableItem, UINT nEnable);
  924.     UINT GetMenuItemCount() const;
  925.     UINT GetMenuItemID(int nPos) const;
  926.     UINT GetMenuState(UINT nID, UINT nFlags) const;
  927.     int GetMenuString(UINT nIDItem, LPSTR lpString, int nMaxCount,
  928.                     UINT nFlags) const;
  929.     CMenu* GetSubMenu(int nPos) const;
  930.     BOOL InsertMenu(UINT nPosition, UINT nFlags, UINT nIDNewItem = 0,
  931.                     LPCSTR lpszNewItem = NULL);
  932.     BOOL InsertMenu(UINT nPosition, UINT nFlags, UINT nIDNewItem,
  933.                     const CBitmap* pBmp);
  934.     BOOL ModifyMenu(UINT nPosition, UINT nFlags, UINT nIDNewItem = 0,
  935.                     LPCSTR lpszNewItem = NULL);
  936.     BOOL ModifyMenu(UINT nPosition, UINT nFlags, UINT nIDNewItem,
  937.                     const CBitmap* pBmp);
  938.     BOOL RemoveMenu(UINT nPosition, UINT nFlags);
  939.     BOOL SetMenuItemBitmaps(UINT nPosition, UINT nFlags,
  940.                     const CBitmap* pBmpUnchecked, const CBitmap* pBmpChecked);
  941.  
  942. // Overridables (must override draw and measure for owner-draw menu items)
  943.     virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
  944.     virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
  945.  
  946. // Implementation
  947. public:
  948.     virtual ~CMenu();
  949. #ifdef _DEBUG
  950.     virtual void AssertValid() const;
  951.     virtual void Dump(CDumpContext& dc) const;
  952. #endif
  953. };
  954.  
  955. /////////////////////////////////////////////////////////////////////////////
  956. // Window message map handling
  957.  
  958. struct AFX_MSGMAP_ENTRY;       // declared below after CWnd
  959.  
  960. struct AFXAPI_DATA_TYPE AFX_MSGMAP
  961. {
  962.     AFX_MSGMAP* pBaseMessageMap;
  963.     AFX_MSGMAP_ENTRY FAR* lpEntries;
  964. };
  965.  
  966. #define DECLARE_MESSAGE_MAP() \
  967. private: \
  968.     static AFX_MSGMAP_ENTRY BASED_CODE _messageEntries[]; \
  969. protected: \
  970.     static AFX_MSGMAP AFXAPP_DATA messageMap; \
  971.     virtual AFX_MSGMAP* GetMessageMap() const;
  972.  
  973. #define BEGIN_MESSAGE_MAP(theClass, baseClass) \
  974.     AFX_MSGMAP* theClass::GetMessageMap() const \
  975.         { return &theClass::messageMap; } \
  976.     AFX_MSGMAP AFXAPP_DATA theClass::messageMap = \
  977.     { &(baseClass::messageMap), \
  978.         (AFX_MSGMAP_ENTRY FAR*) &(theClass::_messageEntries) }; \
  979.     AFX_MSGMAP_ENTRY BASED_CODE theClass::_messageEntries[] = \
  980.     {
  981.  
  982. #define END_MESSAGE_MAP() \
  983.     { 0, 0, AfxSig_end, (AFX_PMSG)0 } \
  984.     };
  985.  
  986. // Message map signature values and macros in separate header
  987. #include "afxmsg_.h"
  988.  
  989. /////////////////////////////////////////////////////////////////////////////
  990. // Dialog data exchange (DDX_) and validation (DDV_)
  991.  
  992. class CVBControl;
  993.  
  994. // CDataExchange - for data exchange and validation
  995. class AFX_STACK_DATA CDataExchange
  996. {
  997. // Attributes
  998. public:
  999.     BOOL m_bSaveAndValidate;   // TRUE => save and validate data
  1000.     CWnd* m_pDlgWnd;           // container usually a dialog
  1001.  
  1002. // Operations (for implementors of DDX and DDV procs)
  1003.     HWND PrepareCtrl(int nIDC);     // return HWND of control
  1004.     HWND PrepareEditCtrl(int nIDC); // return HWND of control
  1005.     CVBControl* PrepareVBCtrl(int nIDC);    // return VB control
  1006.     void Fail();                    // will throw exception
  1007.  
  1008. // Implementation
  1009.     CDataExchange(CWnd* pDlgWnd, BOOL bSaveAndValidate);
  1010.  
  1011.     HWND m_hWndLastControl;    // last control used (for validation)
  1012.     BOOL m_bEditLastControl;   // last control was an edit item
  1013. };
  1014.  
  1015. #include "afxdd_.h"     // standard DDX_ and DDV_ routines
  1016.  
  1017. /////////////////////////////////////////////////////////////////////////////
  1018. // CCmdTarget
  1019.  
  1020. // private structures
  1021. struct AFX_CMDHANDLERINFO;   // info about where the command is handled
  1022.  
  1023. class CCmdTarget : public CObject
  1024. {
  1025.     DECLARE_DYNAMIC(CCmdTarget)
  1026. protected:
  1027.     CCmdTarget();
  1028.  
  1029. public:
  1030. // Operations
  1031.     void BeginWaitCursor();
  1032.     void EndWaitCursor();
  1033.     void RestoreWaitCursor();        // call after messagebox
  1034.  
  1035. // Overridables
  1036.     // route and dispatch standard command message types
  1037.     //   (more sophisticated than OnCommand)
  1038.     virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra,
  1039.         AFX_CMDHANDLERINFO* pHandlerInfo);
  1040.  
  1041. // Implementation
  1042. private:
  1043.     static CView* pRoutingView;
  1044.     friend class CView;
  1045.  
  1046. protected:
  1047.     CView* GetRoutingView();
  1048.     DECLARE_MESSAGE_MAP()       // base class - no {{ }} macros
  1049. };
  1050.  
  1051. class CCmdUI        // simple helper class
  1052. {
  1053. public:
  1054. // Attributes
  1055.     UINT m_nID;
  1056.     UINT m_nIndex;          // menu item or other index
  1057.  
  1058.     // if a menu item
  1059.     CMenu* m_pMenu;         // NULL if not a menu
  1060.     CMenu* m_pSubMenu;      // sub containing menu item
  1061.                             // if a popup sub menu - ID is for first in popup
  1062.  
  1063.     // if from some other window
  1064.     CWnd* m_pOther;         // NULL if a menu or not a CWnd
  1065.  
  1066. // Operations to do in ON_UPDATE_COMMAND_UI
  1067.     virtual void Enable(BOOL bOn = TRUE);
  1068.     virtual void SetCheck(int nCheck = 1);   // 0, 1 or 2 (indeterminate)
  1069.     virtual void SetRadio(BOOL bOn = TRUE);
  1070.     virtual void SetText(LPCSTR lpszText);
  1071.  
  1072. // Advanced operation
  1073.     void ContinueRouting();
  1074.  
  1075. // Implementation
  1076.     CCmdUI();
  1077.     BOOL m_bEnableChanged;
  1078.     BOOL m_bContinueRouting;
  1079.     UINT m_nIndexMax;       // last + 1 for iterating m_nIndex
  1080.  
  1081.     void DoUpdate(CCmdTarget* pTarget, BOOL bDisableIfNoHndler);
  1082. };
  1083.  
  1084. // special CCmdUI derived classes are used for other UI paradigms
  1085. //  like toolbar buttons and status indicators
  1086.  
  1087. /////////////////////////////////////////////////////////////////////////////
  1088. // CWnd implementation
  1089.  
  1090. // structures (see afxext.h)
  1091. struct CCreateContext;      // context for creating things
  1092. struct CPrintInfo;          // print preview customization info
  1093.  
  1094. // pointer to afx_msg member function
  1095. #ifndef AFX_MSG_CALL
  1096. #define AFX_MSG_CALL PASCAL
  1097. #endif
  1098. typedef void (AFX_MSG_CALL CCmdTarget::*AFX_PMSG)(void);
  1099.  
  1100. struct AFX_MSGMAP_ENTRY
  1101. {
  1102.     UINT nMessage;   // windows message or control notification code
  1103.     UINT nID;        // control ID (or 0 for windows messages)
  1104.     UINT nSig;       // signature type (action) or near pointer to message #
  1105.     AFX_PMSG pfn;    // routine to call (or special value)
  1106. };
  1107.  
  1108. /////////////////////////////////////////////////////////////////////////////
  1109. // CWnd - a Microsoft Windows application window
  1110.  
  1111. class CWnd : public CCmdTarget
  1112. {
  1113.     DECLARE_DYNCREATE(CWnd)
  1114. protected:
  1115.     static const MSG* PASCAL GetCurrentMessage();
  1116.  
  1117. // Attributes
  1118. public:
  1119.     HWND m_hWnd;            // must be first data member
  1120.  
  1121.     HWND GetSafeHwnd() const;
  1122.     DWORD GetStyle() const;
  1123.     DWORD GetExStyle() const;
  1124.  
  1125. // Constructors and other creation
  1126.     CWnd();
  1127.  
  1128.     static CWnd* PASCAL FromHandle(HWND hWnd);
  1129.     static CWnd* PASCAL FromHandlePermanent(HWND hWnd);    // INTERNAL USE
  1130.     static void PASCAL DeleteTempMap();
  1131.     BOOL Attach(HWND hWndNew);
  1132.     HWND Detach();
  1133.     BOOL SubclassWindow(HWND hWnd);
  1134.     BOOL SubclassDlgItem(UINT nID, CWnd* pParent);
  1135.             // for dynamic subclassing of windows control
  1136.  
  1137. protected: // This CreateEx() wraps CreateWindowEx - dangerous to use directly
  1138.     BOOL CreateEx(DWORD dwExStyle, LPCSTR lpszClassName,
  1139.         LPCSTR lpszWindowName, DWORD dwStyle,
  1140.         int x, int y, int nWidth, int nHeight,
  1141.         HWND hWndParent, HMENU nIDorHMenu, LPSTR lpParam = NULL);
  1142.  
  1143. private:
  1144.     CWnd(HWND hWnd);    // just for special initialization
  1145.  
  1146. public:
  1147.     // for child windows, views, panes etc
  1148.     virtual BOOL Create(LPCSTR lpszClassName,
  1149.         LPCSTR lpszWindowName, DWORD dwStyle,
  1150.         const RECT& rect,
  1151.         CWnd* pParentWnd, UINT nID,
  1152.         CCreateContext* pContext = NULL);
  1153.  
  1154.     virtual BOOL DestroyWindow();
  1155.  
  1156.     // special pre-creation and window rect adjustment hooks
  1157.     virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  1158.     virtual void CalcWindowRect(LPRECT lpClientRect);// virtual AdjustWindowRect
  1159.  
  1160. // Window tree access
  1161.     int GetDlgCtrlID() const;
  1162.         // return window ID, for child windows only
  1163.     CWnd* GetDlgItem(int nID) const;
  1164.         // get immediate child with given ID
  1165.     CWnd* GetDescendantWindow(int nID) const;
  1166.         // like GetDlgItem but recursive
  1167.     void SendMessageToDescendants(UINT message,
  1168.                     WPARAM wParam = 0, LPARAM lParam = 0, BOOL bDeep = TRUE);
  1169.     CFrameWnd* GetParentFrame() const;
  1170.  
  1171. // Message Functions
  1172.     LRESULT SendMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0);
  1173.     BOOL PostMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0);
  1174.  
  1175. // Window Text Functions
  1176.     void SetWindowText(LPCSTR lpszString);
  1177.     int GetWindowText(LPSTR lpszStringBuf, int nMaxCount) const;
  1178.     int GetWindowTextLength() const;
  1179.     void GetWindowText(CString& rString) const;
  1180.     void SetFont(CFont* pFont, BOOL bRedraw = TRUE);
  1181.     CFont* GetFont() const;
  1182.  
  1183. // CMenu Functions - non-Child windows only
  1184.     CMenu* GetMenu() const;
  1185.     BOOL SetMenu(CMenu* pMenu);
  1186.     void DrawMenuBar();
  1187.     CMenu* GetSystemMenu(BOOL bRevert) const;
  1188.     BOOL HiliteMenuItem(CMenu* pMenu, UINT nIDHiliteItem, UINT nHilite);
  1189.  
  1190. // Window Size and Position Functions
  1191.     BOOL IsIconic() const;
  1192.     BOOL IsZoomed() const;
  1193.     void MoveWindow(int x, int y, int nWidth, int nHeight,
  1194.                 BOOL bRepaint = TRUE);
  1195.     void MoveWindow(LPCRECT lpRect, BOOL bRepaint = TRUE);
  1196.  
  1197.     static const CWnd AFXAPI_DATA wndTop; // SetWindowPos's pWndInsertAfter
  1198.     static const CWnd AFXAPI_DATA wndBottom; // SetWindowPos's pWndInsertAfter
  1199. #if (WINVER >= 0x030a)
  1200.     static const CWnd AFXAPI_DATA wndTopMost; // SetWindowPos pWndInsertAfter
  1201.     static const CWnd AFXAPI_DATA wndNoTopMost; // SetWindowPos pWndInsertAfter
  1202. #endif
  1203.  
  1204.     BOOL SetWindowPos(const CWnd* pWndInsertAfter, int x, int y,
  1205.                 int cx, int cy, UINT nFlags);
  1206.     UINT ArrangeIconicWindows();
  1207.     void BringWindowToTop();
  1208.     void GetWindowRect(LPRECT lpRect) const;
  1209.     void GetClientRect(LPRECT lpRect) const;
  1210.  
  1211. #if (WINVER >= 0x030a)
  1212.     BOOL GetWindowPlacement(WINDOWPLACEMENT FAR* lpwndpl) const;
  1213.     BOOL SetWindowPlacement(const WINDOWPLACEMENT FAR* lpwndpl);
  1214. #endif
  1215.  
  1216. // Coordinate Mapping Functions
  1217.     void ClientToScreen(LPPOINT lpPoint) const;
  1218.     void ClientToScreen(LPRECT lpRect) const;
  1219.     void ScreenToClient(LPPOINT lpPoint) const;
  1220.     void ScreenToClient(LPRECT lpRect) const;
  1221. #if (WINVER >= 0x030a)
  1222.     void MapWindowPoints(CWnd* pwndTo, LPPOINT lpPoint, UINT nCount) const;
  1223.     void MapWindowPoints(CWnd* pwndTo, LPRECT lpRect) const;
  1224. #endif
  1225.  
  1226. // Update/Painting Functions
  1227.     CDC* BeginPaint(LPPAINTSTRUCT lpPaint);
  1228.     void EndPaint(LPPAINTSTRUCT lpPaint);
  1229.     CDC* GetDC();
  1230.     CDC* GetWindowDC();
  1231.     int ReleaseDC(CDC* pDC);
  1232.  
  1233.     void UpdateWindow();
  1234.     void SetRedraw(BOOL bRedraw = TRUE);
  1235.     BOOL GetUpdateRect(LPRECT lpRect, BOOL bErase = FALSE);
  1236.     int GetUpdateRgn(CRgn* pRgn, BOOL bErase = FALSE);
  1237.     void Invalidate(BOOL bErase = TRUE);
  1238.     void InvalidateRect(LPCRECT lpRect, BOOL bErase = TRUE);
  1239.     void InvalidateRgn(CRgn* pRgn, BOOL bErase = TRUE);
  1240.     void ValidateRect(LPCRECT lpRect);
  1241.     void ValidateRgn(CRgn* pRgn);
  1242.     BOOL ShowWindow(int nCmdShow);
  1243.     BOOL IsWindowVisible() const;
  1244.     void ShowOwnedPopups(BOOL bShow = TRUE);
  1245.  
  1246. #if (WINVER >= 0x030a)
  1247.     CDC* GetDCEx(CRgn* prgnClip, DWORD flags);
  1248.     BOOL LockWindowUpdate();
  1249.     BOOL RedrawWindow(LPCRECT lpRectUpdate = NULL,
  1250.         CRgn* prgnUpdate = NULL,
  1251.         UINT flags = RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
  1252.     BOOL EnableScrollBar(int nSBFlags, UINT nArrowFlags = ESB_ENABLE_BOTH);
  1253. #endif
  1254.  
  1255. // Timer Functions
  1256.     UINT SetTimer(UINT nIDEvent, UINT nElapse,
  1257.                     void (CALLBACK EXPORT* lpfnTimer)(HWND, UINT, UINT, DWORD));
  1258.     BOOL KillTimer(int nIDEvent);
  1259.  
  1260. // Window State Functions
  1261.     BOOL IsWindowEnabled() const;
  1262.     BOOL EnableWindow(BOOL bEnable = TRUE);
  1263.  
  1264.     // This active window applies only to top-most (i.e. Frame windows)
  1265.     static CWnd* PASCAL GetActiveWindow();
  1266.     CWnd* SetActiveWindow();
  1267.  
  1268.     // Capture and Focus apply to all windows
  1269.     static CWnd* PASCAL GetCapture();
  1270.     CWnd* SetCapture();
  1271.     static CWnd* PASCAL GetFocus();
  1272.     CWnd* SetFocus();
  1273.  
  1274.     static CWnd* PASCAL GetDesktopWindow();
  1275.  
  1276. // Obsolete and non-portable APIs - not recommended for new code
  1277.     void CloseWindow();
  1278.     BOOL OpenIcon();
  1279.     CWnd* SetSysModalWindow();
  1280.     static CWnd* PASCAL GetSysModalWindow();
  1281.  
  1282. // Dialog-Box Item Functions
  1283. // (NOTE: Dialog-Box Items/Controls are not necessarily in dialog boxes!)
  1284.     void CheckDlgButton(int nIDButton, UINT nCheck);
  1285.     void CheckRadioButton(int nIDFirstButton, int nIDLastButton,
  1286.                     int nIDCheckButton);
  1287.     int GetCheckedRadioButton(int nIDFirstButton, int nIDLastButton);
  1288.     int DlgDirList(LPSTR lpPathSpec, int nIDListBox,
  1289.                     int nIDStaticPath, UINT nFileType);
  1290.     int DlgDirListComboBox(LPSTR lpPathSpec, int nIDComboBox,
  1291.                     int nIDStaticPath, UINT nFileType);
  1292.     BOOL DlgDirSelect(LPSTR lpString, int nIDListBox);
  1293.     BOOL DlgDirSelectComboBox(LPSTR lpString, int nIDComboBox);
  1294.  
  1295.     UINT GetDlgItemInt(int nID, BOOL* lpTrans = NULL,
  1296.                     BOOL bSigned = TRUE) const;
  1297.     int GetDlgItemText(int nID, LPSTR lpStr, int nMaxCount) const;
  1298.     CWnd* GetNextDlgGroupItem(CWnd* pWndCtl, BOOL bPrevious = FALSE) const;
  1299.  
  1300.     CWnd* GetNextDlgTabItem(CWnd* pWndCtl, BOOL bPrevious = FALSE) const;
  1301.     UINT IsDlgButtonChecked(int nIDButton) const;
  1302.     LRESULT SendDlgItemMessage(int nID, UINT message,
  1303.                     WPARAM wParam = 0, LPARAM lParam = 0);
  1304.     void SetDlgItemInt(int nID, UINT nValue, BOOL bSigned = TRUE);
  1305.     void SetDlgItemText(int nID, LPCSTR lpszString);
  1306.  
  1307. // Scrolling Functions
  1308.     int GetScrollPos(int nBar) const;
  1309.     void GetScrollRange(int nBar, LPINT lpMinPos, LPINT lpMaxPos) const;
  1310.     void ScrollWindow(int xAmount, int yAmount,
  1311.                     LPCRECT lpRect = NULL,
  1312.                     LPCRECT lpClipRect = NULL);
  1313.     int SetScrollPos(int nBar, int nPos, BOOL bRedraw = TRUE);
  1314.     void SetScrollRange(int nBar, int nMinPos, int nMaxPos,
  1315.             BOOL bRedraw = TRUE);
  1316.     void ShowScrollBar(UINT nBar, BOOL bShow = TRUE);
  1317.     void EnableScrollBarCtrl(int nBar, BOOL bEnable = TRUE);
  1318.     virtual CScrollBar* GetScrollBarCtrl(int nBar) const;
  1319.             // return sibling scrollbar control (or NULL if none)
  1320.  
  1321. #if (WINVER >= 0x030a)
  1322.     int ScrollWindowEx(int dx, int dy,
  1323.                 LPCRECT lpRectScroll, LPCRECT lpRectClip,
  1324.                 CRgn* prgnUpdate, LPRECT lpRectUpdate, UINT flags);
  1325. #endif
  1326.  
  1327.  
  1328. // Window Access Functions
  1329.     CWnd* ChildWindowFromPoint(POINT point) const;
  1330.     static CWnd* PASCAL FindWindow(LPCSTR lpszClassName, LPCSTR lpszWindowName);
  1331.     CWnd* GetNextWindow(UINT nFlag = GW_HWNDNEXT) const;
  1332.     CWnd* GetTopWindow() const;
  1333.  
  1334.     CWnd* GetWindow(UINT nCmd) const;
  1335.     CWnd* GetLastActivePopup() const;
  1336.  
  1337.     BOOL IsChild(const CWnd* pWnd) const;
  1338.     CWnd* GetParent() const;
  1339.     CWnd* SetParent(CWnd* pWndNewParent);
  1340.     static CWnd* PASCAL WindowFromPoint(POINT point);
  1341.  
  1342. // Alert Functions
  1343.     BOOL FlashWindow(BOOL bInvert);
  1344.     int MessageBox(LPCSTR lpszText, LPCSTR lpszCaption = NULL,
  1345.             UINT nType = MB_OK);
  1346.  
  1347. // Clipboard Functions
  1348.     BOOL ChangeClipboardChain(HWND hWndNext);
  1349.     HWND SetClipboardViewer();
  1350.     BOOL OpenClipboard();
  1351.     static CWnd* PASCAL GetClipboardOwner();
  1352.     static CWnd* PASCAL GetClipboardViewer();
  1353. #if (WINVER >= 0x030a)
  1354.     static CWnd* PASCAL GetOpenClipboardWindow();
  1355. #endif
  1356.  
  1357. // Caret Functions
  1358.     void CreateCaret(CBitmap* pBitmap);
  1359.     void CreateSolidCaret(int nWidth, int nHeight);
  1360.     void CreateGrayCaret(int nWidth, int nHeight);
  1361.     static CPoint PASCAL GetCaretPos();
  1362.     static void PASCAL SetCaretPos(POINT point);
  1363.     void HideCaret();
  1364.     void ShowCaret();
  1365.  
  1366. // Drag-Drop Functions
  1367. #if (WINVER >= 0x030a)
  1368.     void DragAcceptFiles(BOOL bAccept = TRUE);
  1369. #endif
  1370.  
  1371. // Dialog Data support
  1372. public:
  1373.     BOOL UpdateData(BOOL bSaveAndValidate = TRUE);
  1374.             // data wnd must be same type as this
  1375.  
  1376. // Layout and other functions
  1377. public:
  1378.     void RepositionBars(UINT nIDFirst, UINT nIDLast, UINT nIDLeftOver);
  1379.     void UpdateDialogControls(CCmdTarget* pTarget, BOOL bDisableIfNoHndler);
  1380.  
  1381. // Window-Management message handler member functions
  1382. protected:
  1383.     virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
  1384.  
  1385.     afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
  1386.     afx_msg void OnActivateApp(BOOL bActive, HTASK hTask);
  1387.     afx_msg void OnCancelMode();
  1388.     afx_msg void OnChildActivate();
  1389.     afx_msg void OnClose();
  1390.     afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  1391.  
  1392.     afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
  1393.  
  1394.     afx_msg void OnDestroy();
  1395.     afx_msg void OnEnable(BOOL bEnable);
  1396.     afx_msg void OnEndSession(BOOL bEnding);
  1397.     afx_msg void OnEnterIdle(UINT nWhy, CWnd* pWho);
  1398.     afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  1399.     afx_msg void OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI);
  1400.     afx_msg void OnIconEraseBkgnd(CDC* pDC);
  1401.     afx_msg void OnKillFocus(CWnd* pNewWnd);
  1402.     afx_msg LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu);
  1403.     afx_msg void OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu);
  1404.     afx_msg void OnMove(int x, int y);
  1405.     afx_msg void OnPaint();
  1406.     afx_msg void OnParentNotify(UINT message, LPARAM lParam);
  1407.     afx_msg HCURSOR OnQueryDragIcon();
  1408.     afx_msg BOOL OnQueryEndSession();
  1409.     afx_msg BOOL OnQueryNewPalette();
  1410.     afx_msg BOOL OnQueryOpen();
  1411.     afx_msg void OnSetFocus(CWnd* pOldWnd);
  1412.     afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
  1413.     afx_msg void OnSize(UINT nType, int cx, int cy);
  1414. #if (WINVER >= 0x030a)
  1415.     afx_msg void OnWindowPosChanging(WINDOWPOS FAR* lpwndpos);
  1416.     afx_msg void OnWindowPosChanged(WINDOWPOS FAR* lpwndpos);
  1417. #endif
  1418.  
  1419. // Nonclient-Area message handler member functions
  1420.     afx_msg BOOL OnNcActivate(BOOL bActive);
  1421.     afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp);
  1422.     afx_msg BOOL OnNcCreate(LPCREATESTRUCT lpCreateStruct);
  1423.     afx_msg void OnNcDestroy();
  1424.     afx_msg UINT OnNcHitTest(CPoint point);
  1425.     afx_msg void OnNcLButtonDblClk(UINT nHitTest, CPoint point);
  1426.     afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point);
  1427.     afx_msg void OnNcLButtonUp(UINT nHitTest, CPoint point);
  1428.     afx_msg void OnNcMButtonDblClk(UINT nHitTest, CPoint point);
  1429.     afx_msg void OnNcMButtonDown(UINT nHitTest, CPoint point);
  1430.     afx_msg void OnNcMButtonUp(UINT nHitTest, CPoint point);
  1431.     afx_msg void OnNcMouseMove(UINT nHitTest, CPoint point);
  1432.     afx_msg void OnNcPaint();
  1433.     afx_msg void OnNcRButtonDblClk(UINT nHitTest, CPoint point);
  1434.     afx_msg void OnNcRButtonDown(UINT nHitTest, CPoint point);
  1435.     afx_msg void OnNcRButtonUp(UINT nHitTest, CPoint point);
  1436.  
  1437. // System message handler member functions
  1438. #if (WINVER >= 0x030a)
  1439.     afx_msg void OnDropFiles(HDROP hDropInfo);
  1440.     afx_msg void OnPaletteIsChanging(CWnd* pRealizeWnd);
  1441. #endif
  1442.     afx_msg void OnSysChar(UINT nChar, UINT nRepCnt, UINT nFlags);
  1443.     afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
  1444.     afx_msg void OnSysDeadChar(UINT nChar, UINT nRepCnt, UINT nFlags);
  1445.     afx_msg void OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  1446.     afx_msg void OnSysKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
  1447.     afx_msg void OnCompacting(UINT nCpuTime);
  1448.     afx_msg void OnDevModeChange(LPSTR lpDeviceName);
  1449.     afx_msg void OnFontChange();
  1450.     afx_msg void OnPaletteChanged(CWnd* pFocusWnd);
  1451.     afx_msg void OnSpoolerStatus(UINT nStatus, UINT nJobs);
  1452.     afx_msg void OnSysColorChange();
  1453.     afx_msg void OnTimeChange();
  1454.     afx_msg void OnWinIniChange(LPCSTR lpszSection);
  1455.  
  1456. // Input message handler member functions
  1457.     afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
  1458.     afx_msg void OnDeadChar(UINT nChar, UINT nRepCnt, UINT nFlags);
  1459.     afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  1460.     afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  1461.     afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  1462.     afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
  1463.     afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
  1464.     afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  1465.     afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  1466.     afx_msg void OnMButtonDblClk(UINT nFlags, CPoint point);
  1467.     afx_msg void OnMButtonDown(UINT nFlags, CPoint point);
  1468.     afx_msg void OnMButtonUp(UINT nFlags, CPoint point);
  1469.     afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
  1470.     afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  1471.     afx_msg void OnRButtonDblClk(UINT nFlags, CPoint point);
  1472.     afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
  1473.     afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
  1474.     afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
  1475.     afx_msg void OnTimer(UINT nIDEvent);
  1476.  
  1477. // Initialization message handler member functions
  1478.     afx_msg void OnInitMenu(CMenu* pMenu);
  1479.     afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu);
  1480.  
  1481. // Clipboard message handler member functions
  1482.     afx_msg void OnAskCbFormatName(UINT nMaxCount, LPSTR lpszString);
  1483.     afx_msg void OnChangeCbChain(HWND hWndRemove, HWND hWndAfter);
  1484.     afx_msg void OnDestroyClipboard();
  1485.     afx_msg void OnDrawClipboard();
  1486.     afx_msg void OnHScrollClipboard(CWnd* pClipAppWnd, UINT nSBCode, UINT nPos);
  1487.     afx_msg void OnPaintClipboard(CWnd* pClipAppWnd, HGLOBAL hPaintStruct);
  1488.     afx_msg void OnRenderAllFormats();
  1489.     afx_msg void OnRenderFormat(UINT nFormat);
  1490.     afx_msg void OnSizeClipboard(CWnd* pClipAppWnd, HGLOBAL hRect);
  1491.     afx_msg void OnVScrollClipboard(CWnd* pClipAppWnd, UINT nSBCode, UINT nPos);
  1492.  
  1493. // Control message handler member functions
  1494.     afx_msg int OnCompareItem(int nIDCtl, LPCOMPAREITEMSTRUCT lpCompareItemStruct);
  1495.     afx_msg void OnDeleteItem(int nIDCtl, LPDELETEITEMSTRUCT lpDeleteItemStruct);
  1496.     afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
  1497.     afx_msg UINT OnGetDlgCode();
  1498.     afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
  1499.     afx_msg int OnCharToItem(UINT nChar, CListBox* pListBox, UINT nIndex);
  1500.     afx_msg int OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex);
  1501.  
  1502. // MDI message handler member functions
  1503.     afx_msg void OnMDIActivate(BOOL bActivate,
  1504.             CWnd* pActivateWnd, CWnd* pDeactivateWnd);
  1505.  
  1506. // Overridables and other helpers (for implementation of derived classes)
  1507. protected:
  1508.     // for deriving from a standard control
  1509.     virtual WNDPROC* GetSuperWndProcAddr();
  1510.  
  1511.     // for dialog data exchange and validation
  1512.     virtual void DoDataExchange(CDataExchange* pDX);
  1513.  
  1514. public:
  1515.     // for translating Windows messages in main message pump
  1516.     virtual BOOL PreTranslateMessage(MSG* pMsg);
  1517.  
  1518. protected:
  1519.     // for processing Windows messages
  1520.     virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
  1521.  
  1522.     // for handling default processing
  1523.     LRESULT Default();
  1524.     virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
  1525.  
  1526.     // for custom cleanup after WM_NCDESTROY
  1527.     virtual void PostNcDestroy();
  1528.     // for notifications from parent
  1529.     virtual BOOL OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam,
  1530.                     LRESULT* pLResult);
  1531.                     // return TRUE if parent should not process this message
  1532.  
  1533. // Implementation
  1534. public:
  1535.     virtual ~CWnd();
  1536. #ifdef _DEBUG
  1537.     virtual void AssertValid() const;
  1538.     virtual void Dump(CDumpContext& dc) const;
  1539. #endif
  1540.     // helper routines for implementation
  1541.     BOOL SendChildNotifyLastMsg(LRESULT* pLResult = NULL);
  1542.     BOOL ExecuteDlgInit(LPCSTR lpszResourceName);
  1543.     static BOOL PASCAL GrayCtlColor(HDC hDC, HWND hWnd, UINT nCtlColor,
  1544.             HBRUSH hbrGray, COLORREF clrText);
  1545.     void CenterWindow(CWnd* pAlternateOwner = NULL);
  1546.  
  1547.     // implementation message handlers for private messages
  1548.     afx_msg LRESULT OnVBXEvent(WPARAM wParam, LPARAM lParam);
  1549.  
  1550. protected:
  1551.     // implementation of message routing
  1552.     friend LRESULT CALLBACK AFX_EXPORT _AfxSendMsgHook(int, WPARAM, LPARAM);
  1553.     friend LRESULT PASCAL _AfxCallWndProc(CWnd*, HWND, UINT, WPARAM, LPARAM);
  1554.  
  1555.     //{{AFX_MSG(CWnd)
  1556.     //}}AFX_MSG
  1557.     DECLARE_MESSAGE_MAP()
  1558. };
  1559.  
  1560. // helpers for registering your own WNDCLASSes
  1561. const char* AFXAPI AfxRegisterWndClass(UINT nClassStyle,
  1562.     HCURSOR hCursor = 0, HBRUSH hbrBackground = 0, HICON hIcon = 0);
  1563.  
  1564. // Implementation
  1565. LRESULT CALLBACK AFX_EXPORT AfxWndProc(HWND, UINT, WPARAM, LPARAM);
  1566. typedef void (AFX_MSG_CALL CWnd::*AFX_PMSGW)(void);
  1567.         // like 'AFX_PMSG' but for CWnd derived classes only
  1568.  
  1569. /////////////////////////////////////////////////////////////////////////////
  1570. // CDialog - a modal or modeless dialog
  1571.  
  1572. class CDialog : public CWnd
  1573. {
  1574.     DECLARE_DYNAMIC(CDialog)
  1575.  
  1576.     // Modeless construct
  1577.         // (protected since you must subclass to implement a modeless Dialog)
  1578. protected:
  1579.     CDialog();
  1580.  
  1581.     BOOL Create(LPCSTR lpszTemplateName, CWnd* pParentWnd = NULL);
  1582.     BOOL Create(UINT nIDTemplate, CWnd* pParentWnd = NULL);
  1583.     BOOL CreateIndirect(const void FAR* lpDialogTemplate,
  1584.         CWnd* pParentWnd = NULL);
  1585.  
  1586.     // Modal construct
  1587. public:
  1588.     CDialog(LPCSTR lpszTemplateName, CWnd* pParentWnd = NULL);
  1589.     CDialog(UINT nIDTemplate, CWnd* pParentWnd = NULL);
  1590.  
  1591.     BOOL InitModalIndirect(HGLOBAL hDialogTemplate);
  1592.                              // was CModalDialog::Create()
  1593.  
  1594. // Attributes
  1595. public:
  1596.     void MapDialogRect(LPRECT lpRect) const;
  1597.     void SetHelpID(UINT nIDR);
  1598.  
  1599. // Operations
  1600. public:
  1601.     // modal processing
  1602.     virtual int DoModal();
  1603.  
  1604.     // message processing for modeless
  1605.     BOOL IsDialogMessage(LPMSG lpMsg);
  1606.  
  1607.     // support for passing on tab control - use 'PostMessage' if needed
  1608.     void NextDlgCtrl() const;
  1609.     void PrevDlgCtrl() const;
  1610.     void GotoDlgCtrl(CWnd* pWndCtrl);
  1611.  
  1612.     // default button access
  1613.     void SetDefID(UINT nID);
  1614.     DWORD GetDefID() const;
  1615.  
  1616.     // termination
  1617.     void EndDialog(int nResult);
  1618.  
  1619. // Overridables (special message map entries)
  1620.     virtual BOOL OnInitDialog();
  1621.     virtual void OnSetFont(CFont* pFont);
  1622. protected:
  1623.     virtual void OnOK();
  1624.     virtual void OnCancel();
  1625.  
  1626. // Implementation
  1627. public:
  1628.     virtual ~CDialog();
  1629. #ifdef _DEBUG
  1630.     virtual void AssertValid() const;
  1631.     virtual void Dump(CDumpContext& dc) const;
  1632. #endif
  1633.     virtual BOOL PreTranslateMessage(MSG* pMsg);
  1634.     virtual WNDPROC* GetSuperWndProcAddr();
  1635.     virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra,
  1636.         AFX_CMDHANDLERINFO* pHandlerInfo);
  1637.  
  1638. protected:
  1639.     UINT m_nIDHelp;             // Help ID (0 for none, see HID_BASE_RESOURCE)
  1640.  
  1641.     // parameters for 'DoModal'
  1642.     LPCSTR m_lpDialogTemplate;  // name or MAKEINTRESOURCE
  1643.     HGLOBAL m_hDialogTemplate;  // Indirect if (lpDialogTemplate == NULL)
  1644.     CWnd* m_pParentWnd;
  1645.  
  1646. protected:
  1647.     //{{AFX_MSG(CDialog)
  1648.     afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
  1649.     afx_msg LRESULT OnCommandHelp(WPARAM wParam, LPARAM lParam);
  1650.     afx_msg LRESULT OnHelpHitTest(WPARAM wParam, LPARAM lParam);
  1651.     //}}AFX_MSG
  1652.     DECLARE_MESSAGE_MAP()
  1653. };
  1654.  
  1655. // all CModalDialog functionality is now in CDialog
  1656. #define CModalDialog    CDialog
  1657.  
  1658. /////////////////////////////////////////////////////////////////////////////
  1659. // Standard Windows controls
  1660.  
  1661. class CStatic : public CWnd
  1662. {
  1663.     DECLARE_DYNAMIC(CStatic)
  1664.  
  1665. // Constructors
  1666. public:
  1667.     CStatic();
  1668.     BOOL Create(LPCSTR lpszText, DWORD dwStyle,
  1669.                 const RECT& rect, CWnd* pParentWnd, UINT nID = 0xffff);
  1670.  
  1671. #if (WINVER >= 0x030a)
  1672.     HICON SetIcon(HICON hIcon);
  1673.     HICON GetIcon() const;
  1674. #endif
  1675.  
  1676. // Implementation
  1677. public:
  1678.     virtual ~CStatic();
  1679. protected:
  1680.     virtual WNDPROC* GetSuperWndProcAddr();
  1681. };
  1682.  
  1683. class CButton : public CWnd
  1684. {
  1685.     DECLARE_DYNAMIC(CButton)
  1686.  
  1687. // Constructors
  1688. public:
  1689.     CButton();
  1690.     BOOL Create(LPCSTR lpszCaption, DWORD dwStyle,
  1691.                 const RECT& rect, CWnd* pParentWnd, UINT nID);
  1692.  
  1693. // Attributes
  1694.     UINT GetState() const;
  1695.     void SetState(BOOL bHighlight);
  1696.     int GetCheck() const;
  1697.     void SetCheck(int nCheck);
  1698.     UINT GetButtonStyle() const;
  1699.     void SetButtonStyle(UINT nStyle, BOOL bRedraw = TRUE);
  1700.  
  1701. // Overridables (for owner draw only)
  1702.     virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
  1703.  
  1704. // Implementation
  1705. public:
  1706.     virtual ~CButton();
  1707. protected:
  1708.     virtual WNDPROC* GetSuperWndProcAddr();
  1709.     virtual BOOL OnChildNotify(UINT, WPARAM, LPARAM, LRESULT*);
  1710. };
  1711.  
  1712.  
  1713. class CListBox : public CWnd
  1714. {
  1715.     DECLARE_DYNAMIC(CListBox)
  1716.  
  1717. // Constructors
  1718. public:
  1719.     CListBox();
  1720.     BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
  1721.  
  1722. // Attributes
  1723.  
  1724.     // for entire listbox
  1725.     int GetCount() const;
  1726.     int GetHorizontalExtent() const;
  1727.     void SetHorizontalExtent(int cxExtent);
  1728.     int GetTopIndex() const;
  1729.     int SetTopIndex(int nIndex);
  1730.  
  1731.     // for single-selection listboxes
  1732.     int GetCurSel() const;
  1733.     int SetCurSel(int nSelect);
  1734.  
  1735.     // for multiple-selection listboxes
  1736.     int GetSel(int nIndex) const;           // also works for single-selection
  1737.     int SetSel(int nIndex, BOOL bSelect = TRUE);
  1738.     int GetSelCount() const;
  1739.     int GetSelItems(int nMaxItems, LPINT rgIndex) const;
  1740.  
  1741.     // for listbox items
  1742.     DWORD GetItemData(int nIndex) const;
  1743.     int SetItemData(int nIndex, DWORD dwItemData);
  1744.     void* GetItemDataPtr(int nIndex) const;
  1745.     int SetItemDataPtr(int nIndex, void* pData);
  1746.     int GetItemRect(int nIndex, LPRECT lpRect) const;
  1747.     int GetText(int nIndex, LPSTR lpszBuffer) const;
  1748.     int GetTextLen(int nIndex) const;
  1749.     void GetText(int nIndex, CString& rString) const;
  1750.  
  1751.     // Settable only attributes
  1752.     void SetColumnWidth(int cxWidth);
  1753.     BOOL SetTabStops(int nTabStops, LPINT rgTabStops);
  1754.     void SetTabStops();
  1755.     BOOL SetTabStops(const int& cxEachStop);    // takes an 'int'
  1756.  
  1757. #if (WINVER >= 0x030a)
  1758.     int SetItemHeight(int nIndex, UINT cyItemHeight);
  1759.     int GetItemHeight(int nIndex) const;
  1760.     int FindStringExact(int nIndexStart, LPCSTR lpszFind) const;
  1761.     int GetCaretIndex() const;
  1762.     int SetCaretIndex(int nIndex, BOOL bScroll = TRUE);
  1763. #endif
  1764.  
  1765. // Operations
  1766.     // manipulating listbox items
  1767.     int AddString(LPCSTR lpszItem);
  1768.     int DeleteString(UINT nIndex);
  1769.     int InsertString(int nIndex, LPCSTR lpszItem);
  1770.     void ResetContent();
  1771.     int Dir(UINT attr, LPCSTR lpszWildCard);
  1772.  
  1773.     // selection helpers
  1774.     int FindString(int nStartAfter, LPCSTR lpszItem) const;
  1775.     int SelectString(int nStartAfter, LPCSTR lpszItem);
  1776.     int SelItemRange(BOOL bSelect, int nFirstItem, int nLastItem);
  1777.  
  1778. // Overridables (must override draw, measure and compare for owner draw)
  1779.     virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
  1780.     virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
  1781.     virtual int CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct);
  1782.     virtual void DeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct);
  1783.  
  1784. // Implementation
  1785. public:
  1786.     virtual ~CListBox();
  1787. protected:
  1788.     virtual WNDPROC* GetSuperWndProcAddr();
  1789.     virtual BOOL OnChildNotify(UINT, WPARAM, LPARAM, LRESULT*);
  1790. };
  1791.  
  1792. class CComboBox : public CWnd
  1793. {
  1794.     DECLARE_DYNAMIC(CComboBox)
  1795.  
  1796. // Constructors
  1797. public:
  1798.     CComboBox();
  1799.     BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
  1800.  
  1801. // Attributes
  1802.     // for entire combo box
  1803.     int GetCount() const;
  1804.     int GetCurSel() const;
  1805.     int SetCurSel(int nSelect);
  1806.  
  1807.     // for edit control
  1808.     DWORD GetEditSel() const;
  1809.     BOOL LimitText(int nMaxChars);
  1810.     BOOL SetEditSel(int nStartChar, int nEndChar);
  1811.  
  1812.     // for combobox item
  1813.     DWORD GetItemData(int nIndex) const;
  1814.     int SetItemData(int nIndex, DWORD dwItemData);
  1815.     void* GetItemDataPtr(int nIndex) const;
  1816.     int SetItemDataPtr(int nIndex, void* pData);
  1817.     int GetLBText(int nIndex, LPSTR lpszText) const;
  1818.     int GetLBTextLen(int nIndex) const;
  1819.     void GetLBText(int nIndex, CString& rString) const;
  1820.  
  1821. #if (WINVER >= 0x030a)
  1822.     int SetItemHeight(int nIndex, UINT cyItemHeight);
  1823.     int GetItemHeight(int nIndex) const;
  1824.     int FindStringExact(int nIndexStart, LPCSTR lpszFind) const;
  1825.     int SetExtendedUI(BOOL bExtended = TRUE);
  1826.     BOOL GetExtendedUI() const;
  1827.     void GetDroppedControlRect(LPRECT lprect) const;
  1828.     BOOL GetDroppedState() const;
  1829. #endif
  1830.  
  1831. // Operations
  1832.     // for drop-down combo boxes
  1833.     void ShowDropDown(BOOL bShowIt = TRUE);
  1834.  
  1835.     // manipulating listbox items
  1836.     int AddString(LPCSTR lpszString);
  1837.     int DeleteString(UINT nIndex);
  1838.     int InsertString(int nIndex, LPCSTR lpszString);
  1839.     void ResetContent();
  1840.     int Dir(UINT attr, LPCSTR lpszWildCard);
  1841.  
  1842.     // selection helpers
  1843.     int FindString(int nStartAfter, LPCSTR lpszString) const;
  1844.     int SelectString(int nStartAfter, LPCSTR lpszString);
  1845.  
  1846.     // Clipboard operations
  1847.     void Clear();
  1848.     void Copy();
  1849.     void Cut();
  1850.     void Paste();
  1851.  
  1852. // Overridables (must override draw, measure and compare for owner draw)
  1853.     virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
  1854.     virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
  1855.     virtual int CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct);
  1856.     virtual void DeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct);
  1857.  
  1858. // Implementation
  1859. public:
  1860.     virtual ~CComboBox();
  1861. protected:
  1862.     virtual WNDPROC* GetSuperWndProcAddr();
  1863.     virtual BOOL OnChildNotify(UINT, WPARAM, LPARAM, LRESULT*);
  1864. };
  1865.  
  1866.  
  1867. class CEdit : public CWnd
  1868. {
  1869.     DECLARE_DYNAMIC(CEdit)
  1870.  
  1871. // Constructors
  1872. public:
  1873.     CEdit();
  1874.     BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
  1875.  
  1876. // Attributes
  1877.     BOOL CanUndo() const;
  1878.     int GetLineCount() const;
  1879.     BOOL GetModify() const;
  1880.     void SetModify(BOOL bModified = TRUE);
  1881.     void GetRect(LPRECT lpRect) const;
  1882.     DWORD GetSel() const;
  1883.     void GetSel(int& nStartChar, int& nEndChar) const;
  1884.     HLOCAL GetHandle() const;
  1885.     void SetHandle(HLOCAL hBuffer);
  1886.  
  1887.     // NOTE: first word in lpszBuffer must contain the size of the buffer!
  1888.     int GetLine(int nIndex, LPSTR lpszBuffer) const;
  1889.     int GetLine(int nIndex, LPSTR lpszBuffer, int nMaxLength) const;
  1890.  
  1891. // Operations
  1892.     void EmptyUndoBuffer();
  1893.     BOOL FmtLines(BOOL bAddEOL);
  1894.  
  1895.     void LimitText(int nChars = 0);
  1896.     int LineFromChar(int nIndex = -1) const;
  1897.     int LineIndex(int nLine = -1) const;
  1898.     int LineLength(int nLine = -1) const;
  1899.     void LineScroll(int nLines, int nChars = 0);
  1900.     void ReplaceSel(LPCSTR lpszNewText);
  1901.     void SetPasswordChar(char ch);
  1902.     void SetRect(LPCRECT lpRect);
  1903.     void SetRectNP(LPCRECT lpRect);
  1904.     void SetSel(DWORD dwSelection, BOOL bNoScroll = FALSE);
  1905.     void SetSel(int nStartChar, int nEndChar, BOOL bNoScroll = FALSE);
  1906.     BOOL SetTabStops(int nTabStops, LPINT rgTabStops);
  1907.     void SetTabStops();
  1908.     BOOL SetTabStops(const int& cxEachStop);    // takes an 'int'
  1909.  
  1910.     // Clipboard operations
  1911.     BOOL Undo();
  1912.     void Clear();
  1913.     void Copy();
  1914.     void Cut();
  1915.     void Paste();
  1916.  
  1917. #if (WINVER >= 0x030a)
  1918.     BOOL SetReadOnly(BOOL bReadOnly = TRUE);
  1919.     int GetFirstVisibleLine() const;
  1920.     char GetPasswordChar() const;
  1921. #endif
  1922.  
  1923. // Implementation
  1924. public:
  1925.     virtual ~CEdit();
  1926. protected:
  1927.     virtual WNDPROC* GetSuperWndProcAddr();
  1928. };
  1929.  
  1930.  
  1931. class CScrollBar : public CWnd
  1932. {
  1933.     DECLARE_DYNAMIC(CScrollBar)
  1934.  
  1935. // Constructors
  1936. public:
  1937.     CScrollBar();
  1938.     BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
  1939.  
  1940. // Attributes
  1941.     int GetScrollPos() const;
  1942.     int SetScrollPos(int nPos, BOOL bRedraw = TRUE);
  1943.     void GetScrollRange(LPINT lpMinPos, LPINT lpMaxPos) const;
  1944.     void SetScrollRange(int nMinPos, int nMaxPos, BOOL bRedraw = TRUE);
  1945.     void ShowScrollBar(BOOL bShow = TRUE);
  1946.  
  1947. #if (WINVER >= 0x030a)
  1948.     BOOL EnableScrollBar(UINT nArrowFlags = ESB_ENABLE_BOTH);
  1949. #endif
  1950.  
  1951. // Implementation
  1952. public:
  1953.     virtual ~CScrollBar();
  1954. protected:
  1955.     virtual WNDPROC* GetSuperWndProcAddr();
  1956. };
  1957.  
  1958. /////////////////////////////////////////////////////////////////////////////
  1959. // CFrameWnd - base class for SDI and other frame windows
  1960.  
  1961. // Frame window styles
  1962. #define FWS_ADDTOTITLE      0x8000      // modify title based on content
  1963.  
  1964. struct CPrintPreviewState;    // forward reference (see afxext.h)
  1965.  
  1966. class CFrameWnd : public CWnd
  1967. {
  1968.     DECLARE_DYNCREATE(CFrameWnd)
  1969.  
  1970. // Constructors
  1971. public:
  1972.     static const CRect AFXAPI_DATA rectDefault;
  1973.     CFrameWnd();
  1974.  
  1975.     BOOL LoadAccelTable(LPCSTR lpszResourceName);
  1976.     BOOL Create(LPCSTR lpszClassName,
  1977.                 LPCSTR lpszWindowName,
  1978.                 DWORD dwStyle = WS_OVERLAPPEDWINDOW,
  1979.                 const RECT& rect = rectDefault,
  1980.                 CWnd* pParentWnd = NULL,        // != NULL for popups
  1981.                 LPCSTR lpszMenuName = NULL,
  1982.                 DWORD dwExStyle = 0,
  1983.                 CCreateContext* pContext = NULL);
  1984.  
  1985.     // dynamic creation - load frame and associated resources
  1986.     virtual BOOL LoadFrame(UINT nIDResource,
  1987.                 DWORD dwDefaultStyle = WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE,
  1988.                 CWnd* pParentWnd = NULL,
  1989.                 CCreateContext* pContext = NULL);
  1990.  
  1991. // Attributes
  1992.     virtual CDocument* GetActiveDocument();
  1993.  
  1994.     // Active child view maintenance
  1995.     CView* GetActiveView() const;           // active view or NULL
  1996.     void SetActiveView(CView* pViewNew);    // active view or NULL
  1997.  
  1998.     BOOL m_bAutoMenuEnable;
  1999.                     // TRUE => menu items without handlers will be disabled
  2000.  
  2001. // Operations
  2002.     virtual void RecalcLayout();
  2003.     virtual void ActivateFrame(int nCmdShow = -1);
  2004.  
  2005. // Overridables
  2006.     virtual void OnSetPreviewMode(BOOL bPreview, CPrintPreviewState* pState);
  2007. protected:
  2008.     virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
  2009.  
  2010. // Implementation
  2011. public:
  2012.     int m_nWindow;  // general purpose window number - display as ":n"
  2013.                     // -1 => unknown, 0 => only window viewing document
  2014.                     // 1 => first of many windows viewing document, 2=> second
  2015. protected:
  2016.     UINT m_nIDHelp;             // Help ID (0 for none, see HID_BASE_RESOURCE)
  2017.     HACCEL m_hAccelTable;       // accelerator table
  2018.     UINT m_nIDTracking;         // tracking command ID or string IDS
  2019.     UINT m_nIDLastMessage;      // last displayed message string IDS
  2020.     CView* m_pViewActive;       // current active view
  2021.     BOOL (CALLBACK* m_lpfnCloseProc)(CFrameWnd* pFrameWnd);
  2022.  
  2023. public:
  2024. #ifdef _DEBUG
  2025.     virtual void AssertValid() const;
  2026.     virtual void Dump(CDumpContext& dc) const;
  2027. #endif
  2028.     BOOL IsTracking() const;
  2029.     virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra,
  2030.         AFX_CMDHANDLERINFO* pHandlerInfo);
  2031.     virtual CWnd* GetMessageBar();
  2032.     virtual void OnUpdateFrameTitle(BOOL bAddToTitle);
  2033.  
  2034. protected:
  2035.     LPCSTR GetIconWndClass(DWORD dwDefaultStyle, UINT nIDResource);
  2036.     void UpdateFrameTitleForDocument(const char* pszDocName);
  2037.     virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  2038.     virtual BOOL PreTranslateMessage(MSG* pMsg);
  2039.     virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
  2040.     virtual void PostNcDestroy();   // default to delete this.
  2041.     int OnCreateHelper(LPCREATESTRUCT lpcs, CCreateContext* pContext);
  2042.  
  2043.     //{{AFX_MSG(CFrameWnd)
  2044.     // Windows messages
  2045.     afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  2046.     afx_msg void OnDestroy();
  2047.     afx_msg void OnNcDestroy();
  2048.     afx_msg void OnClose();
  2049.     afx_msg void OnInitMenuPopup(CMenu*, UINT, BOOL);
  2050.     afx_msg void OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu);
  2051.     afx_msg LRESULT OnSetMessageString(WPARAM wParam, LPARAM lParam);
  2052.     afx_msg void OnEnterIdle(UINT nWhy, CWnd* pWho);
  2053.     afx_msg void OnSetFocus(CWnd* pOldWnd);
  2054.     afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  2055.     afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  2056.     afx_msg void OnSize(UINT nType, int cx, int cy);
  2057.     afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  2058.     afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
  2059.     afx_msg void OnActivateApp(BOOL bActive, HTASK hTask);
  2060.     afx_msg void OnSysCommand(UINT nID, LONG lParam);
  2061.     afx_msg BOOL OnQueryEndSession();
  2062.     afx_msg void OnDropFiles(HDROP hDropInfo);
  2063.     afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
  2064.     afx_msg LRESULT OnCommandHelp(WPARAM wParam, LPARAM lParam);
  2065.     afx_msg LRESULT OnHelpHitTest(WPARAM wParam, LPARAM lParam);
  2066.     afx_msg LRESULT OnDDEInitiate(WPARAM wParam, LPARAM lParam);
  2067.     afx_msg LRESULT OnDDEExecute(WPARAM wParam, LPARAM lParam);
  2068.     afx_msg LRESULT OnDDETerminate(WPARAM wParam, LPARAM lParam);
  2069.     afx_msg void OnSysColorChange();
  2070.     // standard commands
  2071.     afx_msg void OnUpdateControlBarMenu(CCmdUI* pCmdUI);
  2072.     afx_msg BOOL OnBarCheck(UINT nID);
  2073.     afx_msg void OnUpdateKeyIndicator(CCmdUI* pCmdUI);
  2074.     //}}AFX_MSG
  2075.     DECLARE_MESSAGE_MAP()
  2076. };
  2077.  
  2078.  
  2079. /////////////////////////////////////////////////////////////////////////////
  2080. // MDI Support
  2081.  
  2082. class CMDIFrameWnd : public CFrameWnd
  2083. {
  2084.     DECLARE_DYNCREATE(CMDIFrameWnd)
  2085.  
  2086. public:
  2087.  
  2088. // Constructors
  2089.     CMDIFrameWnd();
  2090.  
  2091. // Operations
  2092.     void MDIActivate(CWnd* pWndActivate);
  2093.     CMDIChildWnd* MDIGetActive(BOOL* pbMaximized = NULL) const;
  2094.     void MDIIconArrange();
  2095.     void MDIMaximize(CWnd* pWnd);
  2096.     void MDINext();
  2097.     void MDIRestore(CWnd* pWnd);
  2098.     CMenu* MDISetMenu(CMenu* pFrameMenu, CMenu* pWindowMenu);
  2099.     void MDITile();
  2100.     void MDICascade();
  2101.  
  2102. #if (WINVER >= 0x030a)
  2103.     void MDITile(int nType);
  2104.     void MDICascade(int nType);
  2105. #endif
  2106.  
  2107. // Overridables
  2108.     // MFC V1 backward compatible CreateClient hook (called by OnCreateClient)
  2109.     virtual BOOL CreateClient(LPCREATESTRUCT lpCreateStruct, CMenu* pWindowMenu);
  2110.     // customize if using an 'Window' menu with non-standard IDs
  2111.     virtual HMENU GetWindowMenuPopup(HMENU hMenuBar);
  2112.  
  2113. // Implementation
  2114. public:
  2115.     HWND m_hWndMDIClient;       // MDI Client window handle
  2116.     HMENU m_hMenuDefault;       // menu when no active child (owned)
  2117.  
  2118. #ifdef _DEBUG
  2119.     virtual void AssertValid() const;
  2120.     virtual void Dump(CDumpContext& dc) const;
  2121. #endif
  2122.     virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  2123.     virtual BOOL LoadFrame(UINT nIDResource,
  2124.                 DWORD dwDefaultStyle = WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE,
  2125.                 CWnd* pParentWnd = NULL,
  2126.                 CCreateContext* pContext = NULL);
  2127.     virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
  2128.     virtual BOOL PreTranslateMessage(MSG* pMsg);
  2129.     virtual void OnUpdateFrameTitle(BOOL bAddToTitle);
  2130.     virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra,
  2131.         AFX_CMDHANDLERINFO* pHandlerInfo);
  2132. protected:
  2133.     virtual LRESULT DefWindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam);
  2134.     virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
  2135.  
  2136.     //{{AFX_MSG(CMDIFrameWnd)
  2137.     afx_msg void OnDestroy();
  2138.     afx_msg void OnSize(UINT nType, int cx, int cy);
  2139.     afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
  2140.     afx_msg void OnUpdateMDIWindowCmd(CCmdUI* pCmdUI);
  2141.     afx_msg BOOL OnMDIWindowCmd(UINT nID);
  2142.     afx_msg void OnWindowNew();
  2143.     afx_msg LRESULT OnCommandHelp(WPARAM wParam, LPARAM lParam);
  2144.     //}}AFX_MSG
  2145.     DECLARE_MESSAGE_MAP()
  2146. };
  2147.  
  2148.  
  2149. class CMDIChildWnd : public CFrameWnd
  2150. {
  2151.     DECLARE_DYNCREATE(CMDIChildWnd)
  2152.  
  2153. // Constructors
  2154. public:
  2155.     CMDIChildWnd();
  2156.  
  2157.     BOOL Create(LPCSTR lpszClassName,
  2158.                 LPCSTR lpszWindowName,
  2159.                 DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW,
  2160.                 const RECT& rect = rectDefault,
  2161.                 CMDIFrameWnd* pParentWnd = NULL,
  2162.                 CCreateContext* pContext = NULL);
  2163.  
  2164. // Attributes
  2165.     CMDIFrameWnd* GetMDIFrame();
  2166.  
  2167. // Operations
  2168.     void MDIDestroy();
  2169.     void MDIActivate();
  2170.     void MDIMaximize();
  2171.     void MDIRestore();
  2172.  
  2173. // Implementation
  2174. protected:
  2175.     HMENU m_hMenuShared;        // menu when we are active
  2176. public:
  2177. #ifdef _DEBUG
  2178.     virtual void AssertValid() const;
  2179.     virtual void Dump(CDumpContext& dc) const;
  2180. #endif
  2181.  
  2182.     virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  2183.     virtual BOOL LoadFrame(UINT nIDResource, DWORD dwDefaultStyle,
  2184.                     CWnd* pParentWnd, CCreateContext* pContext = NULL);
  2185.                     // 'pParentWnd' parameter is required for MDI Child
  2186.     virtual BOOL DestroyWindow();
  2187.     virtual BOOL PreTranslateMessage(MSG* pMsg);
  2188.     virtual void ActivateFrame(int nCmdShow = -1);
  2189. protected:
  2190.     virtual CWnd* GetMessageBar();
  2191.     virtual void OnUpdateFrameTitle(BOOL bAddToTitle);
  2192.     virtual LRESULT DefWindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam);
  2193.     //{{AFX_MSG(CMDIChildWnd)
  2194.     afx_msg void OnMDIActivate(BOOL bActivate, CWnd*, CWnd*);
  2195.     afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  2196.     afx_msg void OnSize(UINT nType, int cx, int cy);
  2197.     //}}AFX_MSG
  2198.     DECLARE_MESSAGE_MAP()
  2199. };
  2200.  
  2201. /////////////////////////////////////////////////////////////////////////////
  2202. // class CView is the client area UI for a document
  2203.  
  2204. class CPrintDialog;     // forward reference (from afxdlgs.h)
  2205. class CPreviewView;
  2206.  
  2207. class CView : public CWnd
  2208. {
  2209.     DECLARE_DYNAMIC(CView)
  2210.  
  2211. // Constructors
  2212. protected:
  2213.     CView();
  2214.  
  2215. // Attributes
  2216. public:
  2217.     CDocument* GetDocument() const;
  2218.  
  2219. // Operations
  2220. public:
  2221.     // for standard printing setup (override OnPreparePrinting)
  2222.     BOOL DoPreparePrinting(CPrintInfo* pInfo);
  2223.  
  2224. // Overridables
  2225. public:
  2226.     virtual BOOL IsSelected(const CObject* pDocItem) const; // support for OLE
  2227.  
  2228. protected:
  2229.     // Activation
  2230.     virtual void OnActivateView(BOOL bActivate, CView* pActivateView,
  2231.                     CView* pDeactiveView);
  2232.  
  2233.     // General drawing/updating
  2234.     virtual void OnInitialUpdate();     // first time after construct
  2235.     virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
  2236.     virtual void OnDraw(CDC* pDC) = 0;
  2237.     virtual void OnPrepareDC(CDC* pDC, CPrintInfo* pInfo = NULL);
  2238.  
  2239.     // Printing support
  2240.     virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
  2241.                     // must override to enable printing and print preview
  2242.  
  2243.     virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
  2244.     virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
  2245.     virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
  2246.  
  2247.     // Advanced: end print preview mode, move to point
  2248.     virtual void OnEndPrintPreview(CDC* pDC, CPrintInfo* pInfo, POINT point,
  2249.                     CPreviewView* pView);
  2250.  
  2251. // Implementation
  2252. public:
  2253.     virtual ~CView();
  2254. #ifdef _DEBUG
  2255.     virtual void Dump(CDumpContext&) const;
  2256.     virtual void AssertValid() const;
  2257. #endif //_DEBUG
  2258.  
  2259.     // Advanced: for implementing custom print preview
  2260.     BOOL DoPrintPreview(UINT nIDResource, CView* pPrintView,
  2261.             CRuntimeClass* pPreviewViewClass, CPrintPreviewState* pState);
  2262.  
  2263. protected:
  2264.     CDocument* m_pDocument;
  2265.  
  2266.     virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra,
  2267.         AFX_CMDHANDLERINFO* pHandlerInfo);
  2268.     virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  2269.     virtual void PostNcDestroy();
  2270.     virtual CScrollBar* GetScrollBarCtrl(int nBar) const;
  2271.  
  2272.     // friend classes that call protected CView overridables
  2273.     friend class CDocument;
  2274.     friend class CPreviewView;
  2275.     friend class CFrameWnd;
  2276.     friend class CMDIFrameWnd;
  2277.     friend class CMDIChildWnd;
  2278.     friend class CSplitterWnd;
  2279.  
  2280.     //{{AFX_MSG(CView)
  2281.     afx_msg int OnCreate(LPCREATESTRUCT lpcs);
  2282.     afx_msg void OnDestroy();
  2283.     afx_msg void OnPaint();
  2284.     afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
  2285.     // commands
  2286.     afx_msg void OnUpdateSplitCmd(CCmdUI* pCmdUI);
  2287.     afx_msg BOOL OnSplitCmd(UINT nID);
  2288.     afx_msg void OnUpdateNextPaneMenu(CCmdUI* pCmdUI);
  2289.     afx_msg BOOL OnNextPaneCmd(UINT nID);
  2290.  
  2291.     // not mapped commands - must be mapped in derived class
  2292.     afx_msg void OnFilePrint();
  2293.     afx_msg void OnFilePrintPreview();
  2294.     //}}AFX_MSG
  2295.     DECLARE_MESSAGE_MAP()
  2296. };
  2297.  
  2298. /////////////////////////////////////////////////////////////////////////////
  2299. // class CScrollView supports simple scrolling and scaling
  2300.  
  2301. class CScrollView : public CView
  2302. {
  2303.     DECLARE_DYNAMIC(CScrollView)
  2304.  
  2305. // Constructors
  2306. protected:
  2307.     CScrollView();
  2308.  
  2309. public:
  2310.     static const SIZE AFXAPI_DATA sizeDefault;
  2311.         // used to specify default calculated page and line sizes
  2312.  
  2313.     // in logical units - call one of the following Set routines
  2314.     void SetScaleToFitSize(SIZE sizeTotal);
  2315.     void SetScrollSizes(int nMapMode, SIZE sizeTotal,
  2316.                 const SIZE& sizePage = sizeDefault,
  2317.                 const SIZE& sizeLine = sizeDefault);
  2318.  
  2319. // Attributes
  2320. public:
  2321.     CPoint GetScrollPosition() const;       // upper corner of scrolling
  2322.     CSize GetTotalSize() const;             // logical size
  2323.  
  2324.     // for device units
  2325.     CPoint GetDeviceScrollPosition() const;
  2326.     void GetDeviceScrollSizes(int& nMapMode, SIZE& sizeTotal,
  2327.             SIZE& sizePage, SIZE& sizeLine) const;
  2328.  
  2329. // Operations
  2330. public:
  2331.     void ScrollToPosition(POINT pt);    // set upper left position
  2332.     void FillOutsideRect(CDC* pDC, CBrush* pBrush);
  2333.     void ResizeParentToFit(BOOL bShrinkOnly = TRUE);
  2334.  
  2335. // Implementation
  2336. protected:
  2337.     int m_nMapMode;
  2338.     CSize m_totalLog;         // total size in logical units (no rounding)
  2339.     CSize m_totalDev;         // total size in device units
  2340.     CSize m_pageDev;          // per page scroll size in device units
  2341.     CSize m_lineDev;          // per line scroll size in device units
  2342.  
  2343.     BOOL m_bCenter;          // Center output if larger than total size
  2344.     BOOL m_bInsideUpdate;    // internal state for OnSize callback
  2345.     void CenterOnPoint(CPoint ptCenter);
  2346.     void ScrollToDevicePosition(POINT ptDev); // explicit scrolling no checking
  2347.  
  2348. protected:
  2349.     virtual void OnDraw(CDC* pDC) = 0;      // pass on pure virtual
  2350.     virtual void OnPrepareDC(CDC* pDC, CPrintInfo* pInfo = NULL);
  2351.  
  2352.     void UpdateBars(); // adjust scrollbars etc
  2353.     BOOL GetTrueClientSize(CSize& size, CSize& sizeSb); // size with no bars
  2354. public:
  2355.     virtual ~CScrollView();
  2356. #ifdef _DEBUG
  2357.     virtual void Dump(CDumpContext&) const;
  2358.     virtual void AssertValid() const;
  2359. #endif //_DEBUG
  2360.  
  2361.     void OnScroll(int nBar, UINT nSBCode, UINT nPos);
  2362.     //{{AFX_MSG(CScrollView)
  2363.     afx_msg void OnSize(UINT nType, int cx, int cy);
  2364.     afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  2365.     afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  2366.     //}}AFX_MSG
  2367.     DECLARE_MESSAGE_MAP()
  2368. };
  2369.  
  2370. /////////////////////////////////////////////////////////////////////////////
  2371. /////////////////////////////////////////////////////////////////////////////
  2372. // Global functions for access to the one and only CWinApp
  2373.  
  2374. extern "C"
  2375. {
  2376. #ifndef _AFXDLL
  2377. // standard C variables if you wish to access them from C programs,
  2378. // use inline functions for C++ programs
  2379. extern CWinApp* NEAR afxCurrentWinApp;
  2380. extern HINSTANCE NEAR afxCurrentInstanceHandle;
  2381. extern HINSTANCE NEAR afxCurrentResourceHandle;
  2382. extern const char* NEAR afxCurrentAppName;
  2383. #endif //!_AFXDLL
  2384.  
  2385. // Advanced initialization: for overriding default WinMain
  2386. extern BOOL AFXAPI AfxWinInit(HINSTANCE, HINSTANCE, LPSTR, int);
  2387. extern void AFXAPI AfxWinTerm();
  2388. }
  2389.  
  2390. // Global Windows state data helper functions (inlines)
  2391. CWinApp* AFXAPI AfxGetApp();
  2392. HINSTANCE AFXAPI AfxGetInstanceHandle();
  2393. HINSTANCE AFXAPI AfxGetResourceHandle();
  2394. void AFXAPI AfxSetResourceHandle(HINSTANCE hInstResource);
  2395. const char* AFXAPI AfxGetAppName();
  2396.  
  2397. /////////////////////////////////////////////////////////////////////////////
  2398. // CWinApp - the root of all Windows applications
  2399.  
  2400. #define _AFX_MRU_COUNT   4       // default support for 4 entries in file MRU
  2401.  
  2402. class CWinApp : public CCmdTarget
  2403. {
  2404.     DECLARE_DYNAMIC(CWinApp)
  2405. public:
  2406.  
  2407. // Constructor
  2408.     CWinApp(const char* pszAppName = NULL);     // app name defaults to EXE name
  2409.  
  2410. // Attributes
  2411.     // Startup args (do not change)
  2412.     HINSTANCE m_hInstance;
  2413.     HINSTANCE m_hPrevInstance;
  2414.     LPSTR m_lpCmdLine;
  2415.     int m_nCmdShow;
  2416.  
  2417.     // Running args (can be changed in InitInstance)
  2418.     CWnd* m_pMainWnd;           // main window (optional)
  2419.     const char* m_pszAppName;   // human readable name
  2420.                                 //  (from constructor or AFX_IDS_APP_TITLE)
  2421.  
  2422.     // Support for Shift+F1 help mode.
  2423.     BOOL m_bHelpMode;               // are we in Shift+F1 mode?
  2424.  
  2425. public:  // set in constructor to override default
  2426.     const char* m_pszExeName;       // executable name (no spaces)
  2427.     const char* m_pszHelpFilePath;  // default based on module path
  2428.     const char* m_pszProfileName;   // default based on app name
  2429.  
  2430. // Initialization Operations - should be done in InitInstance
  2431. protected:
  2432.     void LoadStdProfileSettings(); // load MRU file list and last preview state
  2433.     void EnableVBX();
  2434.     void EnableShellOpen();
  2435.  
  2436.     void SetDialogBkColor(COLORREF clrCtlBk = RGB(192, 192, 192),
  2437.                 COLORREF clrCtlText = RGB(0, 0, 0));
  2438.                 // set dialog box and message box background color
  2439.  
  2440.     void RegisterShellFileTypes();
  2441.                 // call after all doc templates are registered
  2442.  
  2443. // Helper Operations - usually done in InitInstance
  2444. public:
  2445.     // Cursors
  2446.     HCURSOR LoadCursor(LPCSTR lpszResourceName) const;
  2447.     HCURSOR LoadCursor(UINT nIDResource) const;
  2448.     HCURSOR LoadStandardCursor(LPCSTR lpszCursorName) const; // for IDC_ values
  2449.     HCURSOR LoadOEMCursor(UINT nIDCursor) const;             // for OCR_ values
  2450.  
  2451.     // Icons
  2452.     HICON LoadIcon(LPCSTR lpszResourceName) const;
  2453.     HICON LoadIcon(UINT nIDResource) const;
  2454.     HICON LoadStandardIcon(LPCSTR lpszIconName) const;       // for IDI_ values
  2455.     HICON LoadOEMIcon(UINT nIDIcon) const;                   // for OIC_ values
  2456.  
  2457.     // Profile settings (to the app specific .INI file)
  2458.     UINT GetProfileInt(LPCSTR lpszSection, LPCSTR lpszEntry, int nDefault);
  2459.     BOOL WriteProfileInt(LPCSTR lpszSection, LPCSTR lpszEntry, int nValue);
  2460.     CString GetProfileString(LPCSTR lpszSection, LPCSTR lpszEntry,
  2461.                 LPCSTR lpszDefault = NULL);
  2462.     BOOL WriteProfileString(LPCSTR lpszSection, LPCSTR lpszEntry,
  2463.                 LPCSTR lpszValue);
  2464.  
  2465. // Running Operations - to be done on a running application
  2466.     // Dealing with document templates
  2467.     void AddDocTemplate(CDocTemplate* pTemplate);
  2468.  
  2469.     // Dealing with files
  2470.     virtual CDocument* OpenDocumentFile(LPCSTR lpszFileName); // open named file
  2471.     virtual void AddToRecentFileList(const char* pszPathName);  // add to MRU
  2472.  
  2473.     // Printer DC Setup routine, 'struct tagPD' is a PRINTDLG structure
  2474.     BOOL GetPrinterDeviceDefaults(struct tagPD FAR* pPrintDlg);
  2475.  
  2476.     // Preloading/Unloading VBX files and checking for existance
  2477.     HMODULE LoadVBXFile(LPCSTR lpszFileName);
  2478.     BOOL UnloadVBXFile(LPCSTR lpszFileName);
  2479.  
  2480. // Overridables
  2481.     // hooks for your initialization code
  2482.     virtual BOOL InitApplication();
  2483.     virtual BOOL InitInstance();
  2484.  
  2485.     // running and idle processing
  2486.     virtual int Run();
  2487.     virtual BOOL PreTranslateMessage(MSG* pMsg);
  2488.     virtual BOOL OnIdle(LONG lCount); // return TRUE if more idle processing
  2489.  
  2490.     // exiting
  2491.     virtual BOOL SaveAllModified(); // save before exit
  2492.     virtual int ExitInstance(); // return app exit code
  2493.  
  2494.     // Advanced: to override message boxes and other hooks
  2495.     virtual int DoMessageBox(LPCSTR lpszPrompt, UINT nType, UINT nIDPrompt);
  2496.     virtual BOOL ProcessMessageFilter(int code, LPMSG lpMsg);
  2497.     virtual LRESULT ProcessWndProcException(CException* e, const MSG* pMsg);
  2498.     virtual void DoWaitCursor(int nCode); // 0 => restore, 1=> begin, -1=> end
  2499.  
  2500.     // Advanced: process async DDE request
  2501.     virtual BOOL OnDDECommand(char* pszCommand);
  2502.  
  2503.     // Help support (overriding is advanced)
  2504.     virtual void WinHelp(DWORD dwData, UINT nCmd = HELP_CONTEXT);   // general
  2505.  
  2506. // Command Handlers
  2507. protected:
  2508.     // map to the following for file new/open
  2509.     afx_msg void OnFileNew();
  2510.     afx_msg void OnFileOpen();
  2511.  
  2512.     // map to the following to enable print setup
  2513.     afx_msg void OnFilePrintSetup();
  2514.  
  2515.     // map to the following to enable help
  2516.     afx_msg void OnContextHelp();   // shift-F1
  2517.     afx_msg void OnHelp();          // F1 (uses current context)
  2518.     afx_msg void OnHelpIndex();     // ID_HELP_INDEX, ID_DEFAULT_HELP
  2519.     afx_msg void OnHelpUsing();     // ID_HELP_USING
  2520.  
  2521. // Implementation
  2522. protected:
  2523.     MSG m_msgCur;                   // current message
  2524.  
  2525.     CPtrList m_templateList;        // list of templates
  2526.     HGLOBAL m_hDevMode;             // printer Dev Mode
  2527.     HGLOBAL m_hDevNames;            // printer Device Names
  2528.     DWORD m_dwPromptContext;        // help context override for message box
  2529.  
  2530.     int m_nWaitCursorCount;         // for wait cursor (>0 => waiting)
  2531.     HCURSOR m_hcurWaitCursorRestore; // old cursor to restore after wait cursor
  2532.  
  2533.     CString m_strRecentFiles[_AFX_MRU_COUNT]; // default MRU implementation
  2534.     void (CALLBACK* m_lpfnCleanupVBXFiles)();
  2535.  
  2536.     void UpdatePrinterSelection(BOOL bForceDefaults);
  2537.     void SaveStdProfileSettings();  // save options to .INI file
  2538.     BOOL ProcessHelpMsg(MSG& msg, DWORD* pContext);
  2539.     HWND SetHelpCapture(POINT ptCursor);
  2540.  
  2541. public: // public for implementation access
  2542.     ATOM m_atomApp, m_atomSystemTopic;   // for DDE open
  2543.     HCURSOR m_hcurHelp;           // always loaded if m_bHelpMode == TRUE
  2544.     UINT m_nNumPreviewPages;      // number of default printed pages
  2545.  
  2546.     // memory safety pool
  2547.     size_t  m_nSafetyPoolSize;      // ideal size
  2548.     void*   m_pSafetyPoolBuffer;    // current buffer
  2549.  
  2550.     void SetCurrentHandles();
  2551.     BOOL PumpMessage();     // low level message pump
  2552.     int GetOpenDocumentCount();
  2553.  
  2554.     // helpers for standard commdlg dialogs
  2555.     BOOL DoPromptFileName(CString& fileName, UINT nIDSTitle,
  2556.             DWORD lFlags, BOOL bOpenFileDialog, CDocTemplate* pTemplate);
  2557.     int DoPrintDialog(CPrintDialog* pPD);
  2558.  
  2559. public:
  2560.     virtual ~CWinApp();
  2561. #ifdef _DEBUG
  2562.     virtual void AssertValid() const;
  2563.     virtual void Dump(CDumpContext& dc) const;
  2564.     int m_nDisablePumpCount; // Diagnostic trap to detect illegal re-entrancy
  2565. #endif //_DEBUG
  2566.  
  2567. #ifdef _AFXDLL
  2568.     // force linkage to AFXDLL startup code and special stack segment for
  2569.     //    applications linking with AFXDLL
  2570.     virtual void _ForceLinkage();
  2571. #endif //_AFXDLL
  2572.  
  2573. protected: // standard commands
  2574.     //{{AFX_MSG(CWinApp)
  2575.     afx_msg void OnAppExit();
  2576.     afx_msg void OnUpdateRecentFileMenu(CCmdUI* pCmdUI);
  2577.     afx_msg BOOL OnOpenRecentFile(UINT nID);
  2578.     //}}AFX_MSG
  2579.     DECLARE_MESSAGE_MAP()
  2580. };
  2581.  
  2582. /////////////////////////////////////////////////////////////////////////////
  2583. // class CDocTemplate creates documents
  2584.  
  2585. class CDocTemplate : public CCmdTarget
  2586. {
  2587.     DECLARE_DYNAMIC(CDocTemplate)
  2588.  
  2589. // Constructors
  2590. protected:
  2591.     CDocTemplate(UINT nIDResource, CRuntimeClass* pDocClass,
  2592.         CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass);
  2593.  
  2594. // Attributes
  2595. public:
  2596.     // iterating over open documents
  2597.     virtual POSITION GetFirstDocPosition() const = 0;
  2598.     virtual CDocument* GetNextDoc(POSITION& rPos) const = 0;
  2599.  
  2600. // Operations
  2601. public:
  2602.     virtual void AddDocument(CDocument* pDoc);      // must override
  2603.     virtual void RemoveDocument(CDocument* pDoc);   // must override
  2604.  
  2605.     enum DocStringIndex
  2606.     {
  2607.         windowTitle,        // default window title
  2608.         docName,            // user visible name for default document
  2609.         fileNewName,        // user visible name for FileNew
  2610.         // for file based documents:
  2611.         filterName,         // user visible name for FileOpen
  2612.         filterExt,          // user visible extension for FileOpen
  2613.         // for file based documents with Shell open support:
  2614.         regFileTypeId,      // REGEDIT visible registered file type identifier
  2615.         regFileTypeName     // Shell visible registered file type name
  2616.     };
  2617.     virtual BOOL GetDocString(CString& rString,
  2618.         enum DocStringIndex index) const; // get one of the info strings
  2619.  
  2620. // Overridables
  2621. public:
  2622.     enum Confidence
  2623.     {
  2624.         noAttempt,
  2625.         maybeAttemptForeign,
  2626.         maybeAttemptNative,
  2627.         yesAttemptForeign,
  2628.         yesAttemptNative,
  2629.         yesAlreadyOpen
  2630.     };
  2631.     virtual Confidence MatchDocType(const char* pszPathName,
  2632.                     CDocument*& rpDocMatch);
  2633.     virtual CDocument* CreateNewDocument();
  2634.     virtual CFrameWnd* CreateNewFrame(CDocument* pDoc, CFrameWnd* pOther);
  2635.     virtual void InitialUpdateFrame(CFrameWnd* pFrame, CDocument* pDoc);
  2636.     virtual BOOL SaveAllModified();       // for all documents
  2637.     virtual CDocument* OpenDocumentFile(const char* pszPathName) = 0;
  2638.                     // open named file
  2639.                     // if lpszPathName == NULL => create new file with this type
  2640.  
  2641. // Implementation
  2642. public:
  2643.     virtual ~CDocTemplate();
  2644.  
  2645.     CObject* m_pAttachedServer; 
  2646.             // back pointer to OLE or other server (NULL if none of disabled)
  2647. #ifdef _DEBUG
  2648.     virtual void Dump(CDumpContext&) const;
  2649.     virtual void AssertValid() const;
  2650. #endif //_DEBUG
  2651.  
  2652. protected:  // standard implementation
  2653.     UINT m_nIDResource;                // IDR_ for frame/menu/accel as well
  2654.     CRuntimeClass* m_pDocClass;        // class for creating new documents
  2655.     CRuntimeClass* m_pFrameClass;      // class for creating new frames
  2656.     CRuntimeClass* m_pViewClass;       // class for creating new views
  2657.     CString m_strDocStrings;    // '\n' separated names
  2658.         // The document names sub-strings are represented as _one_ string:
  2659.         // windowTitle\ndocName\n ... (see DocStringIndex enum)
  2660. };
  2661.  
  2662. // SDI support (1 document only)
  2663. class CSingleDocTemplate : public CDocTemplate
  2664. {
  2665.     DECLARE_DYNAMIC(CSingleDocTemplate)
  2666.  
  2667. // Constructors
  2668. public:
  2669.     CSingleDocTemplate(UINT nIDResource, CRuntimeClass* pDocClass,
  2670.         CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass);
  2671.  
  2672. // Implementation
  2673. public:
  2674.     virtual ~CSingleDocTemplate();
  2675.     virtual void AddDocument(CDocument* pDoc);
  2676.     virtual void RemoveDocument(CDocument* pDoc);
  2677.     virtual POSITION GetFirstDocPosition() const;
  2678.     virtual CDocument* GetNextDoc(POSITION& rPos) const;
  2679.     virtual CDocument* OpenDocumentFile(const char* pszPathName);
  2680. #ifdef _DEBUG
  2681.     virtual void Dump(CDumpContext&) const;
  2682.     virtual void AssertValid() const;
  2683. #endif //_DEBUG
  2684.  
  2685. protected:  // standard implementation
  2686.     CDocument* m_pOnlyDoc;
  2687. };
  2688.  
  2689. // MDI support (zero or more documents)
  2690. class CMultiDocTemplate : public CDocTemplate
  2691. {
  2692.     DECLARE_DYNAMIC(CMultiDocTemplate)
  2693.  
  2694. // Constructors
  2695. public:
  2696.     CMultiDocTemplate(UINT nIDResource, CRuntimeClass* pDocClass,
  2697.         CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass);
  2698.  
  2699. // Implementation
  2700. public:
  2701.     // Menu and accel table for MDI Child windows of this type
  2702.     HMENU m_hMenuShared;
  2703.     HACCEL m_hAccelTable;
  2704.  
  2705.     virtual ~CMultiDocTemplate();
  2706.     virtual void AddDocument(CDocument* pDoc);
  2707.     virtual void RemoveDocument(CDocument* pDoc);
  2708.     virtual POSITION GetFirstDocPosition() const;
  2709.     virtual CDocument* GetNextDoc(POSITION& rPos) const;
  2710.     virtual CDocument* OpenDocumentFile(const char* pszPathName);
  2711. #ifdef _DEBUG
  2712.     virtual void Dump(CDumpContext&) const;
  2713.     virtual void AssertValid() const;
  2714. #endif //_DEBUG
  2715.  
  2716. protected:  // standard implementation
  2717.     CPtrList m_docList;          // open documents of this type
  2718.     UINT m_nUntitledCount;   // start at 0, for "Document1" title
  2719. };
  2720.  
  2721. /////////////////////////////////////////////////////////////////////////////
  2722. // class CDocument is the main document data abstraction
  2723.  
  2724. class CDocument : public CCmdTarget
  2725. {
  2726.     DECLARE_DYNAMIC(CDocument)
  2727.  
  2728. public:
  2729. // Constructors
  2730.     CDocument();
  2731.  
  2732. // Attributes
  2733. public:
  2734.     const CString& GetTitle() const;
  2735.     virtual void SetTitle(const char* pszTitle);
  2736.     const CString& GetPathName() const;
  2737.     virtual void SetPathName(const char* pszPathName);
  2738.  
  2739.     CDocTemplate* GetDocTemplate() const;
  2740.     BOOL IsModified();
  2741.     void SetModifiedFlag(BOOL bModified = TRUE);
  2742.  
  2743. // Operations
  2744.     void AddView(CView* pView);
  2745.     void RemoveView(CView* pView);
  2746.     virtual POSITION GetFirstViewPosition() const;
  2747.     virtual CView* GetNextView(POSITION& rPosition) const;
  2748.  
  2749.     // Update Views (simple update - DAG only)
  2750.     void UpdateAllViews(CView* pSender, LPARAM lHint = 0L,
  2751.                                 CObject* pHint = NULL);
  2752.  
  2753. // Overridables
  2754.     // Special notifications
  2755.     virtual void OnChangedViewList(); // after Add or Remove view
  2756.     virtual void DeleteContents(); // delete doc items etc
  2757.  
  2758.     // File helpers
  2759.     virtual BOOL OnNewDocument();
  2760.     virtual BOOL OnOpenDocument(const char* pszPathName);
  2761.     virtual BOOL OnSaveDocument(const char* pszPathName);
  2762.     virtual void OnCloseDocument();
  2763.     virtual void ReportSaveLoadException(const char* pszPathName,
  2764.                 CException* e, BOOL bSaving, UINT nIDPDefault);
  2765.  
  2766.     // advanced overridables, closing down frame/doc
  2767.     virtual BOOL CanCloseFrame(CFrameWnd* pFrame);
  2768.     virtual BOOL SaveModified(); // return TRUE if ok to continue
  2769.  
  2770. // Implementation
  2771. protected:
  2772.     // default implementation
  2773.     CString m_strTitle;
  2774.     CString m_strPathName;
  2775.     CDocTemplate* m_pDocTemplate;
  2776.     CPtrList m_viewList;                // list of views
  2777.     BOOL m_bModified;                   // changed since last saved
  2778.  
  2779. public:
  2780.     BOOL m_bAutoDelete;           // TRUE => delete document when no more views
  2781.  
  2782. #ifdef _DEBUG
  2783.     virtual void Dump(CDumpContext&) const;
  2784.     virtual void AssertValid() const;
  2785. #endif //_DEBUG
  2786.     virtual ~CDocument();
  2787.     BOOL DoSave(const char* pszPathName, BOOL bReplace = TRUE);
  2788.     void UpdateFrameCounts();
  2789.  
  2790.     virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra,
  2791.         AFX_CMDHANDLERINFO* pHandlerInfo);
  2792.     friend class CDocTemplate;
  2793. protected:
  2794.     // file menu commands
  2795.     //{{AFX_MSG(CDocument)
  2796.     afx_msg void OnFileClose();
  2797.     afx_msg void OnFileSave();
  2798.     afx_msg void OnFileSaveAs();
  2799.     //}}AFX_MSG
  2800.     DECLARE_MESSAGE_MAP()
  2801. };
  2802.  
  2803. /////////////////////////////////////////////////////////////////////////////
  2804. // Extra diagnostic tracing options
  2805.  
  2806. #ifdef _DEBUG
  2807. // afxTraceFlags
  2808.     // 1 => multi-app debugging
  2809.     // 2 => main message pump trace (includes DDE)
  2810.     // 4 => Windows message tracing
  2811.     // 8 => Windows command routing trace (set 4+8 for control notifications)
  2812.     // 16 (0x10) => special OLE callback trace
  2813. #ifndef _AFXDLL
  2814. extern "C" { extern int NEAR afxTraceFlags; }
  2815. #endif //!_AFXDLL
  2816. #endif // _DEBUG
  2817.  
  2818. //////////////////////////////////////////////////////////////////////////////
  2819. // MessageBox helpers
  2820.  
  2821. void AFXAPI AfxFormatString1(CString& rString, UINT nIDS, LPCSTR lpsz1);
  2822. void AFXAPI AfxFormatString2(CString& rString, UINT nIDS,
  2823.                 LPCSTR lpsz1, LPCSTR lpsz2);
  2824. int AFXAPI AfxMessageBox(LPCSTR lpszText, UINT nType = MB_OK,
  2825.                 UINT nIDHelp = 0);
  2826. int AFXAPI AfxMessageBox(UINT nIDPrompt, UINT nType = MB_OK,
  2827.                 UINT nIDHelp = (UINT)-1);
  2828.  
  2829. // Implementation string helpers
  2830. void AFXAPI AfxFormatStrings(CString& rString, UINT nIDS,
  2831.                 LPCSTR* rglpsz, int nString);
  2832. void AFXAPI AfxFormatStrings(CString& rString, LPCSTR lpszFormat,
  2833.                 LPCSTR* rglpsz, int nString);
  2834. BOOL AFXAPI AfxExtractSubString(CString& rString, LPCSTR lpszFullString,
  2835.                 int iSubString, char chSep = '\012');
  2836.  
  2837. /////////////////////////////////////////////////////////////////////////////
  2838. // Special target variant APIs
  2839.  
  2840. // AFX DLL special includes
  2841. #ifdef _AFXDLL
  2842. #include "afxdll_.h"
  2843. #endif
  2844.  
  2845. // Windows Version compatibility
  2846. void AFXAPI AfxEnableWin30Compatibility();
  2847.  
  2848. /////////////////////////////////////////////////////////////////////////////
  2849. // Inline function declarations
  2850.  
  2851. #ifdef _AFX_ENABLE_INLINES
  2852. #define _AFXWIN_INLINE inline
  2853. #include "afxwin.inl"
  2854. #endif
  2855.  
  2856. #undef AFXAPP_DATA
  2857. #define AFXAPP_DATA     NEAR
  2858.  
  2859. /////////////////////////////////////////////////////////////////////////////
  2860. #else //RC_INVOKED
  2861. #include "afxres.h"     // standard resource IDs
  2862. #endif //RC_INVOKED
  2863. #endif //__AFXWIN_H__
  2864.