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.

1129 lines
27 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1995 - 1998 **/
  4. /**********************************************************************/
  5. /*
  6. FILE HISTORY:
  7. */
  8. #ifndef _COMMON_H_
  9. #define _COMMON_H_
  10. #ifndef _IPADDR_H
  11. #include "ipaddr.h"
  12. #endif
  13. //
  14. // Forward declarations
  15. //
  16. class CObjHelper ;
  17. class CObjectPlus ;
  18. class CObOwnedList ;
  19. class CObListIter ;
  20. class CObOwnedArray ;
  21. //
  22. // Wrappers for the *BROKEN* C8 TRY/CATCH stuff
  23. //
  24. #define CATCH_MEM_EXCEPTION \
  25. TRY
  26. #define END_MEM_EXCEPTION(err) \
  27. CATCH_ALL(e) { \
  28. err = ERROR_NOT_ENOUGH_MEMORY ; \
  29. } END_CATCH_ALL
  30. /****************************************************************************
  31. DEBUGAFX.H
  32. ****************************************************************************/
  33. //
  34. // ENUM for special debug output control tokens
  35. //
  36. enum ENUM_DEBUG_AFX { EDBUG_AFX_EOL = -1 } ;
  37. #if defined(_DEBUG)
  38. #define TRACEFMTPGM DbgFmtPgm( THIS_FILE, __LINE__ )
  39. #define TRACEOUT(x) { afxDump << x ; }
  40. #define TRACEEOL(x) { afxDump << x << EDBUG_AFX_EOL ; }
  41. #define TRACEEOLID(x) { afxDump << TRACEFMTPGM << x << EDBUG_AFX_EOL ; }
  42. #define TRACEEOLERR(err,x) { if (err) TRACEEOLID(x) }
  43. #else
  44. #define TRACEOUT(x) { ; }
  45. #define TRACEEOL(x) { ; }
  46. #define TRACEEOLID(x) { ; }
  47. #define TRACEEOLERR(err,x) { ; }
  48. #endif
  49. //
  50. // Append an EOL onto the debug output stream
  51. //
  52. CDumpContext & operator << ( CDumpContext & out, ENUM_DEBUG_AFX edAfx ) ;
  53. //
  54. // Format a program name and line number for output (removes the path info)
  55. //
  56. extern const char * DbgFmtPgm ( const char * szFn, int line ) ;
  57. /****************************************************************************
  58. OBJPLUS.H
  59. ****************************************************************************/
  60. //
  61. // Helper class for control of construction and API errors
  62. //
  63. class CObjHelper
  64. {
  65. protected:
  66. LONG m_ctor_err ;
  67. LONG m_api_err ;
  68. DWORD m_time_created ;
  69. BOOL m_b_dirty ;
  70. CObjHelper () ;
  71. public:
  72. void AssertValid () const ;
  73. virtual BOOL IsValid () const ;
  74. operator BOOL()
  75. {
  76. return (IsValid());
  77. }
  78. //
  79. // Update the Dirty flag
  80. //
  81. void SetDirty ( BOOL bDirty = TRUE )
  82. {
  83. m_b_dirty = bDirty ;
  84. }
  85. //
  86. // Query the Dirty flag
  87. //
  88. BOOL IsDirty () const
  89. {
  90. return m_b_dirty ;
  91. }
  92. //
  93. // Return the creation time of this object
  94. //
  95. DWORD QueryCreationTime() const
  96. {
  97. return m_time_created ;
  98. }
  99. //
  100. // Return the elapsed time this object has been alive.
  101. //
  102. DWORD QueryAge () const ;
  103. //
  104. // Query/set constuction failure
  105. //
  106. void ReportError ( LONG errInConstruction ) ;
  107. LONG QueryError () const
  108. {
  109. return m_ctor_err ;
  110. }
  111. //
  112. // Reset all error conditions.
  113. //
  114. void ResetErrors ()
  115. {
  116. m_ctor_err = m_api_err = 0 ;
  117. }
  118. //
  119. // Query/set API errors.
  120. //
  121. LONG QueryApiErr () const
  122. {
  123. return m_api_err ;
  124. }
  125. //
  126. // SetApiErr() echoes the error to the caller.for use in expressions.
  127. //
  128. LONG SetApiErr ( LONG errApi = 0 ) ;
  129. };
  130. class CObjectPlus : public CObject, public CObjHelper
  131. {
  132. public:
  133. CObjectPlus () ;
  134. //
  135. // Compare one object with another
  136. //
  137. virtual int Compare ( const CObjectPlus * pob ) const ;
  138. //
  139. // Define a typedef for an ordering function.
  140. //
  141. typedef int (CObjectPlus::*PCOBJPLUS_ORDER_FUNC) ( const CObjectPlus * pobOther ) const ;
  142. //
  143. // Helper function to release RPC memory from RPC API calls.
  144. //
  145. static void FreeRpcMemory ( void * pvRpcData ) ;
  146. };
  147. class CObListIter : public CObjectPlus
  148. {
  149. protected:
  150. POSITION m_pos ;
  151. const CObOwnedList & m_obList ;
  152. public:
  153. CObListIter ( const CObOwnedList & obList ) ;
  154. CObject * Next () ;
  155. void Reset () ;
  156. POSITION QueryPosition () const
  157. {
  158. return m_pos ;
  159. }
  160. void SetPosition(POSITION pos)
  161. {
  162. m_pos = pos;
  163. }
  164. };
  165. //
  166. // Object pointer list which "owns" the objects pointed to.
  167. //
  168. class CObOwnedList : public CObList, public CObjHelper
  169. {
  170. protected:
  171. BOOL m_b_owned ;
  172. static int _cdecl SortHelper ( const void * pa, const void * pb ) ;
  173. public:
  174. CObOwnedList ( int nBlockSize = 10 ) ;
  175. virtual ~ CObOwnedList () ;
  176. BOOL SetOwnership ( BOOL bOwned = TRUE )
  177. {
  178. BOOL bOld = m_b_owned ;
  179. m_b_owned = bOwned ;
  180. return bOld ;
  181. }
  182. CObject * Index ( int index ) ;
  183. CObject * RemoveIndex ( int index ) ;
  184. BOOL Remove ( CObject * pob ) ;
  185. void RemoveAll () ;
  186. int FindElement ( CObject * pobSought ) const ;
  187. //
  188. // Set all elements to dirty or clean. Return TRUE if
  189. // any element was dirty.
  190. //
  191. BOOL SetAll ( BOOL bDirty = FALSE ) ;
  192. //
  193. // Override of CObList::AddTail() to control exception handling.
  194. // Returns NULL if addition fails.
  195. //
  196. POSITION AddTail ( CObjectPlus * pobj, BOOL bThrowException = FALSE ) ;
  197. //
  198. // Sort the list elements according to the
  199. // given ordering function.
  200. //
  201. LONG Sort ( CObjectPlus::PCOBJPLUS_ORDER_FUNC pOrderFunc ) ;
  202. };
  203. //
  204. // Object array which "owns" the objects pointed to.
  205. //
  206. class CObOwnedArray : public CObArray, public CObjHelper
  207. {
  208. protected:
  209. BOOL m_b_owned ;
  210. static int _cdecl SortHelper ( const void * pa, const void * pb ) ;
  211. public:
  212. CObOwnedArray () ;
  213. virtual ~ CObOwnedArray () ;
  214. BOOL SetOwnership ( BOOL bOwned = TRUE )
  215. {
  216. BOOL bOld = m_b_owned ;
  217. m_b_owned = bOwned ;
  218. return bOld ;
  219. }
  220. void RemoveAt( int nIndex, int nCount = 1);
  221. void RemoveAll () ;
  222. int FindElement ( CObject * pobSought ) const ;
  223. //
  224. // Set all elements to dirty or clean. Return TRUE if
  225. // any element was dirty.
  226. //
  227. BOOL SetAll ( BOOL bDirty = FALSE ) ;
  228. //
  229. // Sort the list elements according to the
  230. // given ordering function.
  231. //
  232. LONG Sort ( CObjectPlus::PCOBJPLUS_ORDER_FUNC pOrderFunc ) ;
  233. private:
  234. void QuickSort(
  235. int nLow,
  236. int nHigh,
  237. CObjectPlus::PCOBJPLUS_ORDER_FUNC pOrderFunc
  238. );
  239. void Swap(
  240. int nIndex1,
  241. int nIndex2
  242. );
  243. };
  244. /***************************************************************************
  245. IPADDRES.H
  246. ***************************************************************************/
  247. //
  248. // IP Address Conversion Macros
  249. //
  250. /*
  251. #ifndef MAKEIPADDRESS
  252. #define MAKEIPADDRESS(b1,b2,b3,b4) ((LONG)(((DWORD)(b1)<<24)+((DWORD)(b2)<<16)+((DWORD)(b3)<<8)+((DWORD)(b4))))
  253. #define GETIP_FIRST(x) ((x>>24) & 0xff)
  254. #define GETIP_SECOND(x) ((x>>16) & 0xff)
  255. #define GETIP_THIRD(x) ((x>> 8) & 0xff)
  256. #define GETIP_FOURTH(x) ((x) & 0xff)
  257. #endif // MAKEIPADDRESS
  258. */
  259. /////////////////////////////////////////////////////////////////////////////
  260. // CIpAddress class
  261. class CIpAddress : public CObjectPlus
  262. {
  263. public:
  264. // Constructors
  265. CIpAddress()
  266. {
  267. m_lIpAddress = 0L;
  268. m_fInitOk = FALSE;
  269. }
  270. CIpAddress (LONG l)
  271. {
  272. m_lIpAddress = l;
  273. m_fInitOk = TRUE;
  274. }
  275. CIpAddress (BYTE b1, BYTE b2, BYTE b3, BYTE b4)
  276. {
  277. m_lIpAddress = MAKEIPADDRESS(b1,b2,b3,b4);
  278. m_fInitOk = TRUE;
  279. }
  280. CIpAddress(const CIpAddress& ia)
  281. {
  282. m_lIpAddress = ia.m_lIpAddress;
  283. m_fInitOk = ia.m_fInitOk;
  284. }
  285. CIpAddress (const CString & str);
  286. //
  287. // Assignment operators
  288. //
  289. const CIpAddress & operator =(const LONG l);
  290. const CIpAddress & operator =(const CString & str);
  291. const CIpAddress & operator =(const CIpAddress& ia)
  292. {
  293. m_lIpAddress = ia.m_lIpAddress;
  294. m_fInitOk = ia.m_fInitOk;
  295. return *this;
  296. }
  297. //
  298. // Conversion operators
  299. //
  300. operator const LONG() const
  301. {
  302. return m_lIpAddress;
  303. }
  304. operator const CString&() const;
  305. public:
  306. BOOL IsValid() const
  307. {
  308. return m_fInitOk;
  309. }
  310. private:
  311. LONG m_lIpAddress;
  312. BOOL m_fInitOk;
  313. };
  314. /****************************************************************************
  315. INTLTIME.H
  316. ****************************************************************************/
  317. //
  318. // CIntlTime class definition
  319. //
  320. class CIntlTime : public CTime
  321. {
  322. //
  323. // Attributes
  324. //
  325. public:
  326. enum _TIME_FORMAT_REQUESTS
  327. {
  328. TFRQ_TIME_ONLY,
  329. TFRQ_DATE_ONLY,
  330. TFRQ_TIME_AND_DATE,
  331. TFRQ_TIME_OR_DATE,
  332. TFRQ_MILITARY_TIME,
  333. };
  334. public:
  335. // Same contructors as CTime
  336. CIntlTime();
  337. CIntlTime(const CTime &timeSrc);
  338. CIntlTime(time_t time);
  339. CIntlTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec);
  340. CIntlTime(WORD wDosDate, WORD wDosTime);
  341. #ifdef _WIN32
  342. CIntlTime(const SYSTEMTIME& sysTime);
  343. CIntlTime(const FILETIME& fileTime);
  344. #endif // _WIN32
  345. // New for CIntlTime
  346. CIntlTime(const CIntlTime &timeSrc);
  347. CIntlTime(const CString &strTime, int nFormat = TFRQ_TIME_OR_DATE, time_t * ptmOldValue = NULL);
  348. public:
  349. virtual ~CIntlTime();
  350. // Operations
  351. public:
  352. // Assignment operators
  353. const CIntlTime& operator=(time_t tmValue);
  354. const CIntlTime& operator=(const CString& strValue);
  355. const CIntlTime& operator=(const CTime & time);
  356. const CIntlTime& operator=(const CIntlTime & time);
  357. // Conversion operators
  358. operator const time_t() const;
  359. operator CString() const;
  360. operator const CString() const;
  361. const CString IntlFormat(int nFormat) const
  362. {
  363. return(ConvertToString(nFormat));
  364. }
  365. // Validation checks
  366. BOOL IsValid() const
  367. {
  368. return(m_fInitOk);
  369. }
  370. static BOOL IsIntlValid()
  371. {
  372. return(CIntlTime::m_fIntlOk);
  373. }
  374. public:
  375. // ... Input and output
  376. #ifdef _DEBUG
  377. friend CDumpContext& AFXAPI operator<<(CDumpContext& dc, const CIntlTime& tim);
  378. #endif // _DEBUG
  379. friend CArchive& AFXAPI operator <<(CArchive& ar, const CIntlTime& tim);
  380. friend CArchive& AFXAPI operator >>(CArchive& ar, CIntlTime& tim);
  381. // Implementation
  382. public:
  383. static void Reset();
  384. static void SetBadDateAndTime(CString strBadDate = "--", CString strBadTime = "--")
  385. {
  386. m_strBadDate = strBadDate;
  387. m_strBadTime = strBadTime;
  388. }
  389. static CString& GetBadDate()
  390. {
  391. return(m_strBadDate);
  392. }
  393. static CString& GetBadTime()
  394. {
  395. return(m_strBadTime);
  396. }
  397. static time_t ConvertFromString (const CString & str, int nFormat, time_t * ptmOldValue, BOOL * pfOk);
  398. static BOOL IsLeapYear(UINT nYear); // Complete year value
  399. static BOOL IsValidDate(UINT nMonth, UINT nDay, UINT nYear);
  400. static BOOL IsValidTime(UINT nHour, UINT nMinute, UINT nSecond);
  401. private:
  402. enum _DATE_FORMATS
  403. {
  404. _DFMT_MDY, // Day, month, year
  405. _DFMT_DMY, // Month, day, year
  406. _DFMT_YMD, // Year, month, day
  407. };
  408. typedef struct _INTL_TIME_SETTINGS
  409. {
  410. CString strDateSeperator; // String used between date fields
  411. CString strTimeSeperator; // String used between time fields.
  412. CString strAM; // Suffix string used for 12 hour clock AM times
  413. CString strPM; // Suffix string used for 12 hour clock PM times
  414. int nDateFormat; // see _DATE_FORMATS enum above.
  415. BOOL f24HourClock; // TRUE = 24 hours, FALSE is AM/PM
  416. BOOL fCentury; // If TRUE, uses 4 digits for the century
  417. BOOL fLeadingTimeZero; // If TRUE, uses leading 0 in time format
  418. BOOL fLeadingDayZero; // If TRUE, uses leading 0 in day
  419. BOOL fLeadingMonthZero; // If TRUE, uses leading 0 in month
  420. } INTL_TIME_SETTINGS;
  421. static INTL_TIME_SETTINGS m_itsInternationalSettings;
  422. static CString m_strBadTime;
  423. static CString m_strBadDate;
  424. private:
  425. static BOOL SetIntlTimeSettings();
  426. static BOOL m_fIntlOk;
  427. private:
  428. const CString GetDateString() const;
  429. const CString GetTimeString() const;
  430. const CString GetMilitaryTime() const;
  431. const CString ConvertToString(int nFormat) const;
  432. private:
  433. BOOL m_fInitOk;
  434. };
  435. /****************************************************************************
  436. NUMERIC.H
  437. ****************************************************************************/
  438. class CIntlNumber : public CObjectPlus
  439. {
  440. public:
  441. CIntlNumber()
  442. {
  443. m_lValue = 0L;
  444. m_fInitOk = TRUE;
  445. }
  446. CIntlNumber(LONG lValue)
  447. {
  448. m_lValue = lValue;
  449. m_fInitOk = TRUE;
  450. }
  451. CIntlNumber(const CString & str);
  452. CIntlNumber(CIntlNumber const &x)
  453. {
  454. m_lValue = x.m_lValue;
  455. m_fInitOk = x.m_fInitOk;
  456. }
  457. CIntlNumber& operator =(CIntlNumber const &x)
  458. {
  459. m_lValue = x.m_lValue;
  460. m_fInitOk = x.m_fInitOk;
  461. return(*this);
  462. }
  463. public:
  464. // Assignment Operators
  465. CIntlNumber& operator =(LONG l);
  466. CIntlNumber& operator =(const CString &str);
  467. // Shorthand operators.
  468. CIntlNumber& operator +=(const CIntlNumber& num);
  469. CIntlNumber& operator +=(const LONG l);
  470. CIntlNumber& operator -=(const CIntlNumber& num);
  471. CIntlNumber& operator -=(const LONG l);
  472. CIntlNumber& operator /=(const CIntlNumber& num);
  473. CIntlNumber& operator /=(const LONG l);
  474. CIntlNumber& operator *=(const CIntlNumber& num);
  475. CIntlNumber& operator *=(const LONG l);
  476. // Conversion operators
  477. operator const LONG() const
  478. {
  479. return(m_lValue);
  480. }
  481. operator const CString() const;
  482. public:
  483. virtual BOOL IsValid() const
  484. {
  485. return(m_fInitOk);
  486. }
  487. public:
  488. static void Reset();
  489. static void SetBadNumber(CString strBadNumber = "--")
  490. {
  491. m_strBadNumber = strBadNumber;
  492. }
  493. static CString ConvertNumberToString(const LONG l);
  494. static LONG ConvertStringToNumber(const CString & str, BOOL * pfOk);
  495. static CString& GetBadNumber()
  496. {
  497. return(m_strBadNumber);
  498. }
  499. private:
  500. static CString GetThousandSeperator();
  501. private:
  502. static CString m_strThousandSeperator;
  503. static CString m_strBadNumber;
  504. private:
  505. LONG m_lValue;
  506. BOOL m_fInitOk;
  507. public:
  508. #ifdef _DEBUG
  509. friend CDumpContext& AFXAPI operator<<(CDumpContext& dc, const CIntlNumber& num);
  510. #endif // _DEBUG
  511. friend CArchive& AFXAPI operator<<(CArchive& ar, const CIntlNumber& num);
  512. friend CArchive& AFXAPI operator>>(CArchive& ar, CIntlNumber& num);
  513. };
  514. class CIntlLargeNumber : public CObjectPlus
  515. {
  516. public:
  517. CIntlLargeNumber()
  518. {
  519. m_lLowValue = 0L;
  520. m_lHighValue = 0L;
  521. m_fInitOk = TRUE;
  522. }
  523. CIntlLargeNumber(LONG lHighWord, LONG lLowWord)
  524. {
  525. m_lLowValue = lLowWord;
  526. m_lHighValue = lHighWord;
  527. m_fInitOk = TRUE;
  528. }
  529. CIntlLargeNumber(const CString & str);
  530. public:
  531. // Assignment Operators
  532. CIntlLargeNumber& operator =(const CString &str);
  533. operator const CString() { return ConvertNumberToString(); }
  534. operator CString() { return ConvertNumberToString(); }
  535. public:
  536. virtual LONG GetLowWord() const { return m_lLowValue; }
  537. virtual LONG GetHighWord() const { return m_lHighValue; }
  538. virtual BOOL IsValid() const { return(m_fInitOk); }
  539. private:
  540. static CString m_strBadNumber;
  541. CString ConvertNumberToString();
  542. void ConvertStringToNumber(const CString & str, BOOL * pfOk);
  543. private:
  544. LONG m_lLowValue;
  545. LONG m_lHighValue;
  546. BOOL m_fInitOk;
  547. };
  548. /****************************************************************************
  549. REGISTRY.H
  550. ****************************************************************************/
  551. //
  552. // Forward declarations
  553. //
  554. //class CRegKey ;
  555. class CRegValueIter ;
  556. class CRegKeyIter ;
  557. //
  558. // Maximum size of a Registry class name
  559. //
  560. #define CREGKEY_MAX_CLASS_NAME MAX_PATH
  561. //
  562. // Wrapper for a Registry key handle.
  563. //
  564. /*
  565. class CRegKey : public CObjectPlus
  566. {
  567. protected:
  568. HKEY m_hKey ;
  569. DWORD m_dwDisposition ;
  570. // Prepare to read a value by finding the value's size.
  571. LONG PrepareValue (
  572. const char * pchValueName,
  573. DWORD * pdwType,
  574. DWORD * pcbSize,
  575. BYTE ** ppbData
  576. );
  577. // Convert a CStringList to the REG_MULTI_SZ format
  578. static LONG FlattenValue (
  579. CStringList & strList,
  580. DWORD * pcbSize,
  581. BYTE ** ppbData
  582. );
  583. // Convert a CByteArray to a REG_BINARY block
  584. static LONG FlattenValue (
  585. CByteArray & abData,
  586. DWORD * pcbSize,
  587. BYTE ** ppbData
  588. );
  589. public:
  590. //
  591. // Key information return structure
  592. //
  593. typedef struct
  594. {
  595. char chBuff [CREGKEY_MAX_CLASS_NAME] ;
  596. DWORD dwClassNameSize,
  597. dwNumSubKeys,
  598. dwMaxSubKey,
  599. dwMaxClass,
  600. dwMaxValues,
  601. dwMaxValueName,
  602. dwMaxValueData,
  603. dwSecDesc ;
  604. FILETIME ftKey ;
  605. } CREGKEY_KEY_INFO ;
  606. //
  607. // Standard constructor for an existing key
  608. //
  609. CRegKey (
  610. HKEY hKeyBase,
  611. const char * pchSubKey = NULL,
  612. REGSAM regSam = KEY_ALL_ACCESS,
  613. const char * pchServerName = NULL
  614. );
  615. //
  616. // Constructor creating a new key.
  617. //
  618. CRegKey (
  619. const char * pchSubKey,
  620. HKEY hKeyBase,
  621. DWORD dwOptions = 0,
  622. REGSAM regSam = KEY_ALL_ACCESS,
  623. LPSECURITY_ATTRIBUTES pSecAttr = NULL,
  624. const char * pchServerName = NULL
  625. );
  626. ~ CRegKey () ;
  627. //
  628. // Allow a CRegKey to be used anywhere an HKEY is required.
  629. //
  630. operator HKEY ()
  631. {
  632. return m_hKey ;
  633. }
  634. //
  635. // Fill a key information structure
  636. //
  637. LONG QueryKeyInfo ( CREGKEY_KEY_INFO * pRegKeyInfo ) ;
  638. //
  639. // Overloaded value query members; each returns ERROR_INVALID_PARAMETER
  640. // if data exists but not in correct form to deliver into result object.
  641. //
  642. LONG QueryValue ( const char * pchValueName, CString & strResult ) ;
  643. LONG QueryValue ( const char * pchValueName, CStringList & strList ) ;
  644. LONG QueryValue ( const char * pchValueName, DWORD & dwResult ) ;
  645. LONG QueryValue ( const char * pchValueName, CByteArray & abResult ) ;
  646. LONG QueryValue ( const char * pchValueName, CIntlTime & itmResult ) ;
  647. LONG QueryValue ( const char * pchValueName, CIntlNumber & inResult ) ;
  648. LONG QueryValue ( const char * pchValueName, void * pvResult, DWORD cbSize );
  649. // Overloaded value setting members.
  650. LONG SetValue ( const char * pchValueName, CString & strResult ) ;
  651. LONG SetValue ( const char * pchValueName, CString & strResult , BOOL fRegExpand) ;
  652. LONG SetValue ( const char * pchValueName, CStringList & strList ) ;
  653. LONG SetValue ( const char * pchValueName, DWORD & dwResult ) ;
  654. LONG SetValue ( const char * pchValueName, CByteArray & abResult ) ;
  655. LONG SetValue ( const char * pchValueName, CIntlTime & itmResult ) ;
  656. LONG SetValue ( const char * pchValueName, CIntlNumber & inResult ) ;
  657. LONG SetValue ( const char * pchValueName, void * pvResult, DWORD cbSize );
  658. };
  659. */
  660. //
  661. // Iterate the values of a key, return the name and type
  662. // of each.
  663. //
  664. class CRegValueIter : public CObjectPlus
  665. {
  666. protected:
  667. //CRegKey & m_rk_iter ;
  668. DWORD m_dw_index ;
  669. char * m_p_buffer ;
  670. DWORD m_cb_buffer ;
  671. public:
  672. //CRegValueIter ( CRegKey & regKey ) ;
  673. ~ CRegValueIter () ;
  674. //
  675. // Get the name (and optional last write time) of the next key.
  676. //
  677. LONG Next ( CString * pstrName, DWORD * pdwType ) ;
  678. //
  679. // Reset the iterator
  680. //
  681. void Reset ()
  682. {
  683. m_dw_index = 0 ;
  684. }
  685. };
  686. //
  687. // Iterate the sub-key names of a key.
  688. //
  689. class CRegKeyIter : public CObjectPlus
  690. {
  691. protected:
  692. //CRegKey & m_rk_iter ;
  693. DWORD m_dw_index ;
  694. char * m_p_buffer ;
  695. DWORD m_cb_buffer ;
  696. public:
  697. //CRegKeyIter ( CRegKey & regKey ) ;
  698. ~ CRegKeyIter () ;
  699. // Get the name (and optional last write time) of the next key.
  700. LONG Next ( CString * pstrName, CTime * pTime = NULL ) ;
  701. // Reset the iterator
  702. void Reset ()
  703. {
  704. m_dw_index = 0 ;
  705. }
  706. };
  707. /****************************************************************************
  708. LISTBOX.H
  709. ****************************************************************************/
  710. class CListBoxExResources
  711. {
  712. public:
  713. CListBoxExResources
  714. (
  715. int bmId,
  716. int nBitmapWidth,
  717. COLORREF crBackground = RGB(0,255,0)
  718. );
  719. ~CListBoxExResources();
  720. private:
  721. COLORREF m_ColorWindow;
  722. COLORREF m_ColorHighlight;
  723. COLORREF m_ColorWindowText;
  724. COLORREF m_ColorHighlightText;
  725. COLORREF m_ColorTransparent;
  726. CDC m_dcFinal;
  727. HGDIOBJ m_hOldBitmap;
  728. CBitmap m_BmpScreen;
  729. int m_BitMapId;
  730. int m_BitmapHeight;
  731. int m_BitmapWidth;
  732. int m_nBitmaps;
  733. private:
  734. void GetSysColors();
  735. void PrepareBitmaps( BOOL );
  736. void UnprepareBitmaps();
  737. void UnloadResources();
  738. void LoadResources();
  739. public:
  740. void SysColorChanged();
  741. const CDC& DcBitMap() const
  742. {
  743. return m_dcFinal;
  744. }
  745. int BitmapHeight() const
  746. {
  747. return m_BitmapHeight;
  748. }
  749. int BitmapWidth() const
  750. {
  751. return m_BitmapWidth;
  752. }
  753. COLORREF ColorWindow() const
  754. {
  755. return m_ColorWindow;
  756. }
  757. COLORREF ColorHighlight() const
  758. {
  759. return m_ColorHighlight;
  760. }
  761. COLORREF ColorWindowText() const
  762. {
  763. return m_ColorWindowText;
  764. }
  765. COLORREF ColorHighlightText() const
  766. {
  767. return m_ColorHighlightText;
  768. }
  769. };
  770. class CListBoxExDrawStruct
  771. {
  772. public:
  773. CListBoxExDrawStruct(
  774. CDC* pdc,
  775. RECT* pRect,
  776. BOOL sel,
  777. DWORD item,
  778. int itemIndex,
  779. const CListBoxExResources* pres
  780. )
  781. {
  782. m_pDC = pdc;
  783. m_Sel = sel;
  784. m_ItemData = item;
  785. m_ItemIndex = itemIndex;
  786. m_pResources = pres;
  787. m_Rect.CopyRect(pRect);
  788. }
  789. public:
  790. const CListBoxExResources * m_pResources;
  791. CDC* m_pDC;
  792. CRect m_Rect;
  793. BOOL m_Sel;
  794. DWORD m_ItemData;
  795. int m_ItemIndex;
  796. };
  797. class CListBoxEx : public CListBox
  798. {
  799. protected:
  800. int m_lfHeight;
  801. protected:
  802. const CListBoxExResources* m_pResources;
  803. //
  804. // Construction
  805. //
  806. public:
  807. CListBoxEx();
  808. void AttachResources(const CListBoxExResources* );
  809. //
  810. // Attributes
  811. //
  812. public:
  813. short TextHeight() const
  814. {
  815. return m_lfHeight;
  816. }
  817. //
  818. // Operations
  819. //
  820. public:
  821. BOOL ChangeFont(
  822. CFont*
  823. );
  824. //
  825. // Implementation
  826. //
  827. public:
  828. virtual ~CListBoxEx();
  829. protected:
  830. virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMIS);
  831. virtual void DrawItem(LPDRAWITEMSTRUCT lpDIS);
  832. protected:
  833. //
  834. // must override this to provide drawing of item
  835. //
  836. /* PURE */ virtual void DrawItemEx( CListBoxExDrawStruct& ) = 0;
  837. //
  838. // Helper function to display text in a limited rectangle
  839. //
  840. static BOOL ColumnText(CDC * pDC, int left, int top, int right, int bottom, const CString & str);
  841. private:
  842. void CalculateTextHeight(CFont*);
  843. protected:
  844. //{{AFX_MSG(CListBoxEx)
  845. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  846. //}}AFX_MSG
  847. DECLARE_MESSAGE_MAP()
  848. DECLARE_DYNAMIC(CListBoxEx)
  849. };
  850. /****************************************************************************
  851. METAL.H
  852. ****************************************************************************/
  853. class CMetalString : public CButton
  854. {
  855. public:
  856. CMetalString()
  857. {
  858. }
  859. protected:
  860. afx_msg void OnPaint();
  861. DECLARE_MESSAGE_MAP()
  862. };
  863. /****************************************************************************
  864. SPINCTRL.H
  865. ****************************************************************************/
  866. class CSpinBox; // Forward decleration;
  867. class CSpinButton : public CButton
  868. {
  869. public:
  870. CSpinButton();
  871. //
  872. // Associate with parent spinner control
  873. //
  874. void Associate(
  875. CSpinBox * pParent
  876. )
  877. {
  878. m_pParent = pParent;
  879. }
  880. //
  881. // Implementation
  882. //
  883. protected:
  884. void NotifyParent();
  885. void Paint(LPDRAWITEMSTRUCT lpDIS);
  886. virtual void DrawItem(LPDRAWITEMSTRUCT lpDIS);
  887. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  888. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  889. afx_msg void OnTimer(UINT nIDEvent);
  890. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  891. DECLARE_MESSAGE_MAP()
  892. private:
  893. typedef enum tagArrowDirection
  894. {
  895. enumArrowUp,
  896. enumArrowDown
  897. } ARROWDIRECTION;
  898. ARROWDIRECTION m_ArrowType;
  899. CSpinBox * m_pParent; // Point back to the edit associated edit box
  900. BOOL m_fButton;
  901. BOOL m_fRealButton;
  902. CRect m_rcUp;
  903. CRect m_rcDown;
  904. UINT m_uScroll;
  905. UINT m_uTimer;
  906. BOOL m_fKeyDown;
  907. };
  908. class CSpinBox : public CEdit
  909. {
  910. public:
  911. typedef enum tagEDITTYPE
  912. {
  913. enumNormal, // Perform no modification at all
  914. enumSeconds, // Value represents the number of seconds
  915. enumMinutes, // Value is in minutes.
  916. enumMinutesHigh, // Value is in minutes, which is the highest unit
  917. enumHours, // Value is in hours
  918. enumHoursHigh, // Value is in hours, which is the highest unit
  919. enumDays, // Value in in days
  920. enumDaysHigh, // Value is in days, which is the highest unit
  921. } EDITTYPE;
  922. public:
  923. CSpinBox(
  924. int nMin,
  925. int nMax,
  926. int nButtonId,
  927. EDITTYPE nType = enumNormal,
  928. BOOL fLeadingZero = FALSE
  929. );
  930. BOOL SubclassDlgItem(UINT nID, CWnd *pParent);
  931. BOOL EnableWindow(BOOL bEnable = TRUE);
  932. public:
  933. void OnScrollUp();
  934. void OnScrollDown();
  935. void SetValue(int nValue);
  936. BOOL GetValue(int &nValue);
  937. // Implementation
  938. protected:
  939. virtual void OnBadInput();
  940. void IncreaseContent(int nDelta);
  941. afx_msg void OnChar(UINT, UINT, UINT); // for character validation
  942. DECLARE_MESSAGE_MAP()
  943. protected:
  944. int m_nButtonId;
  945. int m_nMin;
  946. int m_nMax;
  947. EDITTYPE m_etType;
  948. BOOL m_fLeadingZero;
  949. CSpinButton m_button_Spin; // Associated scroll bar
  950. };
  951. /////////////////////////////////////////////////////////////////////////////
  952. #endif // _COMMON_H_