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.

603 lines
21 KiB

  1. #ifndef __PWIN32_H__
  2. #define __PWIN32_H__
  3. #if _MSC_VER > 1000
  4. #pragma once
  5. #endif
  6. #include <dde.h>
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif // __cplusplus
  10. /*****************************************************************************\
  11. * Copyright (C) Microsoft Corporation, 1990-1999
  12. * PWIN32.H - PORTABILITY MAPPING HEADER FILE
  13. *
  14. * This file provides macros to map portable windows code to its 32 bit form.
  15. \*****************************************************************************/
  16. /*-----------------------------------USER------------------------------------*/
  17. /* HELPER MACROS */
  18. #define MAPVALUE(v16, v32) (v32)
  19. #define MAPTYPE(v16, v32) v32
  20. #define MAKEMPOINT(l) (*((MPOINT *)&(l)))
  21. #define MPOINT2POINT(mpt,pt) ((pt).x = (mpt).x, (pt).y = (mpt).y)
  22. #define POINT2MPOINT(pt, mpt) ((mpt).x = (SHORT)(pt).x, (mpt).y = (SHORT)(pt).y)
  23. #define LONG2POINT(l, pt) ((pt).x = (SHORT)LOWORD(l), (pt).y = (SHORT)HIWORD(l))
  24. #define SETWINDOWUINT(hwnd, index, ui) (UINT)SetWindowLong(hwnd, index, (LONG)(ui))
  25. #define GETWINDOWUINT(hwnd, index) (UINT)GetWindowLong(hwnd, index)
  26. #define SETCLASSUINT(hwnd, index, ui) (UINT)SetClassLong(hwnd, index, (LONG)(ui))
  27. #define GETCLASSUINT(hwnd, index) (UINT)GetClassLong(hwnd, index)
  28. #define GETCBCLSEXTRA(hwnd) GETCLASSUINT(hwnd, GCL_CBCLSEXTRA)
  29. #define SETCBCLSEXTRA(hwnd, cb) SETCLASSUINT(hwnd, GCL_CBCLSEXTRA, cb)
  30. #define GETCBWNDEXTRA(hwnd) GETCLASSUINT(hwnd, GCL_CBWNDEXTRA)
  31. #define SETCBWNDEXTRA(hwnd, cb) SETCLASSUINT(hwnd, GCL_CBWNDEXTRA, cb)
  32. #define GETCLASSBRBACKGROUND(hwnd) (HBRUSH)GetClassLongPtr((hwnd), GCLP_HBRBACKGROUND)
  33. #define SETCLASSBRBACKGROUND(hwnd, h) (HBRUSH)SetClassLongPtr((hwnd), GCLP_HBRBACKGROUND, (LONG_PTR)(h))
  34. #define GETCLASSCURSOR(hwnd) (HCURSOR)GetClassLongPtr((hwnd), GCLP_HCURSOR)
  35. #define SETCLASSCURSOR(hwnd, h) (HCURSOR)SetClassLongPtr((hwnd), GCLP_HCURSOR, (LONG_PTR)(h))
  36. #define GETCLASSHMODULE(hwnd) (HMODULE)GetClassLongPtr((hwnd), GCLP_HMODULE)
  37. #define SETCLASSHMODULE(hwnd, h) (HMODULE)SetClassLongPtr((hwnd), GCLP_HMODULE, (LONG_PTR)(h))
  38. #define GETCLASSICON(hwnd) (HICON)GetClassLongPtr((hwnd), GCLP_HICON)
  39. #define SETCLASSICON(hwnd, h) (HICON)SetClassLongPtr((hwnd), GCLP_HICON, (LONG_PTR)(h))
  40. #define GETCLASSSTYLE(hwnd) GETCLASSUINT((hwnd), GCL_STYLE)
  41. #define SETCLASSSTYLE(hwnd, style) SETCLASSUINT((hwnd), GCL_STYLE, style)
  42. #define GETHWNDINSTANCE(hwnd) (HINSTANCE)GetWindowLongPtr((hwnd), GWLP_HINSTANCE)
  43. #define SETHWNDINSTANCE(hwnd, h) (HINSTANCE)SetWindowLongPtr((hwnd), GWLP_HINSTANCE, (LONG_PTR)(h))
  44. #define GETHWNDPARENT(hwnd) (HWND)GetWindowLongPtr((hwnd), GWLP_HWNDPARENT)
  45. #define SETHWNDPARENT(hwnd, h) (HWND)SetWindowLongPtr((hwnd), GWLP_HWNDPARENT, (LONG_PTR)(h))
  46. #define GETWINDOWID(hwnd) GETWINDOWUINT((hwnd), GWL_ID)
  47. #define SETWINDOWID(hwnd, id) SETWINDOWUINT((hwnd), GWL_ID, id)
  48. /* USER API */
  49. #define MDlgDirSelect(hDlg, lpstr, nLength, nIDListBox) \
  50. DlgDirSelectEx(hDlg, lpstr, nLength, nIDListBox)
  51. #define MDlgDirSelectCOMBOBOX(hDlg, lpstr, nLength, nIDComboBox) \
  52. DlgDirSelectComboBoxEx(hDlg, lpstr, nLength, nIDComboBox)
  53. #define MGetLastError GetLastError
  54. #define MMain(hInst, hPrevInst, lpCmdLine, nCmdShow) \
  55. INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, \
  56. INT nCmdShow) { \
  57. INT _argc; \
  58. CHAR **_argv;
  59. __inline LPSTR MGetCmdLine()
  60. {
  61. LPSTR lpCmdLine, lpT;
  62. lpCmdLine = GetCommandLineA();
  63. // on NT, lpCmdLine's first string includes its own name, remove this
  64. // to make it exactly like the windows command line.
  65. if (*lpCmdLine) {
  66. lpT = strchr(lpCmdLine, ' '); // skip self name
  67. if (lpT) {
  68. lpCmdLine = lpT;
  69. while (*lpCmdLine == ' ') {
  70. lpCmdLine++; // skip spaces to end or first cmd
  71. }
  72. } else {
  73. lpCmdLine += strlen(lpCmdLine); // point to NULL
  74. }
  75. }
  76. return(lpCmdLine);
  77. }
  78. __inline DWORD APIENTRY MSendMsgEM_GETSEL(HWND hDlg, WORD2DWORD * piStart, WORD2DWORD * piEnd)
  79. {
  80. DWORD dw;
  81. dw = (DWORD)SendMessage(hDlg, EM_GETSEL, 0, 0);
  82. if (piEnd != NULL)
  83. *piEnd = (WORD2DWORD) HIWORD(dw);
  84. if (piStart != NULL)
  85. *piStart = (WORD2DWORD) LOWORD(dw);
  86. return(dw);
  87. }
  88. /* USER MESSAGES: */
  89. #define GET_WPARAM(wp, lp) (wp)
  90. #define GET_LPARAM(wp, lp) (lp)
  91. #define GET_WM_ACTIVATE_STATE(wp, lp) LOWORD(wp)
  92. #define GET_WM_ACTIVATE_FMINIMIZED(wp, lp) (BOOL)HIWORD(wp)
  93. #define GET_WM_ACTIVATE_HWND(wp, lp) (HWND)(lp)
  94. #define GET_WM_ACTIVATE_MPS(s, fmin, hwnd) \
  95. (WPARAM)MAKELONG((s), (fmin)), (LPARAM)(hwnd)
  96. #define GET_WM_CHARTOITEM_CHAR(wp, lp) (TCHAR)LOWORD(wp)
  97. #define GET_WM_CHARTOITEM_POS(wp, lp) HIWORD(wp)
  98. #define GET_WM_CHARTOITEM_HWND(wp, lp) (HWND)(lp)
  99. #define GET_WM_CHARTOITEM_MPS(ch, pos, hwnd) \
  100. (WPARAM)MAKELONG((pos), (ch)), (LPARAM)(hwnd)
  101. #define GET_WM_COMMAND_ID(wp, lp) LOWORD(wp)
  102. #define GET_WM_COMMAND_HWND(wp, lp) (HWND)(lp)
  103. #define GET_WM_COMMAND_CMD(wp, lp) HIWORD(wp)
  104. #define GET_WM_COMMAND_MPS(id, hwnd, cmd) \
  105. (WPARAM)MAKELONG(id, cmd), (LPARAM)(hwnd)
  106. #define WM_CTLCOLOR 0x0019
  107. #define GET_WM_CTLCOLOR_HDC(wp, lp, msg) (HDC)(wp)
  108. #define GET_WM_CTLCOLOR_HWND(wp, lp, msg) (HWND)(lp)
  109. #define GET_WM_CTLCOLOR_TYPE(wp, lp, msg) (WORD)(msg - WM_CTLCOLORMSGBOX)
  110. #define GET_WM_CTLCOLOR_MSG(type) (WORD)(WM_CTLCOLORMSGBOX+(type))
  111. #define GET_WM_CTLCOLOR_MPS(hdc, hwnd, type) \
  112. (WPARAM)(hdc), (LPARAM)(hwnd)
  113. #define GET_WM_MENUSELECT_CMD(wp, lp) LOWORD(wp)
  114. #define GET_WM_MENUSELECT_FLAGS(wp, lp) (UINT)(int)(short)HIWORD(wp)
  115. #define GET_WM_MENUSELECT_HMENU(wp, lp) (HMENU)(lp)
  116. #define GET_WM_MENUSELECT_MPS(cmd, f, hmenu) \
  117. (WPARAM)MAKELONG(cmd, f), (LPARAM)(hmenu)
  118. // Note: the following are for interpreting MDIclient to MDI child messages.
  119. #define GET_WM_MDIACTIVATE_FACTIVATE(hwnd, wp, lp) (lp == (LPARAM)hwnd)
  120. #define GET_WM_MDIACTIVATE_HWNDDEACT(wp, lp) (HWND)(wp)
  121. #define GET_WM_MDIACTIVATE_HWNDACTIVATE(wp, lp) (HWND)(lp)
  122. // Note: the following is for sending to the MDI client window.
  123. #define GET_WM_MDIACTIVATE_MPS(f, hwndD, hwndA)\
  124. (WPARAM)(hwndA), 0
  125. #define GET_WM_MDISETMENU_MPS(hmenuF, hmenuW) (WPARAM)hmenuF, (LPARAM)hmenuW
  126. #define GET_WM_MENUCHAR_CHAR(wp, lp) (TCHAR)LOWORD(wp)
  127. #define GET_WM_MENUCHAR_HMENU(wp, lp) (HMENU)(lp)
  128. #define GET_WM_MENUCHAR_FMENU(wp, lp) (BOOL)HIWORD(wp)
  129. #define GET_WM_MENUCHAR_MPS(ch, hmenu, f) \
  130. (WPARAM)MAKELONG(ch, f), (LPARAM)(hmenu)
  131. #define GET_WM_PARENTNOTIFY_MSG(wp, lp) LOWORD(wp)
  132. #define GET_WM_PARENTNOTIFY_ID(wp, lp) HIWORD(wp)
  133. #define GET_WM_PARENTNOTIFY_HWNDCHILD(wp, lp) (HWND)(lp)
  134. #define GET_WM_PARENTNOTIFY_X(wp, lp) (INT)LOWORD(lp)
  135. #define GET_WM_PARENTNOTIFY_Y(wp, lp) (INT)HIWORD(lp)
  136. #define GET_WM_PARENTNOTIFY_MPS(msg, id, hwnd) \
  137. (WPARAM)MAKELONG(id, msg), (LPARAM)(hwnd)
  138. #define GET_WM_PARENTNOTIFY2_MPS(msg, x, y) \
  139. (WPARAM)MAKELONG(0, msg), MAKELONG(x, y)
  140. #define GET_WM_VKEYTOITEM_CODE(wp, lp) (INT)LOWORD(wp)
  141. #define GET_WM_VKEYTOITEM_ITEM(wp, lp) HIWORD(wp)
  142. #define GET_WM_VKEYTOITEM_HWND(wp, lp) (HWND)(lp)
  143. #define GET_WM_VKEYTOITEM_MPS(code, item, hwnd) \
  144. (WPARAM)MAKELONG(item, code), (LPARAM)(hwnd)
  145. #define GET_EM_SETSEL_START(wp, lp) (INT)(wp)
  146. #define GET_EM_SETSEL_END(wp, lp) (lp)
  147. #define GET_EM_SETSEL_MPS(iStart, iEnd) \
  148. (WPARAM)(iStart), (LONG)(iEnd)
  149. #define GET_EM_LINESCROLL_MPS(vert, horz) \
  150. (WPARAM)horz, (LONG)vert
  151. #define GET_WM_CHANGECBCHAIN_HWNDNEXT(wp, lp) (HWND)(lp)
  152. #define GET_WM_HSCROLL_CODE(wp, lp) LOWORD(wp)
  153. #define GET_WM_HSCROLL_POS(wp, lp) HIWORD(wp)
  154. #define GET_WM_HSCROLL_HWND(wp, lp) (HWND)(lp)
  155. #define GET_WM_HSCROLL_MPS(code, pos, hwnd) \
  156. (WPARAM)MAKELONG(code, pos), (LPARAM)(hwnd)
  157. #define GET_WM_VSCROLL_CODE(wp, lp) LOWORD(wp)
  158. #define GET_WM_VSCROLL_POS(wp, lp) HIWORD(wp)
  159. #define GET_WM_VSCROLL_HWND(wp, lp) (HWND)(lp)
  160. #define GET_WM_VSCROLL_MPS(code, pos, hwnd) \
  161. (WPARAM)MAKELONG(code, pos), (LPARAM)(hwnd)
  162. /* DDE macros */
  163. __inline UINT_PTR APIENTRY MGetDDElParamLo(UINT msg,LPARAM lParam)
  164. {
  165. UINT_PTR uiLo;
  166. if (UnpackDDElParam(msg, lParam, &uiLo, NULL))
  167. return uiLo;
  168. else
  169. return 0;
  170. }
  171. __inline UINT_PTR APIENTRY MGetDDElParamHi(UINT msg,LPARAM lParam)
  172. {
  173. UINT_PTR uiHi;
  174. if (UnpackDDElParam(msg, lParam, NULL, &uiHi))
  175. return uiHi;
  176. else
  177. return 0;
  178. }
  179. __inline BOOL APIENTRY MPostDDEMsg(HWND hwndTo,UINT msg,HWND hwndFrom,UINT_PTR uiLo,UINT_PTR uiHi)
  180. {
  181. LPARAM lParam;
  182. lParam = PackDDElParam(msg, uiLo, uiHi);
  183. if (lParam) {
  184. if (PostMessage(hwndTo, msg, (WPARAM)hwndFrom, lParam)) {
  185. return(TRUE);
  186. }
  187. FreeDDElParam(msg, lParam);
  188. }
  189. return(FALSE);
  190. }
  191. #define DDEFREE(msg, lp) FreeDDElParam(msg, lp)
  192. #define GET_WM_DDE_ACK_STATUS(wp, lp) ((WORD)MGetDDElParamLo(WM_DDE_ACK, lp))
  193. #define GET_WM_DDE_ACK_ITEM(wp, lp) ((ATOM)MGetDDElParamHi(WM_DDE_ACK, lp))
  194. #define MPostWM_DDE_ACK(hTo, hFrom, wStatus, aItem) \
  195. MPostDDEMsg(hTo, WM_DDE_ACK, hFrom, (UINT_PTR)wStatus, (UINT_PTR)aItem)
  196. #define GET_WM_DDE_ADVISE_HOPTIONS(wp, lp) ((HANDLE)MGetDDElParamLo(WM_DDE_ADVISE, lp))
  197. #define GET_WM_DDE_ADVISE_ITEM(wp, lp) ((ATOM)MGetDDElParamHi(WM_DDE_ADVISE, lp))
  198. #define MPostWM_DDE_ADVISE(hTo, hFrom, hOptions, aItem) \
  199. MPostDDEMsg(hTo, WM_DDE_ADVISE, hFrom, (UINT_PTR)hOptions, (UINT_PTR)aItem)
  200. #define GET_WM_DDE_DATA_HDATA(wp, lp) ((HANDLE)MGetDDElParamLo(WM_DDE_DATA, lp))
  201. #define GET_WM_DDE_DATA_ITEM(wp, lp) ((ATOM)MGetDDElParamHi(WM_DDE_DATA, lp))
  202. #define MPostWM_DDE_DATA(hTo, hFrom, hData, aItem) \
  203. MPostDDEMsg(hTo, WM_DDE_DATA, hFrom, (UINT_PTR)hData, (UINT_PTR)aItem)
  204. #define GET_WM_DDE_EXECUTE_HDATA(wp, lp) ((HANDLE)lp)
  205. #define MPostWM_DDE_EXECUTE(hTo, hFrom, hDataExec) \
  206. PostMessage(hTo, WM_DDE_EXECUTE, (WPARAM)hFrom, (LPARAM)hDataExec)
  207. #define GET_WM_DDE_POKE_HDATA(wp, lp) ((HANDLE)MGetDDElParamLo(WM_DDE_POKE, lp))
  208. #define GET_WM_DDE_POKE_ITEM(wp, lp) ((ATOM)MGetDDElParamHi(WM_DDE_POKE, lp))
  209. #define MPostWM_DDE_POKE(hTo, hFrom, hData, aItem) \
  210. MPostDDEMsg(hTo, WM_DDE_POKE, hFrom, (UINT_PTR)hData, (UINT_PTR)aItem)
  211. #define GET_WM_DDE_EXECACK_STATUS(wp, lp) ((WORD)MGetDDElParamLo(WM_DDE_ACK, lp))
  212. #define GET_WM_DDE_EXECACK_HDATA(wp, lp) ((HANDLE)MGetDDElParamHi(WM_DDE_ACK, lp))
  213. #define MPostWM_DDE_EXECACK(hTo, hFrom, wStatus, hCommands) \
  214. MPostDDEMsg(hTo, WM_DDE_ACK, hFrom, (UINT_PTR)wStatus, (UINT_PTR)hCommands)
  215. #define GET_WM_DDE_REQUEST_FORMAT(wp, lp) ((ATOM)LOWORD(lp))
  216. #define GET_WM_DDE_REQUEST_ITEM(wp, lp) ((ATOM)HIWORD(lp))
  217. #define MPostWM_DDE_REQUEST(hTo, hFrom, fmt, aItem) \
  218. MPostDDEMsg(hTo, WM_DDE_REQUEST, hFrom, (UINT_PTR)fmt, (UINT_PTR)aItem)
  219. #define GET_WM_DDE_UNADVISE_FORMAT(wp, lp) ((ATOM)LOWORD(lp))
  220. #define GET_WM_DDE_UNADVISE_ITEM(wp, lp) ((ATOM)HIWORD(lp))
  221. #define MPostWM_DDE_UNADVISE(hTo, hFrom, fmt, aItem) \
  222. MPostDDEMsg(hTo, WM_DDE_UNADVISE, hFrom, (UINT_PTR)fmt, (UINT_PTR)aItem)
  223. #define MPostWM_DDE_TERMINATE(hTo, hFrom) \
  224. PostMessage(hTo, WM_DDE_TERMINATE, (WPARAM)hFrom, 0L)
  225. /*-----------------------------------GDI-------------------------------------*/
  226. __inline BOOL APIENTRY MGetAspectRatioFilter(HDC hdc, INT * pcx, INT * pcy)
  227. {
  228. SIZE Size;
  229. BOOL fSuccess;
  230. fSuccess = GetAspectRatioFilterEx(hdc, & Size);
  231. if (pcx != NULL)
  232. *pcx = (INT)Size.cx;
  233. if (pcy != NULL)
  234. *pcy = (INT)Size.cy;
  235. return(fSuccess);
  236. }
  237. __inline BOOL APIENTRY MGetBitmapDimension(HANDLE hBitmap, INT * pcx, INT * pcy)
  238. {
  239. SIZE Size;
  240. BOOL fSuccess;
  241. fSuccess = GetBitmapDimensionEx((HBITMAP)hBitmap, & Size);
  242. if (pcx != NULL)
  243. *pcx = (INT)Size.cx;
  244. if (pcy != NULL)
  245. *pcy = (INT)Size.cy;
  246. return(fSuccess);
  247. }
  248. __inline BOOL APIENTRY MGetBrushOrg(HDC hdc, INT * px, INT * py)
  249. {
  250. POINT Point;
  251. BOOL fSuccess;
  252. fSuccess = GetBrushOrgEx(hdc, & Point);
  253. if (px != NULL)
  254. *px = Point.x;
  255. if (py != NULL)
  256. *py = Point.y;
  257. return(fSuccess);
  258. }
  259. __inline BOOL APIENTRY MGetCurrentPosition(HDC hdc, INT * px, INT * py)
  260. {
  261. POINT Point;
  262. BOOL fSuccess;
  263. fSuccess = GetCurrentPositionEx(hdc, & Point);
  264. if (px != NULL)
  265. *px = Point.x;
  266. if (py != NULL)
  267. *py = Point.y;
  268. return(fSuccess);
  269. }
  270. __inline BOOL APIENTRY MGetTextExtent(HDC hdc, LPSTR lpstr, INT cnt, INT * pcx, INT * pcy)
  271. {
  272. SIZE Size;
  273. BOOL fSuccess;
  274. fSuccess = GetTextExtentPointA(hdc, lpstr, (DWORD)cnt, & Size);
  275. if (pcx != NULL)
  276. *pcx = (INT)Size.cx;
  277. if (pcy != NULL)
  278. *pcy = (INT)Size.cy;
  279. return(fSuccess);
  280. }
  281. __inline BOOL APIENTRY MGetViewportExt(HDC hdc, INT * pcx, INT * pcy)
  282. {
  283. SIZE Size;
  284. BOOL fSuccess;
  285. fSuccess = GetViewportExtEx(hdc, & Size);
  286. if (pcx != NULL)
  287. *pcx = (INT)Size.cx;
  288. if (pcy != NULL)
  289. *pcy = (INT)Size.cy;
  290. return(fSuccess);
  291. }
  292. __inline BOOL APIENTRY MGetViewportOrg(HDC hdc, INT * px, INT * py)
  293. {
  294. POINT Point;
  295. BOOL fSuccess;
  296. fSuccess = GetViewportOrgEx(hdc, & Point);
  297. if (px != NULL)
  298. *px = Point.x;
  299. if (py != NULL)
  300. *py = Point.y;
  301. return(fSuccess);
  302. }
  303. __inline BOOL APIENTRY MGetWindowExt(HDC hdc, INT * pcx, INT * pcy)
  304. {
  305. SIZE Size;
  306. BOOL fSuccess;
  307. fSuccess = GetWindowExtEx(hdc, & Size);
  308. if (pcx != NULL)
  309. *pcx = (INT)Size.cx;
  310. if (pcy != NULL)
  311. *pcy = (INT)Size.cy;
  312. return(fSuccess);
  313. }
  314. __inline BOOL APIENTRY MGetWindowOrg(HDC hdc, INT * px, INT * py)
  315. {
  316. POINT Point;
  317. BOOL fSuccess;
  318. fSuccess = GetWindowOrgEx(hdc, & Point);
  319. if (px != NULL)
  320. *px = Point.x;
  321. if (py != NULL)
  322. *py = Point.y;
  323. return(fSuccess);
  324. }
  325. __inline HANDLE APIENTRY MGetMetaFileBits(HMETAFILE hmf)
  326. {
  327. HANDLE h;
  328. DWORD dwSize;
  329. h = GlobalAlloc(0, dwSize = GetMetaFileBitsEx(hmf, 0, NULL));
  330. if (h) {
  331. GetMetaFileBitsEx(hmf, dwSize, GlobalLock(h));
  332. GlobalUnlock(h);
  333. DeleteMetaFile(hmf);
  334. }
  335. return(h);
  336. }
  337. __inline HMETAFILE APIENTRY MSetMetaFileBits(HANDLE h)
  338. {
  339. HMETAFILE hmf;
  340. hmf = SetMetaFileBitsEx((UINT) GlobalSize(h), (CONST BYTE *)GlobalLock(h));
  341. GlobalUnlock(h);
  342. GlobalFree(h);
  343. return(hmf);
  344. }
  345. #define MCreateDiscardableBitmap(h, x, y) CreateCompatibleBitmap(h, (DWORD)(x), (DWORD)(y))
  346. #define MMoveTo(hdc, x, y) MoveToEx(hdc, x, y, NULL)
  347. #define MOffsetViewportOrg(hdc, x, y) OffsetViewportOrgEx(hdc, x, y, NULL)
  348. #define MOffsetWindowOrg(hdc, x, y) OffsetWindowOrgEx(hdc, x, y, NULL)
  349. #define MScaleViewportExt(hdc, x, y, xd, yd) ScaleViewportExtEx(hdc, x, y, xd, yd, NULL)
  350. #define MScaleWindowExt(hdc, x, y, xd, yd) ScaleWindowExtEx(hdc, x, y, xd, yd, NULL)
  351. #define MSetBitmapDimension(hbm, x, y) SetBitmapDimensionEx(hbm, (DWORD)(x), (DWORD)(y), NULL)
  352. #define MSetBrushOrg(hbm, x, y) SetBrushOrgEx(hbm, x, y, NULL)
  353. #define MSetViewportExt(hdc, x, y) SetViewportExtEx(hdc, x, y, NULL)
  354. #define MSetViewportOrg(hdc, x, y) SetViewportOrgEx(hdc, x, y, NULL)
  355. #define MSetWindowExt(hdc, x, y) SetWindowExtEx(hdc, x, y, NULL)
  356. #define MSetWindowOrg(hdc, x, y) SetWindowOrgEx(hdc, x, y, NULL)
  357. /* Removed APIs */
  358. #define MUnrealizeObject(h) ((h), TRUE)
  359. /*-----------------------------------KERNEL----------------------------------*/
  360. __inline HFILE APIENTRY MDupHandle(HFILE h)
  361. {
  362. HANDLE hDup;
  363. if (DuplicateHandle(GetCurrentProcess(), LongToHandle(h), GetCurrentProcess(),
  364. &hDup, 0, FALSE, DUPLICATE_SAME_ACCESS)) {
  365. return((HFILE)((ULONG_PTR)hDup));
  366. }
  367. return((HFILE)-1);
  368. }
  369. __inline BOOL APIENTRY MFreeDOSEnvironment(LPSTR lpEnv)
  370. {
  371. return(GlobalFree(GlobalHandle(lpEnv)) == NULL);
  372. }
  373. __inline LPSTR APIENTRY MGetDOSEnvironment(VOID)
  374. {
  375. // no way to make this work on NT. TO BE CANNED!!
  376. // For now, just use an empty string.
  377. static char szNULL[] = "";
  378. return(szNULL);
  379. }
  380. __inline HANDLE APIENTRY MGetInstHandle()
  381. {
  382. return GetModuleHandle( NULL );
  383. }
  384. __inline WORD APIENTRY MGetDriveType(INT nDrive)
  385. {
  386. CHAR lpPath[] = "A:\\";
  387. lpPath[0] = (char)(nDrive + 'A');
  388. return((WORD)GetDriveTypeA((LPSTR)lpPath));
  389. }
  390. __inline BYTE APIENTRY MGetTempDrive(BYTE cDriveLtr)
  391. {
  392. DWORD dwReturnLength;
  393. CHAR lpBuffer[MAX_PATH];
  394. if (cDriveLtr == 0) {
  395. dwReturnLength = GetCurrentDirectoryA(sizeof(lpBuffer), lpBuffer);
  396. } else {
  397. dwReturnLength = GetTempPathA(sizeof(lpBuffer), lpBuffer);
  398. }
  399. if (dwReturnLength && lpBuffer[0] != '\\') {
  400. return(lpBuffer[0]);
  401. } else {
  402. return('\0');
  403. }
  404. }
  405. __inline INT APIENTRY MGetTempFileName(BYTE cDriveLtr, LPSTR lpstrPrefix, WORD wUnique,LPSTR lpTempFileName)
  406. {
  407. DWORD cb;
  408. CHAR lpTempPath[MAX_PATH];
  409. lpTempPath[0] = '\0';
  410. if (cDriveLtr & TF_FORCEDRIVE) {
  411. cb = GetCurrentDirectoryA(sizeof(lpTempPath), lpTempPath);
  412. if (cb) {
  413. if (lpTempPath[0] != (cDriveLtr & ~TF_FORCEDRIVE)) {
  414. lpTempPath[2] = '\\';
  415. lpTempPath[3] = '\0';
  416. }
  417. }
  418. } else {
  419. cb = GetTempPathA(sizeof(lpTempPath), lpTempPath);
  420. }
  421. return((INT)GetTempFileNameA(lpTempPath, lpstrPrefix, wUnique,
  422. lpTempFileName));
  423. }
  424. __inline INT APIENTRY MReadComm(HFILE nCid,LPSTR lpBuf,INT nSize)
  425. {
  426. DWORD cbRead;
  427. if (!ReadFile(LongToHandle(nCid), lpBuf, nSize, &cbRead, 0))
  428. return(-(INT)cbRead);
  429. return((INT)cbRead);
  430. }
  431. __inline INT APIENTRY MWriteComm(HFILE nCid,LPSTR lpBuf,INT nSize)
  432. {
  433. DWORD cbWritten;
  434. if (!WriteFile(LongToHandle(nCid), lpBuf, nSize, &cbWritten, 0))
  435. return(-(INT)cbWritten);
  436. return((INT)cbWritten);
  437. }
  438. #define GETMAJORVERSION(x) ((x)&0xff)
  439. #define GETMINORVERSION(x) (((x)>>8)&0xff)
  440. /* FUNCTION MAPPINGS */
  441. #define GetInstanceData(hPrevInst, pbuf, cb) (cb)
  442. #define MOpenComm(lpstr, wqin, wqout) (wqin), (wqout), CreateFile(lpstr, \
  443. GENERIC_READ | GENERIC_WRITE, 0, \
  444. NULL, \
  445. OPEN_EXISTING | TRUNCATE_EXISTING, \
  446. FILE_FLAG_WRITE_THROUGH, 0)
  447. #define MSetCommState(h, lpDCB) SetCommState((HANDLE)h, lpDCB)
  448. #define MCloseComm(h) (INT)!CloseHandle((HANDLE)h)
  449. #define MDllSharedAlloc(dwFlags, dwBytes) GlobalAlloc(GMEM_DDESHARE | dwFlags, dwBytes)
  450. #define MDllSharedFlags(hMem) GlobalFlags(hMem)
  451. #define MDllSharedFree GlobalFree
  452. #define MDllSharedHandle GlobalHandle
  453. #define MDllSharedLock GlobalLock
  454. #define MDllSharedRealloc(hMem, dwBytes, dwFlags) \
  455. GlobalReAlloc(hMem, dwBytes, dwFlags)
  456. #define MDllSharedSize GlobalSize
  457. #define MDllSharedUnlock GlobalUnlock
  458. #define MGetCurrentTask GetCurrentThreadId
  459. #define MGetModuleUsage(h) ((h), 1)
  460. #define MGetWinFlags() WF_PMODE
  461. #define MLoadLibrary(lpsz) LoadLibrary(lpsz)
  462. #define MLocalInit(w, p1, p2) ((w),(p1),(p2),TRUE)
  463. #define MLockData(dummy)
  464. #define MUnlockData(dummy)
  465. #define M_lclose(fh) _lclose((HFILE)fh)
  466. #define M_lcreat (HFILE)_lcreat
  467. #define MOpenFile (HFILE)OpenFile
  468. #define M_llseek(fh, lOff, iOrg) SetFilePointer(LongToPtr(fh), lOff, NULL, (DWORD)iOrg)
  469. #define MDeleteFile DeleteFile
  470. #define M_lopen (HFILE)_lopen
  471. #define M_lread(fh, lpBuf, cb) _lread((HFILE)fh, lpBuf, cb)
  472. #define M_lwrite(fh, lpBuf, cb) _lwrite((HFILE)fh, lpBuf, cb)
  473. #define MCatch setjmp
  474. #define MThrow longjmp
  475. #ifdef __cplusplus
  476. }
  477. #endif
  478. #endif // __PWIN32_H__