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.

182 lines
6.6 KiB

  1. //
  2. // comm.h: Declares data, defines and struct types for common code
  3. // module.
  4. //
  5. //
  6. #ifndef __COMM_H__
  7. #define __COMM_H__
  8. ///////////////////////////////////////////////////// DEFINES
  9. #define BLOCK
  10. #define Unref(x) x
  11. #ifdef DEBUG
  12. #define INLINE
  13. #define DEBUG_CODE(x) x
  14. #else
  15. #define INLINE __inline
  16. #define DEBUG_CODE(x)
  17. #endif
  18. #define CbFromCch(cch) ((cch)*sizeof(TCHAR))
  19. #define CCH_NUL (sizeof(TCHAR))
  20. ///////////////////////////////////////////////////// MACROS
  21. // Zero-initialize data-item
  22. //
  23. #define ZeroInit(pobj, type) lmemset((CHAR *)pobj, 0, sizeof(type))
  24. // Copy chunk of memory
  25. //
  26. #define BltByte(pdest, psrc, cb) lmemmove((CHAR *)pdest, (CHAR *)psrc, cb)
  27. // General flag macros
  28. //
  29. #define SetFlag(obj, f) do {obj |= (f);} while (0)
  30. #define ToggleFlag(obj, f) do {obj ^= (f);} while (0)
  31. #define ClearFlag(obj, f) do {obj &= ~(f);} while (0)
  32. #define IsFlagSet(obj, f) (BOOL)(((obj) & (f)) == (f))
  33. #define IsFlagClear(obj, f) (BOOL)(((obj) & (f)) != (f))
  34. #define InRange(id, idFirst, idLast) ((UINT)(id-idFirst) <= (UINT)(idLast-idFirst))
  35. //
  36. // Non-shared memory allocation
  37. //
  38. // void * GAlloc(DWORD cbBytes)
  39. // Alloc a chunk of memory, quickly, with no 64k limit on size of
  40. // individual objects or total object size. Initialize to zero.
  41. //
  42. #define GAlloc(cbBytes) GlobalAlloc(GPTR, cbBytes)
  43. // void * GReAlloc(void * pv, DWORD cbNewSize)
  44. // Realloc one of above. If pv is NULL, then this function will do
  45. // an alloc for you. Initializes new portion to zero.
  46. //
  47. #define GReAlloc(pv, cbNewSize) GlobalReAlloc(pv, cbNewSize, GMEM_MOVEABLE | GMEM_ZEROINIT)
  48. // void GFree(void *pv)
  49. // Free pv if it is nonzero. Set pv to zero.
  50. //
  51. #define GFree(pv) do { (pv) ? GlobalFree(pv) : (void)0; pv = NULL; } while (0)
  52. // DWORD GGetSize(void *pv)
  53. // Get the size of a block allocated by Alloc()
  54. //
  55. #define GGetSize(pv) GlobalSize(pv)
  56. // type * GAllocType(type); (macro)
  57. // Alloc some memory the size of <type> and return pointer to <type>.
  58. //
  59. #define GAllocType(type) (type *)GAlloc(sizeof(type))
  60. // type * GAllocArray(type, int cNum); (macro)
  61. // Alloc an array of data the size of <type>.
  62. //
  63. #define GAllocArray(type, cNum) (type *)GAlloc(sizeof(type) * (cNum))
  64. // type * GReAllocArray(type, void * pb, int cNum);
  65. //
  66. #define GReAllocArray(type, pb, cNum) (type *)GReAlloc(pb, sizeof(type) * (cNum))
  67. // Copies psz into *ppszBuf and (re)allocates *ppszBuf accordingly
  68. BOOL PUBLIC GSetString(LPTSTR * ppszBuf, LPCTSTR psz);
  69. // Concatenates psz onto *ppszBuf and (re)allocates *ppszBuf accordingly
  70. BOOL PUBLIC GCatString(LPTSTR * ppszBuf, LPCTSTR psz);
  71. // FileInfo struct that contains file time/size info
  72. //
  73. typedef struct _FileInfo
  74. {
  75. HICON hicon;
  76. FILETIME ftMod;
  77. DWORD dwSize; // size of the file
  78. DWORD dwAttributes; // attributes
  79. LPARAM lParam;
  80. LPTSTR pszDisplayName; // points to the display name
  81. TCHAR szPath[1];
  82. } FileInfo;
  83. #define FIGetSize(pfi) ((pfi)->dwSize)
  84. #define FIGetPath(pfi) ((pfi)->szPath)
  85. #define FIGetDisplayName(pfi) ((pfi)->pszDisplayName)
  86. #define FIGetAttributes(pfi) ((pfi)->dwAttributes)
  87. #define FIIsFolder(pfi) (IsFlagSet((pfi)->dwAttributes, SFGAO_FOLDER))
  88. // Flags for FICreate
  89. #define FIF_DEFAULT 0x0000
  90. #define FIF_ICON 0x0001
  91. #define FIF_DONTTOUCH 0x0002
  92. #define FIF_FOLDER 0x0004
  93. HRESULT PUBLIC FICreate(LPCTSTR pszPath, FileInfo ** ppfi, UINT uFlags);
  94. BOOL PUBLIC FISetPath(FileInfo ** ppfi, LPCTSTR pszPathNew, UINT uFlags);
  95. BOOL PUBLIC FIGetInfoString(FileInfo * pfi, LPTSTR pszBuf, int cchBuf);
  96. void PUBLIC FIFree(FileInfo * pfi);
  97. void PUBLIC FileTimeToDateTimeString(LPFILETIME pft, LPTSTR pszBuf, int cchBuf);
  98. // Color macros
  99. //
  100. #define ColorText(nState) (((nState) & ODS_SELECTED) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT)
  101. #define ColorBk(nState) (((nState) & ODS_SELECTED) ? COLOR_HIGHLIGHT : COLOR_WINDOW)
  102. #define ColorMenuText(nState) (((nState) & ODS_SELECTED) ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT)
  103. #define ColorMenuBk(nState) (((nState) & ODS_SELECTED) ? COLOR_HIGHLIGHT : COLOR_MENU)
  104. #define GetImageDrawStyle(nState) (((nState) & ODS_SELECTED) ? ILD_SELECTED : ILD_NORMAL)
  105. // Sets the dialog handle in the given data struct on first
  106. // message that the dialog gets (WM_SETFONT).
  107. //
  108. #define SetDlgHandle(hwnd, msg, lp) if((msg)==WM_SETFONT) (lp)->hdlg=(hwnd);
  109. #define DECLAREHOURGLASS HCURSOR hcurSavHourglass
  110. #define SetHourglass() hcurSavHourglass = SetCursor(LoadCursor(NULL, IDC_WAIT))
  111. #define ResetHourglass() SetCursor(hcurSavHourglass)
  112. // UNICODE WARNING: These must stay as CHARS for the math to be right
  113. CHAR * PUBLIC lmemset(CHAR * dst, CHAR val, UINT count);
  114. CHAR * PUBLIC lmemmove(CHAR * dst, CHAR * src, int count);
  115. int PUBLIC AnsiToInt(LPCTSTR pszString);
  116. INT_PTR PUBLIC DoModal (HWND hwndParent, DLGPROC lpfnDlgProc, UINT uID, LPARAM lParam);
  117. VOID PUBLIC SetRectFromExtent(HDC hdc, LPRECT lprc, LPCTSTR lpcsz);
  118. // Flags for MyDrawText()
  119. #define MDT_DRAWTEXT 0x00000001
  120. #define MDT_ELLIPSES 0x00000002
  121. #define MDT_LINK 0x00000004
  122. #define MDT_SELECTED 0x00000008
  123. #define MDT_DESELECTED 0x00000010
  124. #define MDT_DEPRESSED 0x00000020
  125. #define MDT_EXTRAMARGIN 0x00000040
  126. #define MDT_TRANSPARENT 0x00000080
  127. #define MDT_LEFT 0x00000100
  128. #define MDT_RIGHT 0x00000200
  129. #define MDT_CENTER 0x00000400
  130. #define MDT_VCENTER 0x00000800
  131. #define MDT_CLIPPED 0x00001000
  132. void PUBLIC MyDrawText(HDC hdc, LPCTSTR pszText, RECT * prc, UINT flags, int cyChar, int cxEllipses, COLORREF clrText, COLORREF clrTextBk);
  133. DWORD PUBLIC MsgWaitObjectsSendMessage(DWORD cObjects, LPHANDLE phObjects, DWORD dwTimeout);
  134. HCURSOR PUBLIC SetCursorRemoveWigglies(HCURSOR hcur);
  135. LPTSTR PUBLIC _ConstructMessageString(HINSTANCE hinst, LPCTSTR pszMsg, va_list *ArgList);
  136. BOOL PUBLIC ConstructMessage(LPTSTR * ppsz, HINSTANCE hinst, LPCTSTR pszMsg, ...);
  137. #endif // __COMM_H__