home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / inc / book1632.h next >
C/C++ Source or Header  |  1995-05-03  |  12KB  |  456 lines

  1. /*
  2.  * BOOK1632.H
  3.  *
  4.  * Macros and other definitions that assist in porting between Win16
  5.  * and Win32 applications.  Defines WIN32 to enable 32-bit versions.
  6.  *
  7.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Microsoft
  10.  * Internet  :  kraigb@microsoft.com
  11.  * Compuserve:  INTERNET>kraigb@microsoft.com
  12.  */
  13.  
  14.  
  15. #ifndef _BOOK1632_H_
  16. #define _BOOK1632_H_
  17.  
  18. #ifdef WIN32
  19.  
  20. #ifndef COMMANDPARAMS
  21. #define COMMANDPARAMS(wID, wCode, hWndMsg)                          \
  22.     WORD        wID     = LOWORD(wParam);                           \
  23.     WORD        wCode   = HIWORD(wParam);                           \
  24.     HWND        hWndMsg = (HWND)(UINT)lParam;
  25. #endif  //COMMANDPARAMS
  26.  
  27. #ifndef SendCommand
  28. #define SendCommand(hWnd, wID, wCode, hControl)                     \
  29.             SendMessage(hWnd, WM_COMMAND, MAKEWPARAM(wID, wCode)    \
  30.                         , (LPARAM)hControl)
  31. #endif  //SendCommand
  32.  
  33. #ifndef MENUSELECTPARAMS
  34. #define MENUSELECTPARAMS(wID, wFlags, hMenu)                        \
  35.     WORD        wID     = LOWORD(wParam);                           \
  36.     WORD        wFlags  = HIWORD(wParam);                           \
  37.     HMENU       hMenu   = (HMENU)lParam;
  38. #endif  //MENUSELECTPARAMS
  39.  
  40.  
  41. #ifndef SendMenuSelect
  42. #define SendMenuSelect(hWnd, wID, wFlags, hMenu)                    \
  43.             SendMessage(hWnd, WM_MENUSELECT                         \
  44.                 , MAKEWPARAM((WORD)wID, (WORD)wFlags), (LPARAM)hMenu)
  45.  
  46. #endif  //SendMenuSelect
  47.  
  48. #ifndef SendScrollPosition
  49. #define SendScrollPosition(hWnd, iMsg, iPos)                        \
  50.             SendMessage(hWnd, iMsg, MAKEWPARAM(SB_THUMBPOSITION, iPos), 0)
  51. #endif //SendScrollPosition
  52.  
  53. #ifndef ScrollThumbPosition
  54. #define ScrollThumbPosition(w, l) HIWORD(w)
  55. #endif //ScrollThumbPosition
  56.  
  57. #ifndef GETWINDOWINSTANCE
  58. #define GETWINDOWINSTANCE(h) (HINSTANCE)GetWindowLong(h, GWL_HINSTANCE)
  59. #endif  //GETWINDOWINSTANCE
  60.  
  61. #ifndef GETWINDOWID
  62. #define GETWINDOWID(h) (UINT)GetWindowLong(h, GWW_ID)
  63. #endif  //GETWINDOWID
  64.  
  65. #ifndef POINTFROMLPARAM
  66. #define POINTFROMLPARAM(p, l) {p.x=(LONG)(SHORT)LOWORD(l); \
  67.                                p.y=(LONG)(SHORT)HIWORD(l);}
  68. #endif  //POINTFROMLPARAM
  69.  
  70. #ifndef MDISETMENU
  71. #define MDISETMENU(h, hM, hMW)  SendMessage(h, WM_MDISETMENU \
  72.                                     , (WPARAM)hM, (LPARAM)hMW);
  73. #endif  //MDISETMENU
  74.  
  75.  
  76. #ifndef MDIREFRESHMENU
  77. #define MDIREFRESHMENU(h) SendMessage(h, WM_MDIREFRESHMENU, 0, 0L)
  78. #endif  //MDIREFRESHMENU
  79.  
  80.  
  81. //Activated child window in WM_MDIACTIVATE
  82. #ifndef NEWMDIACTIVE
  83. #define NEWMDIACTIVE lParam
  84. #endif  //NEWMDIACTIVE
  85.  
  86. #ifndef UNICODETOANSI
  87. #ifdef UNICODE
  88. #define UNICODETOANSI(s, d, cch) WideCharToMultiByte(CP_ACP \
  89.             , 0, s, -1, d, cch, NULL, NULL)
  90. #else  //ANSI
  91. #define UNICODETOANSI(s, d, cch) lstrcpy(d, (LPTSTR)s);
  92. #endif
  93. #endif //UNICODETOANSI
  94.  
  95.  
  96. #ifndef ANSITOUNICODE
  97. #ifdef UNICODE
  98. #define ANSITOUNICODE(s, d, cch) MultiByteToWideChar(CP_ACP \
  99.             , 0, s, -1, d, cch)
  100. #else //ANSI
  101. #define ANSITOUNICODE(s, d, cch) lstrcpy(d, (LPTSTR)s);
  102. #endif
  103. #endif  //ANSITOUNICODE
  104.  
  105.  
  106.  
  107. #ifndef SETMESSAGEQUEUE
  108. #define SETMESSAGEQUEUE
  109. #endif
  110.  
  111. #ifndef CHECKVER_COM
  112. #define CHECKVER_COM
  113. #endif  //CHECKVER_COM
  114.  
  115. #ifndef CHECKVER_OLE
  116. #define CHECKVER_OLE
  117. #endif  //CHECKVER_OLE
  118.  
  119. //****END WIN32
  120.  
  121.  
  122.  
  123. #else
  124.  
  125.  
  126.  
  127. //****START !WIN32
  128.  
  129. #ifndef POINTS
  130. typedef POINT POINTS;
  131. #endif  //POINTS
  132.  
  133. #ifndef LPPOINTS
  134. typedef POINTS FAR *LPPOINTS;
  135. #endif  //LPPOINTS
  136.  
  137. #ifndef MAKEPOINTS
  138. #define MAKEPOINTS MAKEPOINT
  139. #endif  //MAKEPOINTS
  140.  
  141.  
  142. #ifndef COMMANDPARAMS
  143. #define COMMANDPARAMS(wID, wCode, hWndMsg)                          \
  144.     WORD        wID     = LOWORD(wParam);                           \
  145.     WORD        wCode   = HIWORD(lParam);                           \
  146.     HWND        hWndMsg = (HWND)(UINT)lParam;
  147. #endif  //COMMANDPARAMS
  148.  
  149. #ifndef SendCommand
  150. #define SendCommand(hWnd, wID, wCode, hControl)                     \
  151.             SendMessage(hWnd, WM_COMMAND, wID                       \
  152.                         , MAKELONG(hControl, wCode))
  153. #endif  //SendCommand
  154.  
  155. #ifndef MENUSELECTPARAMS
  156. #define MENUSELECTPARAMS(wID, wFlags, hMenu)                        \
  157.     WORD        wID     = LOWORD(wParam);                           \
  158.     WORD        wFlags  = LOWORD(lParam);                           \
  159.     HMENU       hMenu   = (HMENU)HIWORD(lParam);
  160. #endif  //MENUSELECTPARAMS
  161.  
  162. #ifndef SendMenuSelect
  163. #define SendMenuSelect(hWnd, wID, wFlags, hMenu)                    \
  164.             SendMessage(hWnd, WM_MENUSELECT, wID                    \
  165.                         , MAKELONG((WORD)wFlags, (WORD)hMenu))
  166. #endif  //SendMenuSelect
  167.  
  168. #ifndef SendScrollPosition
  169. #define SendScrollPosition(hWnd, iMsg, iPos)                        \
  170.             SendMessage(hWnd, iMsg, SB_THUMBPOSITION, MAKELONG(iPos, 0))
  171. #endif //Send ScrollPosition
  172.  
  173. #ifndef ScrollThumbPosition
  174. #define ScrollThumbPosition(w, l) LOWORD(l)
  175. #endif //ScrollThumbPosition
  176.  
  177. #ifndef GETWINDOWINSTANCE
  178. #define GETWINDOWINSTANCE(h) (HINSTANCE)GetWindowWord(h, GWW_HINSTANCE)
  179. #endif  //GETWINDOWINSTANCE
  180.  
  181. #ifndef GETWINDOWID
  182. #define GETWINDOWID(h) (UINT)GetWindowWord(h, GWW_ID)
  183. #endif  //GETWINDOWID
  184.  
  185. #ifndef POINTFROMLPARAM
  186. #define POINTFROMLPARAM(p, l) {p.x=LOWORD(l); p.y=HIWORD(l);}
  187. #endif  //POINTFROMLPARAM
  188.  
  189. #ifndef MDISETMENU
  190. #define MDISETMENU(h, hM, hMW)  SendMessage(h, WM_MDISETMENU \
  191.                      , (WPARAM)FALSE, (LPARAM)MAKELPARAM(hM, hMW))
  192. #endif  //MDISETMENU
  193.  
  194.  
  195. #ifndef MDIREFRESHMENU
  196. #define MDIREFRESHMENU(h) SendMessage(h, WM_MDISETMENU, TRUE, 0L)
  197. #endif  //MDIREFRESHMENU
  198.  
  199. //Activated child window in WM_MDIACTIVATE
  200. #ifndef NEWMDIACTIVE
  201. #define NEWMDIACTIVE wParam
  202. #endif  //NEWMDIACTIVE
  203.  
  204.  
  205. //Things not present in Win3.1 SDK but present in Win32 SDK.
  206.  
  207. #ifndef APIENTRY
  208. #define APIENTRY __export FAR PASCAL
  209. #endif  //APIENTRY
  210.  
  211. #ifndef USHORT
  212. typedef unsigned short USHORT;
  213. #endif  //USHORT
  214.  
  215. //These are so we can write ANSI/UNICODE portable code.
  216. #ifndef TCHAR
  217. typedef char TCHAR;
  218. #endif  //TCHAR
  219.  
  220. #ifndef LPTSTR
  221. typedef TCHAR *LPTSTR;
  222. #endif  //LPTSTR
  223.  
  224. #ifndef LPCTSTR
  225. typedef const TCHAR *LPCTSTR;
  226. #endif  //LPCTSTR
  227.  
  228. #ifndef _tcsncpy
  229. #define _tcsncpy strncpy
  230. #endif  //_tcsncpy
  231.  
  232. #ifndef _tcsstr
  233. #define _tcsstr strstr
  234. #endif  //_tcsstr
  235.  
  236. #ifndef _tcsrchr
  237. #define _tcsrchr strrchr
  238. #endif  //_tcsrchr
  239.  
  240. #ifndef _tcsncicmp
  241. #define _tcsncicmp  strnicmp
  242. #endif  //_tcsncicmp
  243.  
  244. #ifndef _ttoi
  245. #define _ttoi   atoi
  246. #endif  //_ttoi
  247.  
  248. #ifndef lstrcpyA
  249. #define lstrcpyA lstrcpy
  250. #endif  //lstrcpyA
  251.  
  252. #ifndef lstrcmpiA
  253. #define lstrcmpiA lstrcmpi
  254. #endif  //lstrcmpiA
  255.  
  256. #ifndef TEXT
  257. #define TEXT(a) a
  258. #endif  //TEXT
  259.  
  260. #ifndef ReadFile
  261. #define ReadFile(h, b, c, x, y) _lread(h, b, c)
  262. #endif  //ReadFile
  263.  
  264. #ifndef CloseHandle
  265. #define CloseHandle(h) _lclose(h)
  266. #endif  //CloseHandle
  267.  
  268. #ifndef INVALID_HANDLE_VALUE
  269. #define INVALID_HANDLE_VALUE        HFILE_ERROR
  270. #endif  //INVALID_HANDLE_VALUE
  271.  
  272. #ifndef MAX_PATH
  273. #define MAX_PATH   260
  274. #endif  //MAX_PATH
  275.  
  276. #ifndef _MAX_PATH
  277. #define _MAX_PATH   MAX_PATH
  278. #endif  //_MAX_PATH
  279.  
  280. #ifndef RegCreateKeyEx
  281. #define RegCreateKeyEx(h, sz, d, nl1, opt, acc, nl2, ph, nl3)   \
  282.         RegCreateKey(h, sz, ph)
  283. #endif  //RegCreateKeyEx
  284.  
  285. #ifndef RegSetValueEx
  286. #define RegSetValueEx(h, nl, d, rsz, psz, pch)  \
  287.         RegSetValue(h, nl, rsz, (LPCSTR)psz, 0)
  288. #endif  //RegSetValueEx
  289.  
  290. #ifndef wsprintfA
  291. #define wsprintfA wsprintf
  292. #endif  //wsprintfA
  293.  
  294. #ifndef LoadLibraryA
  295. #define LoadLibraryA LoadLibrary
  296. #endif  //LoadLibraryA
  297.  
  298. #ifndef MessageBoxA
  299. #define MessageBoxA MessageBox
  300. #endif  //MessageBoxA
  301.  
  302. #ifndef SetForegroundWindow
  303. #define SetForegroundWindow(h) BringWindowToTop(h)
  304. #endif  //SetForegroundWindow
  305.  
  306. #ifndef DeleteFile
  307. #define DeleteFile(f)                       \
  308.             {                               \
  309.             OFSTRUCT    of;                 \
  310.             OpenFile(f, &of, OF_DELETE);    \
  311.             }
  312. #endif  //DeleteFile
  313.  
  314. #ifndef UNICODETOANSI
  315. #define UNICODETOANSI(s, d, cch) lstrcpy(d, (LPTSTR)s);
  316. #endif  //UNICODETOANSI
  317.  
  318. #ifndef ANSITOUNICODE
  319. #define ANSITOUNICODE(s, d, cch) lstrcpy(d, (LPTSTR)s);
  320. #endif  //ANSITOUNICODE
  321.  
  322.  
  323. #ifndef SETMESSAGEQUEUE
  324. #define SETMESSAGEQUEUE                                  \
  325.             {                                            \
  326.             int cMsg=96;                                 \
  327.             while (!SetMessageQueue(cMsg) && (cMsg-=8)); \
  328.             }
  329. #endif  //SETMESSAGEQUEUE
  330.  
  331.  
  332. #ifdef INC_OLE2
  333. #ifndef CoTaskMemFree
  334. #define CoTaskMemFree(pv)                                       \
  335.             {                                                   \
  336.             IMalloc *pIMalloc;                                  \
  337.             if (SUCCEEDED(CoGetMalloc(MEMCTX_TASK, &pIMalloc))) \
  338.                 {                                               \
  339.                 pIMalloc->Free(pv);                             \
  340.                 pIMalloc->Release();                            \
  341.                 }                                               \
  342.             }
  343. #endif  //CoTaskMemFree
  344. #endif
  345.  
  346. #ifndef CHECKVER_COM
  347. #define CHECKVER_COM                    \
  348.             {                           \
  349.             DWORD       dwVer;          \
  350.                                         \
  351.             dwVer=CoBuildVersion();     \
  352.                                         \
  353.             if (rmm!=HIWORD(dwVer))     \
  354.                 return FALSE;           \
  355.             }
  356.  
  357. #endif  //CHECKVER_COM
  358.  
  359.  
  360. #ifndef CHECKVER_OLE
  361. #define CHECKVER_OLE                    \
  362.             {                           \
  363.             DWORD       dwVer;          \
  364.                                         \
  365.             dwVer=OleBuildVersion();    \
  366.                                         \
  367.             if (rmm!=HIWORD(dwVer))     \
  368.                 return FALSE;           \
  369.             }
  370.  
  371. #endif  //CHECKVER_OLE
  372.  
  373.  
  374. //Stolen from Win32 so we can do OLE Controls on Win16
  375. #ifndef FVIRTKEY
  376. #define FVIRTKEY  TRUE
  377. #endif
  378. #ifndef FNOINVERT
  379. #define FNOINVERT 0x02
  380. #endif
  381. #ifndef FSHIFT
  382. #define FSHIFT    0x04
  383. #endif
  384. #ifndef FCONTROL
  385. #define FCONTROL  0x08
  386. #endif
  387. #ifndef FALT
  388. #define FALT      0x10
  389. #endif
  390.  
  391. #ifndef ACCELL
  392. typedef struct tagACCEL
  393.     {
  394.     BYTE   fVirt;
  395.     WORD   key;
  396.     WORD   cmd;
  397.     } ACCEL, *LPACCEL;
  398. #endif
  399.  
  400.  
  401. /*
  402.  * Appeared in OLE2.02 on 16-bit, always in Win32 defined as 1.
  403.  * 0 is the only valid flag on OLE 2.01 and 2.00.
  404.  */
  405. #ifndef ROTFLAGS_REGISTRATIONKEEPSALIVE
  406. #define ROTFLAGS_REGISTRATIONKEEPSALIVE     0
  407. #endif  //ROTFLAGS_REGISTRATIONKEEPSALIVE
  408.  
  409. #endif  //!WIN32
  410.  
  411.  
  412. //These definitions we need regardless of Win16 or Win32
  413.  
  414. /*
  415.  * May not have these in which case they're irrelevant but
  416.  * we want things to still compile.
  417.  */
  418. #ifndef ACTIVEOBJECT_STRONG
  419. #define ACTIVEOBJECT_STRONG     0
  420. #endif  //ACTIVEOBJECT_STRONG
  421.  
  422. //If this is not defined, it doesn't exist, so make it zero.
  423. #ifndef ACTIVEOBJECT_WEAK
  424. #define ACTIVEOBJECT_WEAK       0
  425. #endif  //ACTIVEOBJECT_WEAK
  426.  
  427.  
  428. typedef struct
  429.     {
  430.     short   left;
  431.     short   top;
  432.     short   right;
  433.     short   bottom;
  434.     } RECTS, FAR *LPRECTS;
  435.  
  436. #define RECTSTORECT(rs, r) {(r).left=(rs).left;(r).top=(rs).top; \
  437.     (r).right=(rs).right;(r).bottom=(rs).bottom;};
  438.  
  439. #define RECTTORECTS(r, rs) {(rs).left=(short)(r).left;   \
  440.     (rs).top=(short)(r).top;(rs).right=(short)(r).right; \
  441.     (rs).bottom=(short)(r).bottom;};
  442.  
  443.  
  444. /*
  445.  * This is for ANSI compiles on Win32, where we HAVE to use
  446.  * a Unicode string literal (so the TEXT macro isn't good enough).
  447.  */
  448.  
  449. #ifdef WIN32ANSI
  450. #define OLETEXT(x)  L ## x
  451. #else
  452. #define OLETEXT(x)  TEXT(x)
  453. #endif
  454.  
  455. #endif  //_BOOK1632_H_
  456.