home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Internet 2000 May / MICD_2000_05.iso / CBuilder5 / INSTALL / DATA1.CAB / Program_Built_Files / Include / dispdib.h < prev    next >
C/C++ Source or Header  |  2000-02-01  |  11KB  |  284 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*        DISPDIB.H - Include file for DisplayDib() function.               */
  4. /*                                                                          */
  5. /*        Note: You must include WINDOWS.H before including this file.      */
  6. /*                                                                          */
  7. /*        Copyright (c) 1990-1995, Microsoft Corp.  All rights reserved.    */
  8. /*                                                                          */
  9. /****************************************************************************/
  10.  
  11. #ifndef __DISPDIB_H__
  12. #pragma option push -b -a8 -pc -A- /*P_O_Push*/
  13. #define __DISPDIB_H__
  14.  
  15. // DisplayDib() error return codes
  16. #define DISPLAYDIB_NOERROR          0x0000  // success
  17. #define DISPLAYDIB_NOTSUPPORTED     0x0001  // function not supported
  18. #define DISPLAYDIB_INVALIDDIB       0x0002  // null or invalid DIB header
  19. #define DISPLAYDIB_INVALIDFORMAT    0x0003  // invalid DIB format
  20. #define DISPLAYDIB_INVALIDTASK      0x0004  // not called from current task
  21. #define DISPLAYDIB_STOP             0x0005  // stop requested
  22. #define DISPLAYDIB_NOTACTIVE        0x0006  // DisplayDibWindow not foreground
  23. #define DISPLAYDIB_BADSIZE          0x0007  //
  24.  
  25. // flags for <wFlags> parameter of DisplayDib()
  26. #define DISPLAYDIB_NOPALETTE        0x0010  // don't set palette
  27. #define DISPLAYDIB_NOCENTER         0x0020  // don't center image
  28. #define DISPLAYDIB_NOWAIT           0x0040  // don't wait before returning
  29. #define DISPLAYDIB_NOIMAGE          0x0080  // don't draw image
  30. #define DISPLAYDIB_ZOOM2            0x0100  // stretch by 2
  31. #define DISPLAYDIB_DONTLOCKTASK     0x0200  // don't lock current task
  32. #define DISPLAYDIB_TEST             0x0400  // testing the command
  33. #define DISPLAYDIB_NOFLIP           0x0800  // dont page flip
  34. #define DISPLAYDIB_BEGIN            0x8000  // start of multiple calls
  35. #define DISPLAYDIB_END              0x4000  // end of multiple calls
  36.  
  37. #define DISPLAYDIB_MODE             0x000F  // mask for display mode
  38. #define DISPLAYDIB_MODE_DEFAULT     0x0000  // default display mode
  39. #define DISPLAYDIB_MODE_320x200x8   0x0001  // 320-by-200
  40. #define DISPLAYDIB_MODE_320x240x8   0x0005  // 320-by-240
  41.  
  42. //
  43. // a Win32 app must use the window class the function
  44. // versions are not available
  45. //
  46. #ifndef _WIN32
  47.  
  48. // function prototypes
  49. UINT FAR PASCAL DisplayDib(LPBITMAPINFOHEADER lpbi, LPSTR lpBits, WORD wFlags);
  50. UINT FAR PASCAL DisplayDibEx(LPBITMAPINFOHEADER lpbi, int x, int y, LPSTR lpBits, WORD wFlags);
  51.  
  52. #define DisplayDibBegin() DisplayDib(NULL, NULL, DISPLAYDIB_BEGIN|DISPDIB_NOWAIT)
  53. #define DisplayDibEnd()   DisplayDib(NULL, NULL, DISPLAYDIB_END|DISPDIB_NOWAIT)
  54.  
  55. #endif
  56.  
  57. //
  58. //  DisplayDibWindow class.
  59. //
  60. //  simple interface to DISPDIB as a window class.
  61. //  draw images and create a fullscreen window in one easy step.
  62. //
  63. //  advantages over calling the APIs directly.
  64. //
  65. //      if you show the window it will handle enabling/disabling
  66. //      fullscreen mode when it has a activation.
  67. //
  68. //      while in fullscreen mode, window will be sized to
  69. //      cover entire display preventing other apps from getting
  70. //      clicked on. (when visible)
  71. //
  72. //      if window looses activation, fullscreen mode will be disabled
  73. //      DDM_DRAW will return DISPLAYDIB_NOTACTIVE if you try to draw
  74. //
  75. //      forwards all mouse and keyboard events to owner, easy way
  76. //      to take over entire screen.
  77. //
  78. //      alows interop with a Win32 application (via WM_COPYDATA)
  79. //      NOTE WM_COPYDATA does not actualy copy anything if the
  80. //      window belongs to the calling thread.  it will do a copy
  81. //      if the window is owned by another thread....
  82. //
  83. //  you can use a DisplayDibWindow in two ways.....
  84. //
  85. //      hidden window
  86. //
  87. //          if the window is hidden, you must use the
  88. //          DDM_BEGIN and DDM_END message to enable/disable
  89. //          fullscreen mode manualy when your app is activated deactivated.
  90. //
  91. //      visible toplevel window
  92. //
  93. //          if you show the window it will take over the entire screen
  94. //          and forward all mouse/keyboard input to its owner.
  95. //
  96. //          it will enter fullscreen automaticly when it is shown.
  97. //
  98. //          it will leave fullscreen and hide it self it another app
  99. //          grabs the focus.
  100. //
  101. //  class name:     "DisplayDibWindow"
  102. //                  class is registered when DISPDIB.DLL is loaded.
  103. //                  as a global class.
  104. //
  105. //  messages:
  106. //
  107. //      DDM_SETFMT  set new DIB format or program a new palette
  108. //
  109. //            fullscreen mode, will use best mode
  110. //                  for displaying the passed DIB format.
  111. //            defaul is 320x240x8 tripple buffered
  112. //
  113. //                  the palette will be programed with the color
  114. //                  table of the passed BITMAPINFOHEADER.
  115. //
  116. //                  the format is a BITMAPINFOHEADER followed by a color table.
  117. //
  118. //                  you must set a format before doing a begin, end or draw
  119. //                  you can set a 320x200 or a 320x24 mode by selecting
  120. //                  a DIB of the format you want.
  121. //
  122. //                  if you do a setfmt while fullscreen mode is active only the
  123. //                  the palette will be changed the new size (if any) wont
  124. //                  happen until the next begin.
  125. //
  126. //        wParam = 0
  127. //          lParam = LPBITMAPINFOHEADER
  128. //
  129. //          returns 0 if success else DISPLAYDIB_* error code.
  130. //
  131. //      DDM_DRAW    draws DIB data to fullscreen
  132. //                  format is assumed the same as format passed to
  133. //                  DDM_BEGIN or DDM_FMT
  134. //
  135. //          wParam = flags
  136. //          lParam = bits pointer.
  137. //
  138. //          returns 0 if success else DISPLAYDIB_* error code.
  139. //
  140. //      DDM_CLOSE   destroy window *and* free the DLL
  141. //
  142. //      DDM_BEGIN   enter DISPDIB mode.
  143. //          wParam = flags
  144. //          lParam = 0
  145. //
  146. //          returns 0 if success else DISPLAYDIB_* error code.
  147. //
  148. //      DDM_END     leave DISPDIB mode.
  149. //          wParam = flags
  150. //          lParam = 0
  151. //
  152. //          returns 0 if success else DISPLAYDIB_* error code.
  153. //
  154. //      WM_COPYDATA allows a Win32 app to send a DDM_ message, that requires
  155. //      a pointer.
  156. //
  157. //          wParam = hwnd of sender
  158. //          lParam = PCOPYDATASTRUCT
  159. //                  dwData      - LOWORD: DDM_* message value.
  160. //                  dwData      - HIWORD: wParam for message
  161. //                  lpData      - lParam (pointer to a BITMAPINFOHEADER or bits)
  162. //                  cbData      - size of data
  163. //
  164. //          returns   0 if success else DISPLAYDIB_* error code.
  165. //
  166.  
  167. #define DISPLAYDIB_WINDOW_CLASS     "DisplayDibWindow"
  168. #define DISPLAYDIB_DLL              "DISPDIB.DLL"
  169.  
  170. #define DDM_SETFMT      WM_USER+0
  171. #define DDM_DRAW        WM_USER+1
  172. #define DDM_CLOSE       WM_USER+2
  173. #define DDM_BEGIN       WM_USER+3
  174. #define DDM_END         WM_USER+4
  175.  
  176. //
  177. // inline function to send a message to a DisplayDibWindow
  178. //
  179. __inline UINT DisplayDibWindowMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, DWORD cbSize)
  180. {
  181. #if defined(_WIN32) || defined(WIN32)
  182.         COPYDATASTRUCT cds;
  183.         cds.dwData = MAKELONG(msg, wParam);
  184.         cds.cbData = lParam ? cbSize : 0;
  185.         cds.lpData = (LPVOID)lParam;
  186.         return (UINT)SendMessage(hwnd, WM_COPYDATA, (WPARAM)(HWND)NULL, (LPARAM)(LPVOID)&cds);
  187. #else
  188.         return (UINT)SendMessage(hwnd, msg, wParam, lParam);
  189. #endif
  190. }
  191.  
  192. //
  193. // inline function to create a DisplayDibWindow
  194. //
  195. __inline HWND DisplayDibWindowCreateEx(HWND hwndParent, HINSTANCE hInstance, DWORD dwStyle)
  196. {
  197. #if defined(_WIN32) || defined(WIN32)
  198.     DWORD show = 2;
  199.     DWORD zero = 0;
  200.     LPVOID params[4] = {NULL, &zero, &show, 0};
  201.  
  202.     if ((UINT)LoadModule(DISPLAYDIB_DLL, ¶ms) < (UINT)HINSTANCE_ERROR)
  203.         return NULL;    // loading DISPDIB did not work
  204. #else
  205.     if ((UINT)LoadLibrary(DISPLAYDIB_DLL) < (UINT)HINSTANCE_ERROR)
  206.         return NULL;    // loading DISPDIB did not work
  207. #endif
  208.  
  209.     return CreateWindow(DISPLAYDIB_WINDOW_CLASS,"",dwStyle,0, 0,
  210.             GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),
  211.             hwndParent, NULL,
  212.             (hInstance ? hInstance : GetWindowInstance(hwndParent)), NULL);
  213. }
  214.  
  215. //
  216. //  helper macros for a DisplayDibWindow
  217. //
  218. //  DisplayDibWindowCreate
  219. //
  220. //      used to create a toplevel WS_POPUP window.
  221. //
  222. //  DisplayDibWindowCreateEx
  223. //
  224. //      used to create a non-toplevel window, of a custom style.
  225. //
  226. //  DisplayDibWindowSetFmt
  227. //
  228. //      macro to send the DDM_SETFMT message.
  229. //
  230. //  DisplayDibWindowDraw
  231. //
  232. //      macro to send the DDM_DRAW message
  233. //
  234. //  DisplayDibWindowBegin
  235. //
  236. //      macro used to show the window
  237. //
  238. //  DisplayDibWindowEnd
  239. //
  240. //      macro used to hide the window
  241. //
  242. //  DisplayDibWindowBeginEx
  243. //
  244. //      macro used to send a DDM_BEGIN message, used with hidden windows
  245. //
  246. //  DisplayDibWindowEndEx
  247. //
  248. //      macro used to send a DDM_END message, used with hidden windows
  249. //
  250. //  DisplayDibWindowClose
  251. //
  252. //      macro used to send a DDM_CLOSE message
  253. //      this will destroy the window and free the DLL.
  254. //
  255. //  NOTES
  256. //      warning DisplayDibWindowBegin/End will show the DisplayDibWindow
  257. //      this will steal actiation away from your app. all mouse keyboard
  258. //      input will go to the dispdib window and it will forward it to
  259. //      its owner (make sure you set the right owner on create)
  260. //
  261. //      this may cause a problem for your app, you can keep the window
  262. //      hidden be using the DDM_BEGIN/END messages in this case.
  263. //
  264. #define DisplayDibWindowCreate(hwndP, hInstance)        DisplayDibWindowCreateEx(hwndP, hInstance, WS_POPUP)
  265. #define DisplayDibWindowSetFmt(hwnd, lpbi)              DisplayDibWindowMessage(hwnd, DDM_SETFMT, 0, (LPARAM)(LPVOID)(lpbi), sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD))
  266. #define DisplayDibWindowDraw(hwnd, flags, bits, size)   DisplayDibWindowMessage(hwnd, DDM_DRAW, (WPARAM)(UINT)(flags), (LPARAM)(LPVOID)(bits), (DWORD)(size))
  267.  
  268. #ifdef __cplusplus
  269. #define DisplayDibWindowBegin(hwnd)                     ::ShowWindow(hwnd, SW_SHOWNORMAL)
  270. #define DisplayDibWindowEnd(hwnd)                       ::ShowWindow(hwnd, SW_HIDE)
  271. #define DisplayDibWindowBeginEx(hwnd, f)                ::SendMessage(hwnd, DDM_BEGIN, (WPARAM)(UINT)(f), 0)
  272. #define DisplayDibWindowEndEx(hwnd)                     ::SendMessage(hwnd, DDM_END, 0, 0)
  273. #define DisplayDibWindowClose(hwnd)                     ::SendMessage(hwnd, DDM_CLOSE, 0, 0)
  274. #else
  275. #define DisplayDibWindowBegin(hwnd)                     ShowWindow(hwnd, SW_SHOWNORMAL)
  276. #define DisplayDibWindowEnd(hwnd)                       ShowWindow(hwnd, SW_HIDE)
  277. #define DisplayDibWindowBeginEx(hwnd)                   SendMessage(hwnd, DDM_BEGIN, 0, 0)
  278. #define DisplayDibWindowEndEx(hwnd)                     SendMessage(hwnd, DDM_END, 0, 0)
  279. #define DisplayDibWindowClose(hwnd)                     SendMessage(hwnd, DDM_CLOSE, 0, 0)
  280. #endif
  281.  
  282. #pragma option pop /*P_O_Pop*/
  283. #endif // _DISPDIB_H
  284.