home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD-ROM User 1995 January
/
CDuser6Jan95.iso
/
DYNASTY
/
WING
/
TIMEWING.CP_
/
TIMEWING.CP
Wrap
Text File
|
1994-06-25
|
22KB
|
886 lines
/*
* TIMEWING.CPP
*
* (C) Copyright Microsoft Corp. 1994. 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.
*
*
* History: |
* 11-18-93 checker (from toddla's qa)
* |
*/
#include <windows.h>
#include<windowsx.h>
#include <commdlg.h>
#include "timewing.h"
#include<string.h>
#include<mmsystem.h>
#include<fstream.h>
#include<strstrea.h>
#include"dib.hpp"
#include <wing.h>
/*----------------------------------------------------------------------------*\
| |
| g l o b a l v a r i a b l e s |
| |
\*----------------------------------------------------------------------------*/
static char szAppName[]="WinG Timer Sample";
static char szAppFilter[]="Bitmaps\0*.bmp\0";
static HINSTANCE hInstApp;
HWND hwndApp;
static HPALETTE hpalApp;
static BOOL fAppActive;
static int dx, dy;
PDIB pCurrentDIB;
char aDescription[200];
char aBuffer[5000];
struct
{
BITMAPINFOHEADER Header;
RGBQUAD aColors[256];
} Info;
int Iterations = 100;
int StretchFactor = 1;
/*----------------------------------------------------------------------------
Timers
*/
struct timing_result;
typedef void timer( timing_result *pResults, HWND Window );
timer TimeStretchBlt;
timer TimeStretchDIBits;
timer TimeWinG;
/*----------------------------------------------------------------------------
Timer structure.
*/
void PrintTimingResults( ostream &Out );
struct timing_result
{
DWORD Time;
timer *pTimer;
char const *pDescription;
} aTimings[] =
{
0, TimeStretchBlt, "StretchBlt",
0, TimeStretchDIBits, "StretchDIBits",
0, TimeWinG, "WinGStretchBlt",
};
int const NumberOfTimings = sizeof(aTimings) / sizeof(aTimings[0]);
#if defined(WIN32) || defined(_WIN32)
#define _export
#endif
/*----------------------------------------------------------------------------*\
| |
| 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);
void AppOpenFile(HWND hwnd, LPSTR szFileName);
/*----------------------------------------------------------------------------*\
| 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;
/* Save instance handle for DialogBoxs */
hInstApp = hInst;
if (!hPrev)
{
/*
* Register a class for the main application window
*/
cls.hCursor = LoadCursor(NULL,IDC_ARROW);
cls.hIcon = LoadIcon(hInst,"AppIcon");
cls.lpszMenuName = "AppMenu";
cls.lpszClassName = szAppName;
cls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
cls.hInstance = hInst;
cls.style = CS_BYTEALIGNCLIENT | CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
cls.lpfnWndProc = (WNDPROC)AppWndProc;
cls.cbWndExtra = 0;
cls.cbClsExtra = 0;
if (!RegisterClass(&cls))
return FALSE;
}
dx = 400;
dy = 400;
hwndApp = CreateWindow (szAppName, // Class name
szAppName, // Caption
WS_OVERLAPPEDWINDOW, // Style bits
50, 50, // Position
dx+20,dy+75, // Size
(HWND)NULL, // Parent window (no parent)
(HMENU)NULL, // use class menu
hInst, // handle to window instance
(LPSTR)NULL // no params to pass on
);
ShowWindow(hwndApp,sw);
HMENU Menu = GetMenu(hwndApp);
CheckMenuItem(Menu,MENU_1TO1,MF_CHECKED);
//
// build the timing menu.
//
HMENU hmenu = GetSubMenu(Menu, 3);
DeleteMenu(hmenu, MENU_TIME, MF_BYCOMMAND);
for (int i=0; i<NumberOfTimings; i++)
{
AppendMenu(hmenu, 0, MENU_TIME+i, aTimings[i].pDescription);
}
hpalApp = WinGCreateHalftonePalette();
AppOpenFile(hwndApp,"frog.bmp");
if(!pCurrentDIB)
{
// we couldn't load froggie
PostMessage(hwndApp,WM_COMMAND,MENU_OPEN,0);
}
return TRUE;
}
/*----------------------------------------------------------------------------*\
| AppExit() |
| |
| Description: |
| app is just about to exit, cleanup |
| |
\*----------------------------------------------------------------------------*/
void AppExit()
{
}
/*----------------------------------------------------------------------------*\
| WinMain( hInst, hPrev, lpszCmdLine, cmdShow ) |
| |
| Description: |
| The main procedure for the App. After initializing, it just goes |
| into a message-processing loop until it gets a WM_QUIT message |
| (meaning the app was closed). |
| |
| Arguments: |
| hInst instance handle of this instance of the app |
| hPrev instance handle of previous instance, NULL if first |
| szCmdLine ->null-terminated command line |
| cmdShow specifies how the window is initially displayed |
| |
| Returns: |
| The exit code as specified in the WM_QUIT message. |
| |
\*----------------------------------------------------------------------------*/
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
{
MSG msg;
/* Call initialization procedure */
if (!AppInit(hInst,hPrev,sw,