home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / graphics / gdi / showdib / showdib.h < prev    next >
C/C++ Source or Header  |  1997-10-05  |  13KB  |  318 lines

  1.  
  2. /******************************************************************************\
  3. *       This is a part of the Microsoft Source Code Samples. 
  4. *       Copyright (C) 1993-1997 Microsoft Corporation.
  5. *       All rights reserved. 
  6. *       This source code is only intended as a supplement to 
  7. *       Microsoft Development Tools and/or WinHelp documentation.
  8. *       See these sources for detailed information regarding the 
  9. *       Microsoft samples programs.
  10. \******************************************************************************/
  11.  
  12. #include <stdio.h>
  13. /****************************************************************************
  14.  *                                                                          *
  15.  *  FILE        : SHOWDIB.H                                                 *
  16.  *                                                                          *
  17.  *  DESCRIPTION : Header/include file for ShowDIB example.                  *
  18.  *                                                                          *
  19.  ****************************************************************************/
  20.  
  21. typedef    POINTS       MPOINT         ;
  22.  
  23. #ifdef _WIN32
  24. #define GET_WM_ACTIVATE_STATE(wp, lp)   LOWORD(wp)
  25. #define GET_WM_VSCROLL_CODE(wp, lp)     LOWORD(wp)
  26. #define GET_WM_VSCROLL_POS(wp, lp)      HIWORD(wp)
  27. #define GET_WM_HSCROLL_CODE(wp, lp)     LOWORD(wp)
  28. #define GET_WM_HSCROLL_POS(wp, lp)      HIWORD(wp)
  29. #define GET_EM_SETSEL_MPS(iStart, iEnd) (UINT)(iStart), (LONG)(iEnd)
  30. #define GET_WM_COMMAND_CMD(wp, lp)      HIWORD(wp)
  31. #define MAKEMPOINT(l)                   (*((MPOINT *)&(l)))
  32. #define HUGE_T
  33. #else
  34. #define GET_WM_ACTIVATE_STATE(wp, lp)               (wp)
  35. #define GET_WM_HSCROLL_CODE(wp, lp)                 (wp)
  36. #define GET_WM_HSCROLL_POS(wp, lp)                  LOWORD(lp)
  37. #define GET_WM_VSCROLL_CODE(wp, lp)                 (wp)
  38. #define GET_WM_VSCROLL_POS(wp, lp)                  LOWORD(lp)
  39. #define GET_EM_SETSEL_MPS(iStart, iEnd) 0, MAKELONG(iStart, iEnd)
  40. #define GET_WM_COMMAND_CMD(wp, lp)      HIWORD(lp)
  41. #define MAKEMPOINT(l)                   (*((MPOINT FAR *)&(l)))
  42. #define HUGE_T         huge
  43. #endif
  44.  
  45. /* Macro to restrict a given value to an upper or lower boundary value */
  46. #define BOUND(x,min,max) ((x) < (min) ? (min) : ((x) > (max) ? (max) : (x)))
  47.  
  48. /* Macro to swap two values */
  49. #define SWAP(x,y)   ((x)^=(y)^=(x)^=(y))
  50.  
  51. /* Macro to find the minimum of two values */
  52. #define MIN(x,y) (((x) <= (y)) : x ? y)
  53.  
  54. /* Macros to display/remove hourglass cursor for lengthy operations */
  55. #define StartWait() hcurSave = SetCursor(LoadCursor(NULL,IDC_WAIT))
  56. #define EndWait()   SetCursor(hcurSave)
  57.  
  58. /* WinFlags, __WinFlags is a ABS external, thus the need for the & */
  59. #define WinFlags    ((WORD)(&_WinFlags))
  60.  
  61. #define MINBAND         50     /* Minimum band size used by the program */
  62. #define BANDINCREMENT   20     /* Decrement for band size while trying  */
  63.                                /* to determine optimum band size.       */
  64.  
  65. /* Bit values for the DIB attributes flag (fFileOptions). Also used as control
  66.  * IDs for the radiobuttons for DIB bitcount in the File/Open dialog
  67.  */
  68. #define F_1BPP      DLGOPEN_1BPP
  69. #define F_4BPP      DLGOPEN_4BPP
  70. #define F_8BPP      DLGOPEN_8BPP
  71. #define F_24BPP     DLGOPEN_24BPP
  72.  
  73. /* Bit values for the DIB attributes flag (fFileOptions), also used as control
  74.  * IDs for the radiobuttons for DIB compression type in the File/Open dialog
  75.  */
  76. #define F_RLE4      DLGOPEN_RLE4
  77. #define F_RLE8      DLGOPEN_RLE8
  78. #define F_RGB       DLGOPEN_RGB
  79.  
  80. #ifdef NOT_IN_STDIO
  81. /* flags for _lseek */
  82. #define  SEEK_CUR 1
  83. #define  SEEK_END 2
  84. #define  SEEK_SET 0
  85. #endif
  86.  
  87. /* struct to be passed in for the SETDIBSCALING printer escape */
  88. typedef struct {
  89.         SHORT ScaleMode;
  90.         SHORT dx, dy;
  91. } DIBPARAMS;
  92.  
  93. /* Menu IDs */
  94.  
  95. #define IDM_UPDATECOL   1000
  96. #define IDM_ANIMATE0    1001
  97. #define IDM_ANIMATE5    5
  98. #define IDM_ANIMATE20   20
  99. #define IDM_ANIMATE50   50
  100. #define IDM_ANIMATE100  100
  101. #define IDM_ANIMATE200  200
  102. #define IDM_ANIMATE201  32000
  103.  
  104. #define IDM_OPEN        1002
  105. #define IDM_EXIT        1003
  106. #define IDM_ABOUT       1004
  107. #define IDM_DIBSCREEN   1005
  108. #define IDM_NOUGLY      1006
  109. #define IDM_STEALCOL    1009
  110. #define IDM_PRINT       1010
  111. #define IDM_COPY        1012
  112. #define IDM_MEMORYDIB   1014
  113. #define IDM_SAVE        1015
  114. #define IDM_TRANSPARENT 1016
  115.  
  116. #define IDM_PASTEDIB    1020
  117. #define IDM_PASTEDDB    1021
  118. #define IDM_PASTEPAL    1022
  119.  
  120. /*String IDs*/
  121. #define IDS_MEMLOW          650
  122. #define IDS_NOMEM           651
  123. #define IDS_OPENDIBPROMPT   652
  124. #define IDS_SAVEDIBPROMPT   653
  125. #define IDS_CANTSAVEFILE    654
  126. #define IDS_CANTOPENFILE    655
  127. #define IDS_BADDIBFILE      656
  128. #define IDS_CREATEPALFAIL   657
  129. #define IDS_CANTLOADRLE     658
  130. #define IDS_CANTCREATEBMP   659
  131. #define IDS_CANTDRAWSCANS   660
  132. #define IDS_CANTDRAWMAP     661
  133. #define IDS_SAVESTR         662
  134. #define IDS_OPENSTR         663
  135.  
  136. #define IDI_APP         2000
  137.  
  138. #define ABOUTBOX        100
  139.  
  140. extern HWND hWndApp;                   /* The handle to the app. window     */
  141.  
  142. #define MAXREAD  32768                 /* Number of bytes to be read during */
  143.                                        /* each read operation.              */
  144.  
  145. /* Header signatutes for various resources */
  146. #define BFT_ICON   0x4349   /* 'IC' */
  147. #define BFT_BITMAP 0x4d42   /* 'BM' */
  148. #define BFT_CURSOR 0x5450   /* 'PT' */
  149.  
  150. /* macro to determine if resource is a DIB */
  151. #define ISDIB(bft) ((bft) == BFT_BITMAP)
  152.  
  153. /* Macro to align given value to the closest DWORD (unsigned long ) */
  154. #define ALIGNULONG(i)   ((i+3)/4*4)
  155.  
  156. /* Macro to determine to round off the given value to the closest byte */
  157. #define WIDTHBYTES(i)   ((i+31)/32*4)
  158.  
  159. #define PALVERSION      0x300
  160. #define MAXPALETTE      256       /* max. # supported palette entries */
  161.  
  162. /********** THE FOLLOWING ARE USED IN DLGOPEN.C  ************************/
  163.  
  164. /* IDs for controls in the DlgOpen dialog */
  165. #define DLGOPEN_EDIT            101
  166. #define DLGOPEN_FILE_LISTBOX    102
  167. #define DLGOPEN_DIR_LISTBOX     103
  168. #define DLGOPEN_PATH            104
  169. #define DLGOPEN_TEXT            105
  170. #define DLGOPEN_FOLDOUT         106
  171. #define DLGOPEN_BIG             107
  172. #define DLGOPEN_SMALL           108
  173.  
  174. #define DLGOPEN_OPTION          0xF000
  175. #define DLGOPEN_1BPP            0x0001
  176. #define DLGOPEN_4BPP            0x0002
  177. #define DLGOPEN_8BPP            0x0004
  178. #define DLGOPEN_24BPP           0x0008
  179. #define DLGOPEN_RLE4            0x0010
  180. #define DLGOPEN_RLE8            0x0020
  181. #define DLGOPEN_RGB             0x0040
  182.  
  183. #define DLGOPEN_OPTION8         0x0080
  184.  
  185. /*  flags:
  186.  *     The LOWORD is the standard FileOpen() flags (OF_*)
  187.  *     the HIWORD can be any of the following:
  188.  */
  189. #define OF_MUSTEXIST    0x00010000  /* file must exist if the user hits Ok    */
  190. #define OF_NOSHOWSPEC   0x00020000  /* DO NOT Show search spec in the edit box*/
  191. #define OF_SHOWSPEC     0x00000000  /* Show the search spec in the edit box   */
  192. #define OF_SAVE         0x00040000  /* Ok button will say "Save"              */
  193. #define OF_OPEN         0x00080000  /* Ok button will say "Open"              */
  194. #define OF_NOOPTIONS    0x00100000  /* Disable the options fold out           */
  195.  
  196. /* Attributes for DlgDirLst() */
  197. #define ATTRFILELIST    0x0000        /* include files only          */
  198. #define ATTRDIRLIST     0xC010        /* directories and drives ONLY */
  199. #define CBEXTMAX        6             /* Number of bytes in "\*.txt" */
  200.  
  201.  
  202. #define IDF(id)     ((id) & ~DLGOPEN_OPTION)  /* extracts flag from control ID */
  203. #define FID(f)      ((f)  |  DLGOPEN_OPTION)  /* extracts control ID from flag */
  204.  
  205. /***************** GLOBAL VARIABLES *************************/
  206.  
  207. extern CHAR           achFileName[128]; /* File pathname                       */
  208. extern DWORD          dwOffset;     /* Current position if DIB file pointer    */
  209. extern RECT           rcClip;       /* Current clip rectangle.                 */
  210. extern BOOL           fPalColors;   /* TRUE if the current DIB's color table   */
  211.                                     /* contains palette indexes not rgb values */
  212. extern BOOL           bDIBToDevice; /* Use SetDIBitsToDevice() to BLT data.    */
  213. extern BOOL           bLegitDraw;   /* We have a valid bitmap to draw          */
  214. extern WORD           wTransparent; /* Mode of DC                              */
  215. extern CHAR           szAppName[];  /* App. name                               */
  216. extern HPALETTE       hpalCurrent;  /* Handle to current palette               */
  217. extern HANDLE         hdibCurrent;  /* Handle to current memory DIB            */
  218. extern HBITMAP        hbmCurrent;   /* Handle to current memory BITMAP         */
  219. extern HANDLE         hbiCurrent;   /* Handle to current bitmap info struct    */
  220. extern DWORD          dwStyle;      /* Style bits of the App. window           */
  221. extern HINSTANCE      hInst;        /* Global instance handle                  */
  222.  
  223. /***************** FUNCTION DECLARATIONS *******************/
  224.  
  225. DWORD PASCAL lread(INT fh, VOID FAR *pv, DWORD ul);
  226. DWORD PASCAL lwrite(INT fh, VOID FAR *pv, DWORD ul);
  227.  
  228. /***********************************************************/
  229. /* Declarations of functions used in showdib.c module      */
  230. /***********************************************************/
  231.  
  232. LONG     APIENTRY WndProc  (HWND, UINT, UINT, LONG) ;
  233. BOOL               MenuCommand (HWND hWnd, UINT wParam);
  234. INT                InitDIB (HWND);
  235. VOID               FreeDib (VOID);
  236.  
  237. /***********************************************************/
  238. /* Declarations of functions used in dib.c module          */
  239. /***********************************************************/
  240.  
  241. HANDLE      OpenDIB (LPSTR szFile);
  242. BOOL        WriteDIB (LPSTR szFile,HANDLE hdib);
  243. WORD        PaletteSize (VOID FAR * pv);
  244. WORD        DibNumColors (VOID FAR * pv);
  245. HPALETTE    CreateDibPalette (HANDLE hdib);
  246. HPALETTE    CreateBIPalette (LPBITMAPINFOHEADER lpbi);
  247. HANDLE      DibFromBitmap (HBITMAP hbm, DWORD biStyle, WORD biBits, HPALETTE hpal);
  248. HBITMAP     BitmapFromDib (HANDLE hdib, HPALETTE hpal);
  249. BOOL        DibBlt (HDC hdc, INT x0, INT y0, INT dx, INT dy, HANDLE hdib, INT x1, INT y1, LONG rop);
  250. BOOL        StretchDibBlt (HDC hdc, INT x0, INT y0, INT dx, INT dy, HANDLE hdib, INT x1, INT y1, INT dx1, INT dy1, LONG rop);
  251. BOOL        DibInfo (HANDLE hdib,LPBITMAPINFOHEADER lpbi);
  252. HANDLE      ReadDibBitmapInfo (INT fh);
  253. BOOL        DrawBitmap (HDC hdc, INT x, INT y, HBITMAP hbm, DWORD rop);
  254. VOID            ReadBitMapFileHeaderandConvertToDwordAlign(HFILE fh, LPBITMAPFILEHEADER pbf, LPDWORD lpdwoff);
  255. VOID    WriteMapFileHeaderandConvertFromDwordAlignToPacked(HFILE fh, LPBITMAPFILEHEADER pbf);
  256.  
  257. /***********************************************************/
  258. /* Declarations of functions used in drawdib. c module     */
  259. /***********************************************************/
  260.  
  261. VOID               PrintDIB (HWND hWnd, HDC hDC, INT x, INT y, INT dx, INT dy);
  262. VOID               AppPaint (HWND hWnd, HDC hDC, INT x, INT y);
  263. INT                ErrMsg (PSTR sz,...);
  264. BOOL               fDialog (INT id, HWND hwnd, FARPROC fpfn);
  265. VOID               BandDIB (HWND hWnd, HDC hDC, INT x, INT y);
  266. BOOL     APIENTRY AppAbout (HWND, UINT, UINT, LONG) ;
  267. HANDLE             CopyHandle (HANDLE h);
  268. VOID               SizeWindow (HWND hWnd);
  269. VOID               GetRealClientRect (HWND hwnd, PRECT lprc);
  270. VOID               SetScrollRanges (HWND hwnd);
  271. VOID               DrawSelect (HDC hdc, BOOL fDraw);
  272. VOID        PASCAL NormalizeRect (RECT *prc);
  273. VOID               TrackMouse (HWND hwnd, MPOINT pt);
  274. HBITMAP            CopyBitmap (HBITMAP hbm);
  275. HPALETTE           CopyPalette (HPALETTE hpal);
  276. HBITMAP            CropBitmap (HBITMAP hbm, PRECT prc);
  277. HANDLE             RenderFormat (INT cf);
  278. HANDLE             RealizeDibFormat (DWORD biStyle, WORD biBits);
  279.  
  280. /***********************************************************/
  281. /* Declarations of functions used in the print.c module    */
  282. /***********************************************************/
  283.  
  284. BOOL    PASCAL InitPrinting (HDC hDC, HWND hWnd, HANDLE hInst, LPSTR msg);
  285. VOID    PASCAL TermPrinting (HDC hDC);
  286. HDC     PASCAL GetPrinterDC (VOID);
  287. HDC     PASCAL GetPrinterDC1 (VOID);
  288.  
  289. /***********************************************************/
  290. /* Declarations of functions used in the dlgopen.c module  */
  291. /***********************************************************/
  292.  
  293. LONG APIENTRY DlgfnOpen(    
  294.         HWND hwnd,
  295.     UINT msg,
  296.     UINT wParam,
  297.     LONG lParam
  298. );
  299. HFILE APIENTRY DlgOpenFile (
  300.         HWND            hwndParent,
  301.         CHAR            *szTitleIn,
  302.         DWORD           flags,
  303.         CHAR            *szExtIn,
  304.     CHAR        *szFileNameIn,
  305.     WORD                *pfOpt
  306. );
  307.  
  308. /*****************************************************/
  309. /* make new sizeof structs to cover dword alignment  */
  310. /*****************************************************/
  311.  
  312. #define SIZEOF_BITMAPFILEHEADER_PACKED  (   \
  313.     sizeof(WORD) +      /* bfType      */   \
  314.     sizeof(DWORD) +     /* bfSize      */   \
  315.     sizeof(WORD) +      /* bfReserved1 */   \
  316.     sizeof(WORD) +      /* bfReserved2 */   \
  317.     sizeof(DWORD))      /* bfOffBits   */
  318.