Annotation of mstools/samples/showdib/showdib.h, revision 1.1.1.4

1.1.1.4 ! root        1: 
        !             2: /******************************************************************************\
        !             3: *       This is a part of the Microsoft Source Code Samples. 
        !             4: *       Copyright (C) 1993 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: 
1.1       root       12: #include <stdio.h>
                     13: /****************************************************************************
1.1.1.4 ! root       14:  *                                                                          *
        !            15:  *  FILE        : SHOWDIB.H                                                 *
        !            16:  *                                                                          *
        !            17:  *  DESCRIPTION : Header/include file for ShowDIB example.                  *
        !            18:  *                                                                          *
1.1       root       19:  ****************************************************************************/
                     20: 
1.1.1.4 ! root       21: typedef    POINTS       MPOINT         ;
1.1       root       22: 
                     23: #ifdef WIN32
1.1.1.4 ! root       24: #define GET_WM_ACTIVATE_STATE(wp, lp)   LOWORD(wp)
        !            25: #define GET_WM_VSCROLL_CODE(wp, lp)     LOWORD(wp)
1.1       root       26: #define GET_WM_VSCROLL_POS(wp, lp)      HIWORD(wp)
1.1.1.4 ! root       27: #define GET_WM_HSCROLL_CODE(wp, lp)     LOWORD(wp)
1.1       root       28: #define GET_WM_HSCROLL_POS(wp, lp)      HIWORD(wp)
                     29: #define GET_EM_SETSEL_MPS(iStart, iEnd) (UINT)(iStart), (LONG)(iEnd)
1.1.1.4 ! root       30: #define GET_WM_COMMAND_CMD(wp, lp)      HIWORD(wp)
        !            31: #define MAKEMPOINT(l)                   (*((MPOINT *)&(l)))
1.1       root       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: 
1.1.1.4 ! root       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.       */
1.1       root       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:  */
1.1.1.4 ! root       68: #define F_1BPP      DLGOPEN_1BPP
        !            69: #define F_4BPP      DLGOPEN_4BPP
        !            70: #define F_8BPP      DLGOPEN_8BPP
1.1       root       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:  */
1.1.1.4 ! root       76: #define F_RLE4      DLGOPEN_RLE4
        !            77: #define F_RLE8      DLGOPEN_RLE8
        !            78: #define F_RGB       DLGOPEN_RGB
1.1       root       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 {
1.1.1.4 ! root       89:         SHORT ScaleMode;
        !            90:         SHORT dx, dy;
1.1       root       91: } DIBPARAMS;
                     92: 
                     93: /* Menu IDs */
                     94: 
1.1.1.4 ! root       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
1.1       root      114: #define IDM_TRANSPARENT 1016
                    115: 
                    116: #define IDM_PASTEDIB    1020
                    117: #define IDM_PASTEDDB    1021
                    118: #define IDM_PASTEPAL    1022
                    119: 
                    120: #define IDI_APP         2000
                    121: 
                    122: #define ABOUTBOX        100
                    123: 
1.1.1.4 ! root      124: extern HWND hWndApp;                   /* The handle to the app. window     */
1.1       root      125: 
1.1.1.4 ! root      126: #define MAXREAD  32768                 /* Number of bytes to be read during */
        !           127:                                        /* each read operation.              */
1.1       root      128: 
                    129: /* Header signatutes for various resources */
                    130: #define BFT_ICON   0x4349   /* 'IC' */
                    131: #define BFT_BITMAP 0x4d42   /* 'BM' */
                    132: #define BFT_CURSOR 0x5450   /* 'PT' */
                    133: 
                    134: /* macro to determine if resource is a DIB */
                    135: #define ISDIB(bft) ((bft) == BFT_BITMAP)
                    136: 
                    137: /* Macro to align given value to the closest DWORD (unsigned long ) */
1.1.1.4 ! root      138: #define ALIGNULONG(i)   ((i+3)/4*4)
1.1       root      139: 
                    140: /* Macro to determine to round off the given value to the closest byte */
1.1.1.4 ! root      141: #define WIDTHBYTES(i)   ((i+31)/32*4)
1.1       root      142: 
                    143: #define PALVERSION      0x300
1.1.1.4 ! root      144: #define MAXPALETTE      256       /* max. # supported palette entries */
1.1       root      145: 
                    146: /********** THE FOLLOWING ARE USED IN DLGOPEN.C  ************************/
                    147: 
                    148: /* IDs for controls in the DlgOpen dialog */
1.1.1.4 ! root      149: #define DLGOPEN_EDIT            101
        !           150: #define DLGOPEN_FILE_LISTBOX    102
        !           151: #define DLGOPEN_DIR_LISTBOX     103
        !           152: #define DLGOPEN_PATH            104
1.1       root      153: #define DLGOPEN_TEXT            105
                    154: #define DLGOPEN_FOLDOUT         106
                    155: #define DLGOPEN_BIG             107
                    156: #define DLGOPEN_SMALL           108
                    157: 
                    158: #define DLGOPEN_OPTION          0xF000
1.1.1.4 ! root      159: #define DLGOPEN_1BPP            0x0001
        !           160: #define DLGOPEN_4BPP            0x0002
        !           161: #define DLGOPEN_8BPP            0x0004
        !           162: #define DLGOPEN_24BPP           0x0008
        !           163: #define DLGOPEN_RLE4            0x0010
        !           164: #define DLGOPEN_RLE8            0x0020
        !           165: #define DLGOPEN_RGB             0x0040
1.1       root      166: 
                    167: #define DLGOPEN_OPTION8         0x0080
                    168: 
                    169: /*  flags:
                    170:  *     The LOWORD is the standard FileOpen() flags (OF_*)
                    171:  *     the HIWORD can be any of the following:
                    172:  */
1.1.1.4 ! root      173: #define OF_MUSTEXIST    0x00010000  /* file must exist if the user hits Ok    */
        !           174: #define OF_NOSHOWSPEC   0x00020000  /* DO NOT Show search spec in the edit box*/
        !           175: #define OF_SHOWSPEC     0x00000000  /* Show the search spec in the edit box   */
        !           176: #define OF_SAVE         0x00040000  /* Ok button will say "Save"              */
        !           177: #define OF_OPEN         0x00080000  /* Ok button will say "Open"              */
        !           178: #define OF_NOOPTIONS    0x00100000  /* Disable the options fold out           */
1.1       root      179: 
                    180: /* Attributes for DlgDirLst() */
1.1.1.4 ! root      181: #define ATTRFILELIST    0x0000        /* include files only          */
        !           182: #define ATTRDIRLIST     0xC010        /* directories and drives ONLY */
        !           183: #define CBEXTMAX        6             /* Number of bytes in "\*.txt" */
1.1       root      184: 
                    185: 
                    186: #define IDF(id)     ((id) & ~DLGOPEN_OPTION)  /* extracts flag from control ID */
1.1.1.4 ! root      187: #define FID(f)      ((f)  |  DLGOPEN_OPTION)  /* extracts control ID from flag */
1.1       root      188: 
                    189: /***************** GLOBAL VARIABLES *************************/
                    190: 
1.1.1.4 ! root      191: extern CHAR           achFileName[128]; /* File pathname                       */
        !           192: extern DWORD          dwOffset;     /* Current position if DIB file pointer    */
        !           193: extern RECT           rcClip;       /* Current clip rectangle.                 */
        !           194: extern BOOL           fPalColors;   /* TRUE if the current DIB's color table   */
        !           195:                                     /* contains palette indexes not rgb values */
        !           196: extern BOOL           bDIBToDevice; /* Use SetDIBitsToDevice() to BLT data.    */
        !           197: extern BOOL           bLegitDraw;   /* We have a valid bitmap to draw          */
        !           198: extern WORD           wTransparent; /* Mode of DC                              */
        !           199: extern CHAR           szAppName[];  /* App. name                               */
        !           200: extern HPALETTE       hpalCurrent;  /* Handle to current palette               */
        !           201: extern HANDLE         hdibCurrent;  /* Handle to current memory DIB            */
        !           202: extern HBITMAP        hbmCurrent;   /* Handle to current memory BITMAP         */
        !           203: extern HANDLE         hbiCurrent;   /* Handle to current bitmap info struct    */
        !           204: extern DWORD          dwStyle;      /* Style bits of the App. window           */
1.1       root      205: 
                    206: /***************** FUNCTION DECLARATIONS *******************/
                    207: 
                    208: DWORD PASCAL lread(INT fh, VOID FAR *pv, DWORD ul);
                    209: DWORD PASCAL lwrite(INT fh, VOID FAR *pv, DWORD ul);
                    210: 
                    211: /***********************************************************/
1.1.1.4 ! root      212: /* Declarations of functions used in showdib.c module      */
1.1       root      213: /***********************************************************/
                    214: 
1.1.1.4 ! root      215: LONG     APIENTRY WndProc  (HWND, UINT, UINT, LONG) ;
        !           216: BOOL               MenuCommand (HWND hWnd, UINT wParam);
        !           217: INT                InitDIB (HWND);
        !           218: VOID               FreeDib (VOID);
1.1       root      219: 
                    220: /***********************************************************/
1.1.1.4 ! root      221: /* Declarations of functions used in dib.c module          */
1.1       root      222: /***********************************************************/
                    223: 
1.1.1.4 ! root      224: HANDLE      OpenDIB (LPSTR szFile);
        !           225: BOOL        WriteDIB (LPSTR szFile,HANDLE hdib);
        !           226: WORD        PaletteSize (VOID FAR * pv);
        !           227: WORD        DibNumColors (VOID FAR * pv);
1.1       root      228: HPALETTE    CreateDibPalette (HANDLE hdib);
                    229: HPALETTE    CreateBIPalette (LPBITMAPINFOHEADER lpbi);
1.1.1.4 ! root      230: HANDLE      DibFromBitmap (HBITMAP hbm, DWORD biStyle, WORD biBits, HPALETTE hpal);
        !           231: HBITMAP     BitmapFromDib (HANDLE hdib, HPALETTE hpal);
        !           232: BOOL        DibBlt (HDC hdc, INT x0, INT y0, INT dx, INT dy, HANDLE hdib, INT x1, INT y1, LONG rop);
        !           233: BOOL        StretchDibBlt (HDC hdc, INT x0, INT y0, INT dx, INT dy, HANDLE hdib, INT x1, INT y1, INT dx1, INT dy1, LONG rop);
        !           234: BOOL        DibInfo (HANDLE hdib,LPBITMAPINFOHEADER lpbi);
        !           235: HANDLE      ReadDibBitmapInfo (INT fh);
        !           236: BOOL        DrawBitmap (HDC hdc, INT x, INT y, HBITMAP hbm, DWORD rop);
        !           237: VOID            ReadBitMapFileHeaderandConvertToDwordAlign(HFILE fh, LPBITMAPFILEHEADER pbf, LPDWORD lpdwoff);
        !           238: VOID    WriteMapFileHeaderandConvertFromDwordAlignToPacked(HFILE fh, LPBITMAPFILEHEADER pbf);
1.1       root      239: 
                    240: /***********************************************************/
1.1.1.4 ! root      241: /* Declarations of functions used in drawdib. c module     */
1.1       root      242: /***********************************************************/
                    243: 
1.1.1.4 ! root      244: VOID               PrintDIB (HWND hWnd, HDC hDC, INT x, INT y, INT dx, INT dy);
        !           245: VOID               AppPaint (HWND hWnd, HDC hDC, INT x, INT y);
        !           246: INT                ErrMsg (PSTR sz,...);
        !           247: BOOL               fDialog (INT id, HWND hwnd, FARPROC fpfn);
        !           248: VOID               BandDIB (HWND hWnd, HDC hDC, INT x, INT y);
        !           249: BOOL     APIENTRY AppAbout (HWND, UINT, UINT, LONG) ;
        !           250: HANDLE             CopyHandle (HANDLE h);
        !           251: VOID               SizeWindow (HWND hWnd);
        !           252: VOID               GetRealClientRect (HWND hwnd, PRECT lprc);
        !           253: VOID               SetScrollRanges (HWND hwnd);
        !           254: VOID               DrawSelect (HDC hdc, BOOL fDraw);
        !           255: VOID        PASCAL NormalizeRect (RECT *prc);
        !           256: VOID               TrackMouse (HWND hwnd, MPOINT pt);
        !           257: HBITMAP            CopyBitmap (HBITMAP hbm);
        !           258: HPALETTE           CopyPalette (HPALETTE hpal);
        !           259: HBITMAP            CropBitmap (HBITMAP hbm, PRECT prc);
        !           260: HANDLE             RenderFormat (INT cf);
        !           261: HANDLE             RealizeDibFormat (DWORD biStyle, WORD biBits);
1.1       root      262: 
                    263: /***********************************************************/
                    264: /* Declarations of functions used in the print.c module    */
                    265: /***********************************************************/
                    266: 
1.1.1.4 ! root      267: BOOL    PASCAL InitPrinting (HDC hDC, HWND hWnd, HANDLE hInst, LPSTR msg);
        !           268: VOID    PASCAL TermPrinting (HDC hDC);
        !           269: HDC     PASCAL GetPrinterDC (VOID);
        !           270: HDC     PASCAL GetPrinterDC1 (VOID);
1.1       root      271: 
                    272: /***********************************************************/
                    273: /* Declarations of functions used in the dlgopen.c module  */
                    274: /***********************************************************/
                    275: 
                    276: LONG APIENTRY DlgfnOpen(    
1.1.1.4 ! root      277:         HWND hwnd,
1.1       root      278:     UINT msg,
                    279:     UINT wParam,
                    280:     LONG lParam
                    281: );
                    282: HFILE APIENTRY DlgOpenFile (
1.1.1.4 ! root      283:         HWND            hwndParent,
        !           284:         CHAR            *szTitleIn,
        !           285:         DWORD           flags,
        !           286:         CHAR            *szExtIn,
1.1       root      287:     CHAR        *szFileNameIn,
1.1.1.4 ! root      288:     WORD                *pfOpt
1.1       root      289: );
                    290: 
                    291: /*****************************************************/
                    292: /* make new sizeof structs to cover dword alignment  */
                    293: /*****************************************************/
                    294: 
                    295: #define SIZEOF_BITMAPFILEHEADER_PACKED  (   \
                    296:     sizeof(WORD) +      /* bfType      */   \
                    297:     sizeof(DWORD) +     /* bfSize      */   \
                    298:     sizeof(WORD) +      /* bfReserved1 */   \
                    299:     sizeof(WORD) +      /* bfReserved2 */   \
                    300:     sizeof(DWORD))      /* bfOffBits   */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.