Annotation of mstools/samples/sdktools/imagedit/imagundo.c, revision 1.1

1.1     ! root        1: /****************************************************************************/
        !             2: /*                                                                          */
        !             3: /*                         Microsoft Confidential                           */
        !             4: /*                                                                          */
        !             5: /*                 Copyright (c) Microsoft Corp.  1987, 1991                */
        !             6: /*                           All Rights Reserved                            */
        !             7: /*                                                                          */
        !             8: /****************************************************************************/
        !             9: /****************************** Module Header *******************************
        !            10: * Module Name: imagundo.c
        !            11: *
        !            12: * Contains routines for handling the Undo buffers.
        !            13: *
        !            14: * History:
        !            15: *
        !            16: ****************************************************************************/
        !            17: 
        !            18: #include "imagedit.h"
        !            19: 
        !            20: 
        !            21: STATICFN VOID NEAR ImageAllocUndo(VOID);
        !            22: 
        !            23: 
        !            24: 
        !            25: /************************************************************************
        !            26: * ImageUndo
        !            27: *
        !            28: * Undoes the last editing operation by restoring the image to the
        !            29: * saved undo buffer.
        !            30: *
        !            31: * History:
        !            32: *
        !            33: ************************************************************************/
        !            34: 
        !            35: VOID ImageUndo(VOID)
        !            36: {
        !            37:     HDC hdcTemp;
        !            38:     HBITMAP hbmOld;
        !            39: 
        !            40:     /*
        !            41:      * Is there anything to undo?
        !            42:      */
        !            43:     if (!ghbmUndo)
        !            44:         return;
        !            45: 
        !            46:     hdcTemp = CreateCompatibleDC(ghdcImage);
        !            47:     hbmOld = SelectObject(hdcTemp, ghbmUndo);
        !            48:     BitBlt(ghdcImage, 0, 0, gcxImage, gcyImage, hdcTemp, 0, 0, SRCCOPY);
        !            49: 
        !            50:     /*
        !            51:      * For icons and cursors, restore the AND mask also.
        !            52:      */
        !            53:     if (giType != FT_BITMAP) {
        !            54:         SelectObject(hdcTemp, ghbmUndoMask);
        !            55:         BitBlt(ghdcANDMask, 0, 0, gcxImage, gcyImage, hdcTemp, 0, 0, SRCCOPY);
        !            56:     }
        !            57: 
        !            58:     SelectObject(hdcTemp, hbmOld);
        !            59:     DeleteDC(hdcTemp);
        !            60: 
        !            61:     fImageDirty = TRUE;
        !            62: 
        !            63:     /*
        !            64:      * Delete the undo buffer, now that it has been used.
        !            65:      */
        !            66:     ImageFreeUndo();
        !            67: 
        !            68:     ViewUpdate();
        !            69: }
        !            70: 
        !            71: 
        !            72: 
        !            73: /************************************************************************
        !            74: * ImageUpdateUndo
        !            75: *
        !            76: * Makes a snapshot of the current image and places it in the undo
        !            77: * buffer.
        !            78: *
        !            79: * Arguments:
        !            80: *
        !            81: * History:
        !            82: *
        !            83: ************************************************************************/
        !            84: 
        !            85: VOID ImageUpdateUndo(VOID)
        !            86: {
        !            87:     HDC hdcTemp;
        !            88:     HBITMAP hbmOld;
        !            89: 
        !            90:     /*
        !            91:      * If there are currently no undo buffers, allocate them now.
        !            92:      */
        !            93:     if (!ghbmUndo)
        !            94:         ImageAllocUndo();
        !            95: 
        !            96:     hdcTemp = CreateCompatibleDC(ghdcImage);
        !            97:     hbmOld = SelectObject(hdcTemp, ghbmUndo);
        !            98:     BitBlt(hdcTemp, 0, 0, gcxImage, gcyImage, ghdcImage, 0, 0, SRCCOPY);
        !            99: 
        !           100:     /*
        !           101:      * For icons and cursors, update the undo AND mask also.
        !           102:      */
        !           103:     if (giType != FT_BITMAP) {
        !           104:         SelectObject(hdcTemp, ghbmUndoMask);
        !           105:         BitBlt(hdcTemp, 0, 0, gcxImage, gcyImage, ghdcANDMask, 0, 0, SRCCOPY);
        !           106:     }
        !           107: 
        !           108:     SelectObject(hdcTemp, hbmOld);
        !           109:     DeleteDC(hdcTemp);
        !           110: }
        !           111: 
        !           112: 
        !           113: 
        !           114: /************************************************************************
        !           115: * ImageAllocUndo
        !           116: *
        !           117: * Allocates buffers for an undo operation.  For icons and cursors,
        !           118: * this includes an AND mask undo buffer.  This function does not
        !           119: * initialize the bits.  The function ImageFreeUndo frees the buffers
        !           120: * allocated by this function.
        !           121: *
        !           122: * History:
        !           123: *
        !           124: ************************************************************************/
        !           125: 
        !           126: STATICFN VOID NEAR ImageAllocUndo(VOID)
        !           127: {
        !           128:     ImageFreeUndo();
        !           129: 
        !           130:     /*
        !           131:      * Allocate an undo bitmap of the specified size.
        !           132:      */
        !           133:     if (!(ghbmUndo = MyCreateBitmap(ghdcImage, gcxImage, gcyImage, 16))) {
        !           134:         Message(MSG_OUTOFMEMORY);
        !           135:         return;
        !           136:     }
        !           137: 
        !           138:     /*
        !           139:      * For icons and cursors, allocate an undo AND mask also.
        !           140:      */
        !           141:     if (giType != FT_BITMAP) {
        !           142:         if (!(ghbmUndoMask = CreateBitmap(gcxImage, gcyImage,
        !           143:                 (BYTE)1, (BYTE)1, NULL))) {
        !           144:             ImageFreeUndo();
        !           145:             Message(MSG_OUTOFMEMORY);
        !           146:             return;
        !           147:         }
        !           148:     }
        !           149: }
        !           150: 
        !           151: 
        !           152: 
        !           153: /************************************************************************
        !           154: * ImageFreeUndo
        !           155: *
        !           156: * Free's the undo buffers.
        !           157: *
        !           158: * History:
        !           159: *
        !           160: ************************************************************************/
        !           161: 
        !           162: VOID ImageFreeUndo(VOID)
        !           163: {
        !           164:     if (ghbmUndo) {
        !           165:         DeleteObject(ghbmUndo);
        !           166:         ghbmUndo = NULL;
        !           167:     }
        !           168: 
        !           169:     if (ghbmUndoMask) {
        !           170:         DeleteObject(ghbmUndoMask);
        !           171:         ghbmUndoMask = NULL;
        !           172:     }
        !           173: }

unix.superglobalmegacorp.com

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