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