GLOBALS.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:15k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                 Copyright (C) 1987-1996 Microsoft Corp.                */
  4. /*                           All Rights Reserved                            */
  5. /*                                                                          */
  6. /****************************************************************************/
  7. /****************************** Module Header *******************************
  8. * Module Name: globals.c
  9. *
  10. * Global data for the image editor.
  11. *
  12. * History:
  13. *
  14. ****************************************************************************/
  15. #include "imagedit.h"
  16. #include "dialogs.h"
  17. #include "iehelp.h"
  18. #include "ids.h"
  19. /*
  20.  * Initialized data and structures -----------------------------------------
  21.  */
  22. /*
  23.  * Initialization data structure.  This describes each profile entry
  24.  * that is contained in the initialization file.
  25.  */
  26. INIENTRY gaie[] = {
  27.     { "fGrid",          &gfGrid,            FALSE,              0 },
  28.     { "fShowColor",     &gfShowColor,       TRUE,               0 },
  29.     { "fShowView",      &gfShowView,        TRUE,               0 },
  30.     { "fShowToolbox",   &gfShowToolbox,     TRUE,               0 },
  31.     { "nBrushSize",     &gnBrushSize,       3,                  0 },
  32.     { NULL,             NULL,               0,                  0 }
  33. };
  34. BOOL gfGrid;                        // TRUE if the grid is on.
  35. BOOL gfShowColor;                   // TRUE if Color palette is to be shown.
  36. BOOL gfShowView;                    // TRUE if View window is to be shown.
  37. BOOL gfShowToolbox;                 // TRUE if Toolbox is to be shown.
  38. INT gnBrushSize;                    // Current brush size.
  39. CHAR szAppPos[] = "AppPos";         // App window's position keyname.
  40. CHAR szTBPos[] = "TBPos";           // Toolbox window's position keyname.
  41. CHAR szViewPos[] = "ViewPos";       // View window's position keyname.
  42. CHAR szColorPos[] = "ColorPos";     // Color palette window's position keyname.
  43. CHAR szrgbScreen[] = "rgbScreen";   // Screen color keyname.
  44. /*
  45.  * Instance handles, window handles and class strings ----------------------
  46.  */
  47. HANDLE ghInst;                      // App instance handle.
  48. HANDLE haccelTbl;                   // Accelerator table handle.
  49. HCURSOR hcurWait;                   // Standard hourglass cursor.
  50. HWND ghwndMain;                     // Main app window handle.
  51. HWND ghwndWork;                     // Workspace window handle.
  52. HWND ghwndPropBar;                  // Properties Bar window handle.
  53. HWND ghwndToolbox;                  // Toolbox window handle.
  54. HWND ghwndView;                     // View window handle.
  55. HWND ghwndColor;                    // Color palette window handle.
  56. CHAR szMainClass[] = "ImagEdit";    // Main window class.
  57. CHAR szWorkClass[] = "Work";        // Work window class.
  58. CHAR szToolboxClass[] = "Toolbox";  // Toolbox window class.
  59. CHAR szToolBtnClass[] = "ToolBtn";  // Toolbox button window class.
  60. CHAR szViewClass[] = "View";        // View window class.
  61. CHAR szColorBoxClass[] = "ColorBox";// Color box window class.
  62. CHAR szColorLRClass[] = "ColorLR";  // Color Left-Right sample class.
  63. /*
  64.  * Device list globals -----------------------------------------------------
  65.  */
  66. PDEVICE gpIconDeviceHead = NULL;    // Head of icon device list.
  67. INT gnIconDevices = 0;              // Number of icon devices.
  68. PDEVICE gpCursorDeviceHead = NULL;  // Head of cursor device list.
  69. INT gnCursorDevices = 0;            // Number of cursor devices.
  70. /*
  71.  * Globals that describe the current file and image being edited -----------
  72.  */
  73. CHAR gszFullFileName[CCHMAXPATH];   // Full path name of current file.
  74. PSTR gpszFileName = NULL;           // Current file name (or NULL).
  75. INT giType = FT_BITMAP;             // Type of object being edited currently.
  76. PIMAGEINFO gpImageHead = NULL;      // Head of image linked list.
  77. INT gnImages = 0;                   // Number of images in the file.
  78. BOOL fFileDirty;                    // TRUE if the file is dirty.
  79. PIMAGEINFO gpImageCur = NULL;       // Pointer to current image.
  80. INT gcxImage;                       // Width of the image.
  81. INT gcyImage;                       // Height of the image.
  82. INT gnColors = 16;                  // Number of colors of current image.
  83. BOOL fImageDirty;                   // TRUE if the image is dirty.
  84. /*
  85.  * Drawing DC's and bitmaps ------------------------------------------------
  86.  */
  87. HDC ghdcImage = NULL;               // Image XOR DC.
  88. HBITMAP ghbmImage = NULL;           // Image XOR bitmap.
  89. HDC ghdcANDMask = NULL;             // Image AND mask DC.
  90. HBITMAP ghbmANDMask = NULL;         // Image AND mask bitmap.
  91. HBITMAP ghbmUndo = NULL;            // Backup of XOR bitmap for undo.
  92. HBITMAP ghbmUndoMask = NULL;        // Backup of AND mask bitmap for undo.
  93. /*
  94.  * Globals for the color palette and drawing -------------------------------
  95.  */
  96. INT giColorLeft;                    // Index to the left color in gargbCurrent.
  97. INT giColorRight;                   // Index to the right color in gargbCurrent.
  98. INT gfModeLeft;                     // Mode of the left color brush.
  99. INT gfModeRight;                    // Mode of the right color brush.
  100. HBRUSH ghbrLeft = NULL;             // Brush with left mouse button color.
  101. HBRUSH ghbrLeftSolid = NULL;        // Brush with solid left button color.
  102. HBRUSH ghbrRight = NULL;            // Brush with right mouse button color.
  103. HBRUSH ghbrRightSolid = NULL;       // Brush with solid right button color.
  104. HBRUSH ghbrScreen = NULL;           // Brush with screen color.
  105. HBRUSH ghbrInverse = NULL;          // Brush with inverse screen color.
  106. HPEN ghpenLeft = NULL;              // Left color pen.
  107. HPEN ghpenRight = NULL;             // Right color pen.
  108. DWORD grgbScreenDefault;            // Default screen color.
  109. DWORD grgbScreen;                   // RGB of screen color.
  110. DWORD grgbInverse;                  // RGB of inverse screen color.
  111. DWORD *gargbCurrent;                // Points to the current color table.
  112. DWORD gargbColor[COLORSMAX];        // Current color color table.
  113. DWORD gargbMono[COLORSMAX];         // Current monochrome color table.
  114. HPEN hpenDarkGray = NULL;           // A dark gray pen.
  115. DRAWPROC gpfnDrawProc;              // Current drawing functions.
  116. INT gCurTool = -1;                  // Current tool (TOOL_* define).
  117. HBRUSH ghbrDraw = NULL;             // Current drawing brush.
  118. HBRUSH ghbrDrawSolid = NULL;        // Current solid drawing brush.
  119. HPEN ghpenDraw = NULL;              // Current drawing pen.
  120. INT gfDrawMode;                     // Mode of current drawing brush.
  121. /*
  122.  * The default color palette.
  123.  */
  124. DWORD gargbDefaultColor[] = {
  125.     RGB(255, 255, 255), RGB(0, 0, 0),
  126.     RGB(192, 192, 192), RGB(128, 128, 128),
  127.     RGB(255, 0, 0),     RGB(128, 0, 0),
  128.     RGB(255, 255, 0),   RGB(128, 128, 0),
  129.     RGB(0, 255, 0),     RGB(0, 128, 0),
  130.     RGB(0, 255, 255),   RGB(0, 128, 128),
  131.     RGB(0, 0, 255),     RGB(0, 0, 128),
  132.     RGB(255, 0, 255),   RGB(128, 0, 128),
  133.     RGB(255, 255, 128), RGB(128, 128, 64),
  134.     RGB(0, 255, 128),   RGB(0, 64, 64),
  135.     RGB(128, 255, 255), RGB(0, 128, 255),
  136.     RGB(128, 128, 255), RGB(0, 64, 128),
  137.     RGB(255, 0, 128),   RGB(64, 0, 128),
  138.     RGB(255, 128, 64),  RGB(128, 64, 0)
  139. };
  140. /*
  141.  * The default monochrome palette.
  142.  */
  143. DWORD gargbDefaultMono[] =   {
  144.     RGB(255, 255, 255), RGB(0, 0, 0),
  145.     RGB(128, 128, 128), RGB(9, 9, 9),
  146.     RGB(137, 137, 137), RGB(18, 18, 18),
  147.     RGB(146, 146, 146), RGB(27, 27, 27),
  148.     RGB(155, 155, 155), RGB(37, 37, 37),
  149.     RGB(164, 164, 164), RGB(46, 46, 46),
  150.     RGB(173, 173, 173), RGB(55, 55, 55),
  151.     RGB(182, 182, 182), RGB(63, 63, 63),
  152.     RGB(191, 191, 191), RGB(73, 73, 73),
  153.     RGB(201, 201, 201), RGB(82, 82, 82),
  154.     RGB(212, 212, 212), RGB(92, 92, 92),
  155.     RGB(222, 222, 222), RGB(101, 101, 101),
  156.     RGB(231, 231, 231), RGB(110, 110, 110),
  157.     RGB(245, 245, 245), RGB(119, 119, 119)
  158. };
  159. /*
  160.  * Color table for monochrome DIB's.
  161.  */
  162. DWORD gargbColorTable2[] = {
  163.     RGB(0, 0, 0),
  164.     RGB(255, 255, 255)
  165. };
  166. /*
  167.  * Array that describes each tool used in the editor.  This table
  168.  * is indexed by the TOOL_* defines.
  169.  */
  170. TOOLS gaTools[] = {
  171.     { PencilDP,     NULL,   IDBM_TUPENCIL,  NULL,   IDBM_TDPENCIL,  NULL,
  172.         TRUE, FALSE },
  173.     { BrushDP,      NULL,   IDBM_TUBRUSH,   NULL,   IDBM_TDBRUSH,   NULL,
  174.         TRUE, FALSE },
  175.     { PickDP,       NULL,   IDBM_TUSELECT,  NULL,   IDBM_TDSELECT,  NULL,
  176.         FALSE, FALSE },
  177.     { LineDP,       NULL,   IDBM_TULINE,    NULL,   IDBM_TDLINE,    NULL,
  178.         FALSE, TRUE },
  179.     { RectDP,       NULL,   IDBM_TURECT,    NULL,   IDBM_TDRECT,    NULL,
  180.         FALSE, TRUE },
  181.     { RectDP,       NULL,   IDBM_TUSRECT,   NULL,   IDBM_TDSRECT,   NULL,
  182.         FALSE, TRUE },
  183.     { CircleDP,     NULL,   IDBM_TUCIRCLE,  NULL,   IDBM_TDCIRCLE,  NULL,
  184.         FALSE, TRUE },
  185.     { CircleDP,     NULL,   IDBM_TUSCIRCL,  NULL,   IDBM_TDSCIRCL,  NULL,
  186.         FALSE, TRUE },
  187.     { FloodDP,      NULL,   IDBM_TUFLOOD,   NULL,   IDBM_TDFLOOD,   NULL,
  188.         TRUE, FALSE },
  189.     { HotSpotDP,    NULL,   IDBM_TUHOTSPT,  NULL,   IDBM_TDHOTSPT,  NULL,
  190.         FALSE, FALSE }
  191. };
  192. /*
  193.  * Globals and tables for messages and help --------------------------------
  194.  */
  195. /*
  196.  * Message box messages, for the Message() function.
  197.  */
  198. MESSAGEDATA gamdMessages[] = {
  199.     { IDS_OUTOFMEMORY,          MB_OK | MB_ICONHAND                 },
  200.     { IDS_MEMERROR,             MB_OK | MB_ICONHAND                 },
  201.     { IDS_BADBMPFILE,           MB_OK | MB_ICONEXCLAMATION          },
  202.     { IDS_BADICOCURFILE,        MB_OK | MB_ICONEXCLAMATION          },
  203.     { IDS_BADPALFILE,           MB_OK | MB_ICONEXCLAMATION          },
  204.     { IDS_CANTOPEN,             MB_OK | MB_ICONEXCLAMATION          },
  205.     { IDS_READERROR,            MB_OK | MB_ICONEXCLAMATION          },
  206.     { IDS_WRITEERROR,           MB_OK | MB_ICONEXCLAMATION          },
  207.     { IDS_CANTCREATE,           MB_OK | MB_ICONEXCLAMATION          },
  208.     { IDS_NOCLIPBOARDFORMAT,    MB_OK | MB_ICONEXCLAMATION          },
  209.     { IDS_NOCLIPBOARD,          MB_OK | MB_ICONEXCLAMATION          },
  210.     { IDS_CANTEDITIMAGE,        MB_OK | MB_ICONEXCLAMATION          },
  211.     { IDS_SAVEFILE,             MB_YESNOCANCEL | MB_ICONEXCLAMATION },
  212.     { IDS_ENTERANUMBER,         MB_OK | MB_ICONEXCLAMATION          },
  213.     { IDS_BADDEVICESIZE,        MB_OK | MB_ICONEXCLAMATION          },
  214.     { IDS_BADDEVICECOLORS,      MB_OK | MB_ICONEXCLAMATION          },
  215.     { IDS_NOTSUPPORT,           MB_OK | MB_ICONEXCLAMATION          },
  216.     { IDS_NOIMAGES,             MB_OK | MB_ICONEXCLAMATION          },
  217.     { IDS_BADBMPSIZE,           MB_OK | MB_ICONEXCLAMATION          }
  218. };
  219. INT gidCurrentDlg = 0;              // Current dialog id (null if none).
  220. INT gMenuSelected = 0;              // Currently selected menu item.
  221. CHAR gszHelpFile[CCHMAXPATH];       // Path to the help file.
  222. HHOOK ghhkMsgFilter;                // Hook handle for message filter func.
  223. FARPROC lpfnMsgFilterHookFunc;      // The message filter proc instance.
  224. /*
  225.  * Table that maps menu items to help context id's for them.
  226.  */
  227. HELPMAP gahmapMenu[] = {
  228.     {MENU_FILE_NEW,             HELPID_FILE_NEW                 },
  229.     {MENU_FILE_OPEN,            HELPID_FILE_OPEN                },
  230.     {MENU_FILE_SAVE,            HELPID_FILE_SAVE                },
  231.     {MENU_FILE_SAVEAS,          HELPID_FILE_SAVEAS              },
  232.     {MENU_FILE_LOADCOLORS,      HELPID_FILE_LOADCOLORS          },
  233.     {MENU_FILE_SAVECOLORS,      HELPID_FILE_SAVECOLORS          },
  234.     {MENU_FILE_DEFAULTCOLORS,   HELPID_FILE_DEFAULTCOLORS       },
  235.     {MENU_FILE_EXIT,            HELPID_FILE_EXIT                },
  236.     {MENU_EDIT_UNDO,            HELPID_EDIT_UNDO                },
  237.     {MENU_EDIT_RESTORE,         HELPID_EDIT_RESTORE             },
  238.     {MENU_EDIT_COPY,            HELPID_EDIT_COPY                },
  239.     {MENU_EDIT_PASTE,           HELPID_EDIT_PASTE               },
  240.     {MENU_EDIT_CLEAR,           HELPID_EDIT_CLEAR               },
  241.     {MENU_EDIT_NEWIMAGE,        HELPID_EDIT_NEWIMAGE            },
  242.     {MENU_EDIT_SELECTIMAGE,     HELPID_EDIT_SELECTIMAGE         },
  243.     {MENU_EDIT_DELETEIMAGE,     HELPID_EDIT_DELETEIMAGE         },
  244.     {MENU_OPTIONS_GRID,         HELPID_OPTIONS_GRID             },
  245.     {MENU_OPTIONS_BRUSH2,       HELPID_OPTIONS_BRUSH2           },
  246.     {MENU_OPTIONS_BRUSH3,       HELPID_OPTIONS_BRUSH3           },
  247.     {MENU_OPTIONS_BRUSH4,       HELPID_OPTIONS_BRUSH4           },
  248.     {MENU_OPTIONS_BRUSH5,       HELPID_OPTIONS_BRUSH5           },
  249.     {MENU_OPTIONS_SHOWCOLOR,    HELPID_OPTIONS_SHOWCOLOR        },
  250.     {MENU_OPTIONS_SHOWVIEW,     HELPID_OPTIONS_SHOWVIEW         },
  251.     {MENU_OPTIONS_SHOWTOOLBOX,  HELPID_OPTIONS_SHOWTOOLBOX      },
  252.     {MENU_HELP_CONTENTS,        HELPID_HELP_CONTENTS            },
  253.     {MENU_HELP_SEARCH,          HELPID_HELP_SEARCH              },
  254.     // No help for the About menu command.
  255.     {0,                         0                               }
  256. };
  257. /*
  258.  * Table that maps dialog ids to help context id's for them.
  259.  */
  260. HELPMAP gahmapDialog[] = {
  261.     // No help for the About dialog.
  262.     {DID_BITMAPSIZE,            HELPID_BITMAPSIZE               },
  263.     {DID_PASTEOPTIONS,          HELPID_PASTEOPTIONS             },
  264.     {DID_NEWCURSORIMAGE,        HELPID_NEWCURSORIMAGE           },
  265.     {DID_NEWICONIMAGE,          HELPID_NEWICONIMAGE             },
  266.     {DID_SELECTCURSORIMAGE,     HELPID_SELECTCURSORIMAGE        },
  267.     {DID_SELECTICONIMAGE,       HELPID_SELECTICONIMAGE          },
  268.     {DID_RESOURCETYPE,          HELPID_RESOURCETYPE             },
  269.     {DID_COMMONFILEOPEN,        HELPID_COMMONFILEOPEN           },
  270.     {DID_COMMONFILESAVE,        HELPID_COMMONFILESAVE           },
  271.     {DID_COMMONFILEOPENPAL,     HELPID_COMMONFILEOPENPAL        },
  272.     {DID_COMMONFILESAVEPAL,     HELPID_COMMONFILESAVEPAL        },
  273.     {DID_COMMONFILECHOOSECOLOR, HELPID_COMMONFILECHOOSECOLOR    },
  274.     {DID_TOOLBOX,               HELPID_TOOLBOX                  },
  275.     {DID_PROPBAR,               HELPID_PROPERTIESBAR            },
  276.     {DID_COLOR,                 HELPID_COLORPALETTE             },
  277.     {DID_VIEW,                  HELPID_VIEW                     },
  278.     {0,                         0                               }
  279. };
  280. /*
  281.  * Misc. globals -----------------------------------------------------------
  282.  */
  283. INT gcxWorkSpace;                   // Width of workspace window.
  284. INT gcyWorkSpace;                   // Height of workspace window.
  285. INT gZoomFactor;                    // Magnification factor of image.
  286. RECT grcPick;                       // The current picking rectangle.
  287. INT gcxPick;                        // Width of picking rectangle.
  288. INT gcyPick;                        // Height of picking rectangle.
  289. UINT ClipboardFormat;               // ID of private clipboard format.
  290. BOOL fStretchClipboardData = TRUE;  // TRUE to default to stretch on paste.
  291. INT iNewFileType;                   // New file type the user selected.
  292. INT gcyBorder;                      // System border height.
  293. INT gcyPropBar;                     // Height of PropBar window.
  294. WNDPROC lpfnPropBarDlgProc = NULL;  // Proc inst. of PropBar dialog proc.
  295. WNDPROC lpfnColorDlgProc = NULL;    // Proc inst. of Color palette dlg proc.