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.

416 lines
13 KiB

  1. /****************************************************************************
  2. *
  3. * Win32.h
  4. *
  5. * Windows 16/32 porting helper file
  6. *
  7. *
  8. ***************************************************************************/
  9. /**************************************************************************
  10. *
  11. * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  12. * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  14. * PURPOSE.
  15. *
  16. * Copyright (c) 1992 - 1995 Microsoft Corporation. All Rights Reserved.
  17. *
  18. **************************************************************************/
  19. #ifndef INC_OLE2
  20. #define INC_OLE2
  21. #endif
  22. #ifndef INC_WIN32_H
  23. #define INC_WIN32_H // Protect against double inclusion of this file
  24. #if !defined(WIN32) && defined(_WIN32)
  25. #define WIN32
  26. #endif
  27. #if !defined(DEBUG) && defined(_DEBUG)
  28. #define DEBUG
  29. #endif
  30. #ifdef WIN32
  31. // Set up a single define to allow CHICAGO or NT (Daytona)
  32. // N.B. We CANNOT use WINVER <= 0x400 to determine if this is Chicago
  33. // or Daytona. Parts of the Daytona code use Common Controls. For this
  34. // to work WINVER is defined as 0x0400...
  35. // On the other hand, no Chicago code is compiled with UNICODE defined.
  36. #ifdef UNICODE
  37. #define DAYTONA
  38. #undef CHICAGO
  39. #else
  40. #ifndef CHICAGO
  41. #define CHICAGO
  42. #endif
  43. #undef DAYTONA
  44. #endif // UNICODE
  45. #ifndef RC_INVOKED
  46. #pragma warning(disable:4103)
  47. #endif
  48. #define _INC_OLE
  49. #else // 16 bit compilation - must be Chicago
  50. #ifndef CHICAGO
  51. #define CHICAGO
  52. #endif
  53. #endif // WIN32
  54. #if !defined(_INC_WINDOWS) || !defined(_WINDOWS)
  55. #include <windows.h>
  56. #include <windowsx.h>
  57. #if WINVER >= 0x400
  58. #include <winerror.h>
  59. #endif
  60. #include <mmsystem.h>
  61. #endif // INC_WINDOWS...
  62. #ifndef EXTERN_C
  63. #ifdef __cplusplus
  64. #define EXTERN_C extern "C"
  65. #else
  66. #define EXTERN_C extern
  67. #endif
  68. #endif
  69. // Not just for Daytona, things like mciavi define WINVER=0x30a
  70. #ifndef WS_EX_RIGHT
  71. #define WS_EX_RIGHT 0x00001000L // ;Internal 4.0
  72. #define WS_EX_LEFT 0x00000000L // ;Internal 4.0
  73. #define WS_EX_RTLREADING 0x00002000L // ;Internal 4.0
  74. #define WS_EX_LTRREADING 0x00000000L // ;Internal 4.0
  75. #define WS_EX_LEFTSCROLLBAR 0x00004000L // ;Internal 4.0
  76. #define WS_EX_RIGHTSCROLLBAR 0x00000000L // ;Internal 4.0
  77. #endif
  78. // Win 16 and Win 32 use different macros to turn code debugging on/off
  79. // Map the 16 bit version to the NT conventions.
  80. // In particular on NT, debug builds are identified by DBG==1 (and retail
  81. // with DBG==0), hence the NT only source uses #if DBG. Note: #ifdef DBG
  82. // is ALWAYS true on NT.
  83. // Chicago (and VFW 16 bit code) uses #ifdef DEBUG. The complex of
  84. // instructions below should ensure that whether this is Chicago or NT that
  85. // a debug build implies DEBUG defined and DBG==1
  86. // a retail build implies DEBUG NOT defined, and DBG==0
  87. #ifdef WIN32
  88. #ifndef DBG
  89. #ifdef DEBUG
  90. #define DBG 1
  91. #else
  92. #define DBG 0
  93. #endif
  94. #endif
  95. #undef DEBUG
  96. #if DBG
  97. #define DEBUG
  98. #define STATICFN
  99. #define STATICDT
  100. #else
  101. #define STATICFN static
  102. #define STATICDT static
  103. #endif
  104. #else // !WIN32
  105. #define STATICFN static
  106. #define STATICDT static
  107. #endif //WIN32
  108. #if !defined FASTCALL
  109. #define FASTCALL __fastcall
  110. #endif
  111. #if !defined _FASTCALL
  112. #define _FASTCALL __fastcall
  113. #endif
  114. #if !defined NUMELMS
  115. #define NUMELMS(aa) (sizeof(aa)/sizeof((aa)[0]))
  116. #endif
  117. #ifdef WIN32
  118. /* --- Win32 version --------------------------------------------------- */
  119. #include <string.h>
  120. #include <memory.h>
  121. #undef CDECL
  122. #if defined(_MIPS_) || defined(_PPC_)
  123. #define __stdcall
  124. #define _stdcall
  125. #define _cdecl
  126. #define __cdecl
  127. #define CDECL
  128. #else
  129. #define CDECL _cdecl
  130. #endif
  131. //typedef BITMAPINFOHEADER FAR *LPBITMAPINFOHEADER;
  132. #define far
  133. #define _far
  134. #define __far
  135. #define HUGE_T
  136. #undef HUGE
  137. #define HUGE
  138. #define huge
  139. #define _huge
  140. #define __huge
  141. #define near
  142. #define _near
  143. #define __near
  144. #define _fastcall
  145. #define __fastcall
  146. #define _loadds
  147. #define __loadds
  148. #define _LOADDS
  149. #define LOADDS
  150. #define _export //should _export be blank?
  151. #define __export
  152. #define EXPORT
  153. #define _based(x)
  154. #define __based(x)
  155. #define _based32(x)
  156. #define __based32(x)
  157. #ifdef _X86_
  158. // __inline provides speed improvements for x86 platforms. Unfortunately
  159. // the MIPS compiler does not have inline support. Alpha is unknown, so
  160. // we do not assume and play it safe.
  161. #define INLINE __inline
  162. #define inline __inline
  163. #define _inline __inline
  164. #else
  165. #define INLINE
  166. #define inline
  167. #define _inline
  168. #define __inline
  169. #endif
  170. //typedef RGBQUAD FAR *LPRGBQUAD;
  171. //#ifdef DAYTONA
  172. //typedef LRESULT (*DRIVERPROC)(DWORD, HDRVR, UINT, WPARAM, LPARAM);
  173. //#endif
  174. // DriverProc is in the common win 32 sdk mmsystem.h.
  175. #define GetCurrentTask() (HTASK)LongToHandle(GetCurrentThreadId())
  176. #define WF_PMODE 0x0001
  177. #define WF_CPU286 0x0002
  178. #define WF_CPU386 0x0004
  179. #define WF_CPU486 0x0008
  180. #define WF_80x87 0x0400
  181. #define WF_PAGING 0x0800
  182. #define GetWinFlags() (WF_PMODE|WF_CPU486|WF_PAGING|WF_80x87)
  183. //#define hmemcpy memcpy
  184. #define _fmemcpy memcpy
  185. #define _fmemset memset
  186. //#define lstrcpyn(dest, source, cb) ( strncpy(dest, source, cb), ((char *) dest) [cb - 1] = 0)
  187. //!!! should use LARGE_INTEGER stuff.
  188. #define muldiv32 MulDiv
  189. #define muldivru32(a,b,c) (long)(((double)(a) * (double)(b) + (double)((c)-1)) / (double)(c))
  190. #define muldivrd32(a,b,c) (long)(((double)(a) * (double)(b)) / (double)(c))
  191. #define IsTask(x) ((x) != 0)
  192. #define IsGDIObject(obj) (GetObjectType((HGDIOBJ)(obj)) != 0)
  193. #define SZCODEA CHAR
  194. #define SZCODE TCHAR
  195. typedef TCHAR * NPTSTR;
  196. #ifndef UNICODE
  197. // !!!!!!! need lstrcpyW, lstrlenW, wsprintfW, lstrcpynW for Chicago!
  198. #endif
  199. #else
  200. /* --- Win16 version --------------------------------------------------- */
  201. #include <string.h>
  202. #include <memory.h>
  203. #define SZCODEA SZCODE
  204. typedef char TCHAR;
  205. typedef WORD WCHAR;
  206. typedef NPSTR NPTSTR;
  207. typedef LPSTR LPTSTR;
  208. typedef LPSTR LPOLESTR;
  209. typedef LPCSTR LPCOLESTR;
  210. typedef char OLECHAR;
  211. typedef int INT;
  212. #define _LOADDS _loadds
  213. #define LOADDS _loadds
  214. #define EXPORT _export
  215. #define HUGE _huge
  216. #define DRIVERS_SECTION "Drivers"
  217. #define MCI_SECTION "MCI"
  218. #define MCIAVI_SECTION "MCIAVI"
  219. #define TEXT(sz) sz
  220. // stuff in muldiv32.asm
  221. EXTERN_C LONG FAR PASCAL muldiv32(LONG,LONG,LONG);
  222. EXTERN_C LONG FAR PASCAL muldivru32(LONG,LONG,LONG);
  223. EXTERN_C LONG FAR PASCAL muldivrd32(LONG,LONG,LONG);
  224. #define UNALIGNED
  225. #define INLINE __inline
  226. #define CharPrev AnsiPrev
  227. /*
  228. * define these so we can explicitly use Ansi or Unicode versions
  229. * in the NT code, and the standard entry point for Win16.
  230. */
  231. #define SetWindowTextA SetWindowText
  232. #define GetProfileStringA GetProfileString
  233. #define GetPrivateProfileStringA GetPrivateProfileString
  234. #define GetProfileIntA GetProfileInt
  235. #define GetModuleHandleA GetModuleHandle
  236. #define GetModuleFileNameA GetModuleFileName
  237. #define wvsprintfA wvsprintf
  238. #define wsprintfA wsprintf
  239. #define lstrcmpA lstrcmp
  240. #define lstrcmpiA lstrcmpi
  241. #define lstrcpyA lstrcpy
  242. #define lstrcatA lstrcat
  243. #define lstrlenA lstrlen
  244. #define LoadStringA LoadString
  245. #define LoadStringW LoadString
  246. #define OutputDebugStringA OutputDebugString
  247. #define MessageBoxA MessageBox
  248. // Needed for writing OLE-style code that builds 16/32....
  249. #define lstrcpyW lstrcpy
  250. #define lstrcpynW lstrcpyn
  251. #define lstrlenW lstrlen
  252. #define SZCODE char _based(_segname("_CODE"))
  253. #define LPCWSTR LPCSTR
  254. #define LPCTSTR LPCSTR
  255. #define LPWSTR LPSTR
  256. #define PTSTR PSTR
  257. /****** Alternate porting layer macros ****************************************/
  258. #ifndef GET_WPARAM
  259. /* USER MESSAGES: */
  260. #define GET_WPARAM(wp, lp) (wp)
  261. #define GET_LPARAM(wp, lp) (lp)
  262. #define GET_WM_ACTIVATE_STATE(wp, lp) (wp)
  263. #define GET_WM_ACTIVATE_FMINIMIZED(wp, lp) (BOOL)HIWORD(lp)
  264. #define GET_WM_ACTIVATE_HWND(wp, lp) (HWND)LOWORD(lp)
  265. #define GET_WM_ACTIVATE_MPS(s, fmin, hwnd) \
  266. (WPARAM)(s), MAKELONG(hwnd, fmin)
  267. #define GET_WM_CHARTOITEM_CHAR(wp, lp) (CHAR)(wp)
  268. #define GET_WM_CHARTOITEM_POS(wp, lp) HIWORD(lp)
  269. #define GET_WM_CHARTOITEM_HWND(wp, lp) (HWND)LOWORD(lp)
  270. #define GET_WM_CHARTOITEM_MPS(ch, pos, hwnd) \
  271. (WPARAM)(ch), MAKELONG(hwnd, pos)
  272. #define GET_WM_COMMAND_ID(wp, lp) (wp)
  273. #define GET_WM_COMMAND_HWND(wp, lp) (HWND)LOWORD(lp)
  274. #define GET_WM_COMMAND_CMD(wp, lp) HIWORD(lp)
  275. #define GET_WM_COMMAND_MPS(id, hwnd, cmd) \
  276. (WPARAM)(id), MAKELONG(hwnd, cmd)
  277. #define WM_CTLCOLORMSGBOX 0x0132
  278. #define WM_CTLCOLOREDIT 0x0133
  279. #define WM_CTLCOLORLISTBOX 0x0134
  280. #define WM_CTLCOLORBTN 0x0135
  281. #define WM_CTLCOLORDLG 0x0136
  282. #define WM_CTLCOLORSCROLLBAR 0x0137
  283. #define WM_CTLCOLORSTATIC 0x0138
  284. #define GET_WM_CTLCOLOR_HDC(wp, lp, msg) (HDC)(wp)
  285. #define GET_WM_CTLCOLOR_HWND(wp, lp, msg) (HWND)LOWORD(lp)
  286. #define GET_WM_CTLCOLOR_TYPE(wp, lp, msg) HIWORD(lp)
  287. #define GET_WM_CTLCOLOR_MPS(hdc, hwnd, type) \
  288. (WPARAM)(hdc), MAKELONG(hwnd, type)
  289. #define GET_WM_MENUSELECT_CMD(wp, lp) (wp)
  290. #define GET_WM_MENUSELECT_FLAGS(wp, lp) LOWORD(lp)
  291. #define GET_WM_MENUSELECT_HMENU(wp, lp) (HMENU)HIWORD(lp)
  292. #define GET_WM_MENUSELECT_MPS(cmd, f, hmenu) \
  293. (WPARAM)(cmd), MAKELONG(f, hmenu)
  294. // Note: the following are for interpreting MDIclient to MDI child messages.
  295. #define GET_WM_MDIACTIVATE_FACTIVATE(hwnd, wp, lp) (BOOL)(wp)
  296. #define GET_WM_MDIACTIVATE_HWNDDEACT(wp, lp) (HWND)HIWORD(lp)
  297. #define GET_WM_MDIACTIVATE_HWNDACTIVATE(wp, lp) (HWND)LOWORD(lp)
  298. // Note: the following is for sending to the MDI client window.
  299. #define GET_WM_MDIACTIVATE_MPS(f, hwndD, hwndA)\
  300. (WPARAM)(hwndA), 0
  301. #define GET_WM_MDISETMENU_MPS(hmenuF, hmenuW) 0, MAKELONG(hmenuF, hmenuW)
  302. #define GET_WM_MENUCHAR_CHAR(wp, lp) (CHAR)(wp)
  303. #define GET_WM_MENUCHAR_HMENU(wp, lp) (HMENU)LOWORD(lp)
  304. #define GET_WM_MENUCHAR_FMENU(wp, lp) (BOOL)HIWORD(lp)
  305. #define GET_WM_MENUCHAR_MPS(ch, hmenu, f) \
  306. (WPARAM)(ch), MAKELONG(hmenu, f)
  307. #define GET_WM_PARENTNOTIFY_MSG(wp, lp) (wp)
  308. #define GET_WM_PARENTNOTIFY_ID(wp, lp) HIWORD(lp)
  309. #define GET_WM_PARENTNOTIFY_HWNDCHILD(wp, lp) (HWND)LOWORD(lp)
  310. #define GET_WM_PARENTNOTIFY_X(wp, lp) (INT)LOWORD(lp)
  311. #define GET_WM_PARENTNOTIFY_Y(wp, lp) (INT)HIWORD(lp)
  312. #define GET_WM_PARENTNOTIFY_MPS(msg, id, hwnd) \
  313. (WPARAM)(msg), MAKELONG(hwnd, id)
  314. #define GET_WM_PARENTNOTIFY2_MPS(msg, x, y) \
  315. (WPARAM)(msg), MAKELONG(x, y)
  316. #define GET_WM_VKEYTOITEM_CODE(wp, lp) (wp)
  317. #define GET_WM_VKEYTOITEM_ITEM(wp, lp) (INT)HIWORD(lp)
  318. #define GET_WM_VKEYTOITEM_HWND(wp, lp) (HWND)LOWORD(lp)
  319. #define GET_WM_VKEYTOITEM_MPS(code, item, hwnd) \
  320. (WPARAM)(code), MAKELONG(hwnd, item)
  321. #define GET_EM_SETSEL_START(wp, lp) LOWORD(lp)
  322. #define GET_EM_SETSEL_END(wp, lp) HIWORD(lp)
  323. #define GET_EM_SETSEL_MPS(iStart, iEnd) \
  324. 0, MAKELONG(iStart, iEnd)
  325. #define GET_EM_LINESCROLL_MPS(vert, horz) \
  326. 0, MAKELONG(vert, horz)
  327. #define GET_WM_CHANGECBCHAIN_HWNDNEXT(wp, lp) (HWND)LOWORD(lp)
  328. #define GET_WM_HSCROLL_CODE(wp, lp) (wp)
  329. #define GET_WM_HSCROLL_POS(wp, lp) LOWORD(lp)
  330. #define GET_WM_HSCROLL_HWND(wp, lp) (HWND)HIWORD(lp)
  331. #define GET_WM_HSCROLL_MPS(code, pos, hwnd) \
  332. (WPARAM)(code), MAKELONG(pos, hwnd)
  333. #define GET_WM_VSCROLL_CODE(wp, lp) (wp)
  334. #define GET_WM_VSCROLL_POS(wp, lp) LOWORD(lp)
  335. #define GET_WM_VSCROLL_HWND(wp, lp) (HWND)HIWORD(lp)
  336. #define GET_WM_VSCROLL_MPS(code, pos, hwnd) \
  337. (WPARAM)(code), MAKELONG(pos, hwnd)
  338. #endif // !GET_WPARAM
  339. #endif // !WIN32
  340. #endif