Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3246 lines
102 KiB

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