home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
cyber.net 2
/
cybernet2.ISO
/
wing
/
palanim.c_
/
palanim.c
Wrap
C/C++ Source or Header
|
1994-09-07
|
32KB
|
1,017 lines
/**************************************************************************
PALANIM.C - A palette animation demo for WinG
**************************************************************************/
/**************************************************************************
(C) Copyright 1994 Microsoft Corp. All rights reserved.
You have a royalty-free right to use, modify, reproduce and
distribute the Sample Files (and/or any modified version) in
any way you find useful, provided that you agree that
Microsoft has no warranty obligations or liability for any
Sample Application Files which are modified.
**************************************************************************/
#include <windows.h>
#include <commdlg.h>
#include <wing.h>
#include "palanim.h"
#include "..\utils\utils.h"
/*----------------------------------------------------------------------------*\
| |
| g l o b a l v a r i a b l e s |
| |
\*----------------------------------------------------------------------------*/
static char szAppName[]="WinG Palette Animation App";
static HINSTANCE hInstApp;
static HWND hwndApp;
static HPALETTE hpalApp;
static BOOL fAppActive;
static HDC hdcOffscreen;
void far * gpBits;
struct {
BITMAPINFOHEADER InfoHeader;
RGBQUAD ColorTable[256];
} gInfo;
int fAnimatePalette = 0; // Don't animate
int fIncludeStatic = 0; // Use the static color entries
enum {Red, Green, Blue} gWashColor = Red;
PALETTEENTRY aPalette[256];
extern HBITMAP ghBitmapMonochrome;
#ifdef WIN32
#define _export
#endif
//*** Setting up SYSPAL_NOSTATIC
#define NumSysColors (sizeof(SysPalIndex)/sizeof(SysPalIndex[1]))
#define rgbBlack RGB(0,0,0)
#define rgbWhite RGB(255,255,255)
//*** These are the GetSysColor display element identifiers
static int SysPalIndex[] = {
COLOR_ACTIVEBORDER,
COLOR_ACTIVECAPTION,
COLOR_APPWORKSPACE,
COLOR_BACKGROUND,
COLOR_BTNFACE,
COLOR_BTNSHADOW,
COLOR_BTNTEXT,
COLOR_CAPTIONTEXT,
COLOR_GRAYTEXT,
COLOR_HIGHLIGHT,
COLOR_HIGHLIGHTTEXT,
COLOR_INACTIVEBORDER,
COLOR_INACTIVECAPTION,
COLOR_MENU,
COLOR_MENUTEXT,
COLOR_SCROLLBAR,
COLOR_WINDOW,
COLOR_WINDOWFRAME,
COLOR_WINDOWTEXT
};
//*** This array translates the display elements to black and white
static COLORREF MonoColors[] = {
rgbBlack,
rgbWhite,
rgbWhite,
rgbWhite,
rgbWhite,
rgbBlack,
rgbBlack,
rgbBlack,
rgbBlack,
rgbBlack,
rgbWhite,
rgbWhite,
rgbWhite,
rgbWhite,
rgbBlack,
rgbWhite,
rgbWhite,
rgbBlack,
rgbBlack
};
//*** This array holds the old color mapping so we can restore them
static COLORREF OldColors[NumSysColors];
/*----------------------------------------------------------------------------*\
| |
| f u n c t i o n d e f i n i t i o n s |
| |
\*----------------------------------------------------------------------------*/
LONG FAR PASCAL _export AppWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
int ErrMsg (LPSTR sz,...);
LONG AppCommand (HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
void AppExit(void);
BOOL AppIdle(void);
/***************************************************************************
Internal functions for the animation
*/
void CreateWashPalette(void);
void DibCreateWash(BITMAPINFOHEADER far *Info, void far *pBits);
void DibHorizontalLine(BITMAPINFOHEADER far *Info, void far *pBits,
int y, char unsigned color);
/***************************************************************************
Sample functions from wing.hlp
*/
HDC Create100x100WinGDC(void);
void Destroy100x100WinGDC(HDC hWinGDC);
void AppActivate(BOOL fActive);
HPALETTE CreateIdentityPalette(RGBQUAD aRGB[], int nColors);
/*----------------------------------------------------------------------------*\
| AppAbout( hDlg, uiMessage, wParam, lParam ) |
| |
| Description: |
| This function handles messages belonging to the "About" dialog box. |
| The only message that it looks for is WM_COMMAND, indicating the use |
| has pressed the "OK" button. When this happens, it takes down |
| the dialog box. |
| |
| Arguments: |
| hDlg window handle of about dialog window |
| uiMessage message number |
| wParam message-dependent |
| lParam message-dependent |
| |
| Returns: |
| TRUE if message has been processed, else FALSE |
| |
\*----------------------------------------------------------------------------*/
BOOL FAR PASCAL _export AppAbout(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch (msg)
{
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
EndDialog(hwnd,TRUE);
}
break;
case WM_INITDIALOG:
return TRUE;
}
return FALSE;
}
/*----------------------------------------------------------------------------*\
| AppInit( hInst, hPrev) |
| |
| Description: |
| This is called when the application is first loaded into |
| memory. It performs all initialization that doesn't need to be done |
| once per instance. |
| |
| Arguments: |
| hInstance instance handle of current instance |
| hPrev instance handle of previous instance |
| |
| Returns: |
| TRUE if successful, FALSE if not |
| |
\*----------------------------------------------------------------------------*/
BOOL AppInit(HINSTANCE hInst,HINSTANCE hPrev,int sw,LPSTR szCmdLine)
{
WNDCLASS cls;
int dx,dy;
HBITMAP hbmOffscreen;
HMENU hMenu;
HDC Screen;
int PaletteDevice;
int nBitsPixel;
int nPlanes;
int nColorDepth;
/* Save instance handle for DialogBoxes */
hInstApp = hInst;
/* Refuse to run if this is a non-palettized device */
Screen = GetDC(0);
if (Screen)
{
PaletteDevice = GetDeviceCaps(Screen, RASTERCAPS) & RC_PALETTE;
nBitsPixel = GetDeviceCaps(Screen, BITSPIXEL);
nPlanes = GetDeviceCaps(Screen, PLANES);