Dispdib.h 11 KB

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