home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM User 1995 January / CDuser6Jan95.iso / WING / TIMEWING.CP_ / TIMEWING.CP
Text File  |  1994-06-25  |  22KB  |  886 lines

  1. /*
  2.  *    TIMEWING.CPP
  3.  *
  4.  *    (C) Copyright Microsoft Corp. 1994.  All rights reserved.
  5.  *
  6.  *    You have a royalty-free right to use, modify, reproduce and 
  7.  *    distribute the Sample Files (and/or any modified version) in 
  8.  *    any way you find useful, provided that you agree that 
  9.  *    Microsoft has no warranty obligations or liability for any 
  10.  *    Sample Application Files which are modified. 
  11.  *
  12.  *
  13.  *      History:                                                                                                                                   |
  14.  *              11-18-93 checker (from toddla's qa)
  15.  *                                                                                                                                                         |
  16.  */
  17.  
  18. #include <windows.h>
  19. #include<windowsx.h>
  20. #include <commdlg.h>
  21. #include "timewing.h"
  22.  
  23. #include<string.h>
  24. #include<mmsystem.h>
  25. #include<fstream.h>
  26. #include<strstrea.h>
  27.  
  28. #include"dib.hpp"
  29. #include <wing.h>
  30.  
  31.  
  32. /*----------------------------------------------------------------------------*\
  33. |                                                                               |
  34. |    g l o b a l   v a r i a b l e s                                            |
  35. |                                                                               |
  36. \*----------------------------------------------------------------------------*/
  37. static  char    szAppName[]="WinG Timer Sample";
  38. static    char    szAppFilter[]="Bitmaps\0*.bmp\0";
  39.  
  40. static    HINSTANCE hInstApp;
  41. HWND      hwndApp;
  42. static    HPALETTE  hpalApp;
  43. static    BOOL      fAppActive;
  44.  
  45. static int dx, dy;
  46.  
  47. PDIB pCurrentDIB;
  48. char aDescription[200];
  49. char aBuffer[5000];
  50.  
  51. struct
  52. {
  53.     BITMAPINFOHEADER Header;
  54.     RGBQUAD aColors[256];
  55. } Info;
  56.  
  57. int Iterations = 100;
  58. int StretchFactor = 1;
  59.  
  60. /*----------------------------------------------------------------------------
  61.  
  62. Timers
  63.  
  64. */
  65.  
  66. struct timing_result;
  67. typedef void timer( timing_result *pResults, HWND Window );
  68.  
  69. timer TimeStretchBlt;
  70. timer TimeStretchDIBits;
  71. timer TimeWinG;
  72.  
  73.  
  74. /*----------------------------------------------------------------------------
  75.  
  76. Timer structure.
  77.  
  78. */
  79.  
  80. void PrintTimingResults( ostream &Out );
  81.  
  82. struct timing_result
  83. {
  84.     DWORD Time;
  85.     timer *pTimer;
  86.     char const *pDescription;
  87. } aTimings[] =
  88. {
  89.     0, TimeStretchBlt, "StretchBlt",
  90.     0, TimeStretchDIBits, "StretchDIBits",
  91.     0, TimeWinG, "WinGStretchBlt",
  92. };
  93.  
  94. int const NumberOfTimings = sizeof(aTimings) / sizeof(aTimings[0]);
  95.     
  96.  
  97.  
  98.     
  99. #if defined(WIN32) || defined(_WIN32)
  100.     #define _export
  101. #endif
  102.  
  103. /*----------------------------------------------------------------------------*\
  104. |                                                                               |
  105. |    f u n c t i o n   d e f i n i t i o n s                                    |
  106. |                                                                               |
  107. \*----------------------------------------------------------------------------*/
  108.  
  109. LONG FAR PASCAL _export AppWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  110. int  ErrMsg (LPSTR sz,...);
  111. LONG AppCommand (HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  112.  
  113. void AppExit(void);
  114. BOOL AppIdle(void);
  115. void AppOpenFile(HWND hwnd, LPSTR szFileName);
  116.  
  117. /*----------------------------------------------------------------------------*\
  118. |    AppAbout( hDlg, uiMessage, wParam, lParam )                                |
  119. |                                                                               |
  120. |    Description:                                                               |
  121. |        This function handles messages belonging to the "About" dialog box.    |
  122. |        The only message that it looks for is WM_COMMAND, indicating the use   |
  123. |        has pressed the "OK" button.  When this happens, it takes down           |
  124. |        the dialog box.                                                        |
  125. |                                                                               |
  126. |    Arguments:                                                                   |
  127. |        hDlg            window handle of about dialog window                   |
  128. |        uiMessage        message number                                           |
  129. |        wParam            message-dependent                                       |
  130. |        lParam            message-dependent                                       |
  131. |                                                                               |
  132. |    Returns:                                                                   |
  133. |        TRUE if message has been processed, else FALSE                           |
  134. |                                                                               |
  135. \*----------------------------------------------------------------------------*/
  136. BOOL FAR PASCAL _export AppAbout(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
  137. {
  138.     switch (msg)
  139.     {
  140.         case WM_COMMAND:
  141.         if (LOWORD(wParam) == IDOK)
  142.             {
  143.                 EndDialog(hwnd,TRUE);
  144.             }
  145.             break;
  146.  
  147.         case WM_INITDIALOG:
  148.             return TRUE;
  149.     }
  150.     return FALSE;
  151. }
  152.  
  153. /*----------------------------------------------------------------------------*\
  154. |    AppInit( hInst, hPrev)                                                       |
  155. |                                                                               |
  156. |    Description:                                                               |
  157. |        This is called when the application is first loaded into               |
  158. |        memory.  It performs all initialization that doesn't need to be done   |
  159. |        once per instance.                                                       |
  160. |                                                                               |
  161. |    Arguments:                                                                   |
  162. |        hInstance        instance handle of current instance                    |
  163. |        hPrev            instance handle of previous instance                   |
  164. |                                                                               |
  165. |    Returns:                                                                   |
  166. |        TRUE if successful, FALSE if not                                       |
  167. |                                                                               |
  168. \*----------------------------------------------------------------------------*/
  169. BOOL AppInit(HINSTANCE hInst,HINSTANCE hPrev,int sw,LPSTR szCmdLine)
  170. {
  171.     WNDCLASS cls;
  172.  
  173.     /* Save instance handle for DialogBoxs */
  174.     hInstApp = hInst;
  175.  
  176.     if (!hPrev)
  177.     {
  178.         /*
  179.          *    Register a class for the main application window
  180.          */
  181.         cls.hCursor        = LoadCursor(NULL,IDC_ARROW);
  182.         cls.hIcon           = LoadIcon(hInst,"AppIcon");
  183.         cls.lpszMenuName   = "AppMenu";
  184.         cls.lpszClassName  = szAppName;
  185.         cls.hbrBackground  = (HBRUSH)(COLOR_WINDOW + 1);
  186.         cls.hInstance       = hInst;
  187.         cls.style           = CS_BYTEALIGNCLIENT | CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
  188.         cls.lpfnWndProc    = (WNDPROC)AppWndProc;
  189.         cls.cbWndExtra       = 0;
  190.         cls.cbClsExtra       = 0;
  191.  
  192.         if (!RegisterClass(&cls))
  193.             return FALSE;
  194.     }
  195.  
  196.     dx = 400;
  197.     dy = 400;
  198.  
  199.     hwndApp = CreateWindow (szAppName,      // Class name
  200.                             szAppName,                // Caption
  201.                             WS_OVERLAPPEDWINDOW,    // Style bits
  202.                             50, 50,        // Position
  203.                             dx+20,dy+75,            // Size
  204.                             (HWND)NULL,             // Parent window (no parent)
  205.                             (HMENU)NULL,            // use class menu
  206.                             hInst,                    // handle to window instance
  207.                             (LPSTR)NULL             // no params to pass on
  208.                            );
  209.     ShowWindow(hwndApp,sw);
  210.  
  211.  
  212.     HMENU Menu = GetMenu(hwndApp);
  213.     CheckMenuItem(Menu,MENU_1TO1,MF_CHECKED);
  214.  
  215.     //
  216.     // build the timing menu.
  217.     //
  218.  
  219.     HMENU hmenu = GetSubMenu(Menu, 3);
  220.     DeleteMenu(hmenu, MENU_TIME, MF_BYCOMMAND);
  221.  
  222.     for (int i=0; i<NumberOfTimings; i++)
  223.     {
  224.         AppendMenu(hmenu, 0, MENU_TIME+i, aTimings[i].pDescription);
  225.     }
  226.  
  227.     hpalApp = WinGCreateHalftonePalette();
  228.     AppOpenFile(hwndApp,"frog.bmp");
  229.  
  230.     if(!pCurrentDIB)
  231.     {
  232.         // we couldn't load froggie
  233.  
  234.         PostMessage(hwndApp,WM_COMMAND,MENU_OPEN,0);
  235.     }
  236.  
  237.     return TRUE;
  238. }
  239.  
  240.  
  241. /*----------------------------------------------------------------------------*\
  242. |    AppExit()                                       |
  243. |                                                                               |
  244. |    Description:                                                               |
  245. |    app is just about to exit, cleanup                       |
  246. |                                                                               |
  247. \*----------------------------------------------------------------------------*/
  248. void AppExit()
  249. {
  250. }
  251.  
  252. /*----------------------------------------------------------------------------*\
  253. |    WinMain( hInst, hPrev, lpszCmdLine, cmdShow )                               |
  254. |                                                                               |
  255. |    Description:                                                               |
  256. |        The main procedure for the App.  After initializing, it just goes       |
  257. |        into a message-processing loop until it gets a WM_QUIT message           |
  258. |        (meaning the app was closed).                                           |
  259. |                                                                               |
  260. |    Arguments:                                                                   |
  261. |        hInst            instance handle of this instance of the app            |
  262. |        hPrev            instance handle of previous instance, NULL if first    |
  263. |        szCmdLine        ->null-terminated command line                           |
  264. |        cmdShow         specifies how the window is initially displayed        |
  265. |                                                                               |
  266. |    Returns:                                                                   |
  267. |        The exit code as specified in the WM_QUIT message.                       |
  268. |                                                                               |
  269. \*----------------------------------------------------------------------------*/
  270. int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
  271. {
  272.     MSG     msg;
  273.  
  274.     /* Call initialization procedure */
  275.     if (!AppInit(hInst,hPrev,sw,