home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Hits 1995 June / Image.iso / demos / woodruff / wing / timewing.cp_ / timewing.cp
Encoding:
Text File  |  1994-06-26  |  21.4 KB  |  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,szCmdLine))
  276.     return FALSE;
  277.  
  278.     /*
  279.      * Polling messages from event queue
  280.      */
  281.     for (;;)
  282.     {
  283.         if (PeekMessage(&msg, NULL, 0, 0,PM_REMOVE))
  284.         {
  285.             if (msg.message == WM_QUIT)
  286.                 break;
  287.  
  288.             TranslateMessage(&msg);
  289.             DispatchMessage(&msg);
  290.         }
  291.         else
  292.     {
  293.         if (AppIdle())
  294.                 WaitMessage();
  295.         }
  296.     }
  297.  
  298.     AppExit();
  299.     return msg.wParam;
  300. }
  301.  
  302. /*----------------------------------------------------------------------------*\
  303. |    AppIdle()                                       |
  304. |                                                                               |
  305. |    Description:                                                               |
  306. |    place to do idle time stuff.                           |
  307. |                                                                               |
  308. |    Returns:                                       |
  309. |    RETURN TRUE IF YOU HAVE NOTHING TO DO OTHERWISE YOUR APP WILL BE A       |
  310. |    CPU PIG!                                   |
  311. \*----------------------------------------------------------------------------*/
  312. BOOL AppIdle()
  313. {
  314.     if (fAppActive)
  315.     {
  316.     //
  317.     // we are the foreground app.
  318.     //
  319.     return TRUE;        // nothing to do.
  320.     }
  321.     else
  322.     {
  323.     //
  324.     // we are a background app.
  325.     //
  326.     return TRUE;        // nothing to do.
  327.     }
  328. }
  329.  
  330. /*----------------------------------------------------------------------------*\
  331. |    AppOpenFile()                                   |
  332. |                                                                               |
  333. |    Description:                                                               |
  334. |    open a file stupid                               |
  335. |                                                                               |
  336. \*----------------------------------------------------------------------------*/
  337. void AppOpenFile(HWND hwnd, LPSTR szFileName)
  338. {
  339.     PDIB pDIB = DibOpenFile(szFileName);
  340.  
  341.     if(pDIB)
  342.     {
  343.         if(pCurrentDIB)
  344.         {
  345.             DibFree(pCurrentDIB);
  346.         }
  347.  
  348.         pCurrentDIB = pDIB;
  349.         DibMapToPalette(pCurrentDIB,hpalApp);
  350.  
  351.         hmemcpy(&Info,pDIB,sizeof(Info));
  352.  
  353.         DibSetUsage(pCurrentDIB,hpalApp,DIB_PAL_COLORS);
  354.  
  355.         ostrstream Out(aDescription,sizeof(aDescription));
  356.  
  357.         while(*szFileName)
  358.         {
  359.             Out<<*szFileName++;        // can't use far * and near stream, lame
  360.         }
  361.         
  362.         Out<<" - "<<DibWidth(pDIB)<<" x "<<DibHeight(pDIB)<<ends;
  363.  
  364.         SetWindowText(hwnd,aDescription);
  365.     }
  366. }
  367.  
  368. /*----------------------------------------------------------------------------*\
  369. |    AppPaint(hwnd, hdc)                                                        |
  370. |                                                                               |
  371. |    Description:                                                               |
  372. |        The paint function.  Right now this does nothing.                       |
  373. |                                                                               |
  374. |    Arguments:                                                                   |
  375. |        hwnd             window painting into                                   |
  376. |        hdc              display context to paint to                           |
  377. |                                                                               |
  378. |    Returns:                                                                   |
  379. |        nothing                                                                |
  380. |                                                                               |
  381. \*----------------------------------------------------------------------------*/
  382. AppPaint (HWND hwnd, HDC hdc)
  383. {
  384.     RECT    rc;
  385.  
  386.     GetClientRect(hwnd,&rc);
  387.  
  388.     SetTextColor(hdc,GetSysColor(COLOR_WINDOWTEXT));
  389.     SetBkColor(hdc,GetSysColor(COLOR_WINDOW));
  390.  
  391.     return TRUE;
  392. }
  393.  
  394. /*----------------------------------------------------------------------------*\
  395. |    AppWndProc( hwnd, uiMessage, wParam, lParam )                               |
  396. |                                                                               |
  397. |    Description:                                                               |
  398. |        The window proc for the app's main (tiled) window.    This processes all |
  399. |        of the parent window's messages.                                       |
  400. |                                                                               |
  401. \*----------------------------------------------------------------------------*/
  402. LONG FAR PASCAL _export AppWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
  403. {
  404.     PAINTSTRUCT ps;
  405.     HDC hdc;
  406.     BOOL f;
  407.  
  408.     switch (msg)
  409.     {
  410.         case WM_CREATE:
  411.         break;
  412.  
  413.         case WM_ACTIVATEAPP:
  414.         fAppActive = (BOOL)wParam;
  415.         break;
  416.  
  417.         case WM_TIMER:
  418.             break;
  419.  
  420.         case WM_ERASEBKGND:
  421.             break;
  422.  
  423.         case WM_INITMENU:
  424.             break;
  425.  
  426.         case WM_COMMAND:
  427.             return AppCommand(hwnd,msg,wParam,lParam);
  428.  
  429.     case WM_DESTROY:
  430.             PostQuitMessage(0);
  431.             break;
  432.  
  433.         case WM_CLOSE:
  434.         break;
  435.  
  436.         case WM_SIZE:
  437.         {
  438.             static FirstTime = 1;
  439.  
  440.             if(FirstTime)
  441.             {
  442.                 FirstTime = 0;
  443.                 break;
  444.             }
  445.             else
  446.             {
  447.                 return 0;
  448.                 break;
  449.             }
  450.         }
  451.  
  452.         case WM_PALETTECHANGED:
  453.         if ((HWND)wParam == hwnd)
  454.         break;
  455.  
  456.         // fall through to WM_QUERYNEWPALETTE
  457.  
  458.     case WM_QUERYNEWPALETTE:
  459.         hdc = GetDC(hwnd);
  460.  
  461.         if (hpalApp)
  462.         SelectPalette(hdc, hpalApp, FALSE);
  463.  
  464.         f = RealizePalette(hdc);
  465.         ReleaseDC(hwnd,hdc);
  466.  
  467.         if (f)
  468.         InvalidateRect(hwnd,NULL,TRUE);
  469.  
  470.         return f;
  471.  
  472.         case WM_PAINT:
  473.         hdc = BeginPaint(hwnd,&ps);
  474.         AppPaint (hwnd,hdc);
  475.             EndPaint(hwnd,&ps);
  476.             return 0L;
  477.     }
  478.     return DefWindowProc(hwnd,msg,wParam,lParam);
  479. }
  480.  
  481. /*----------------------------------------------------------------------------*\
  482. |    AppCommand(hwnd, msg, wParam, lParam )                       |
  483. |                                                                               |
  484. |    Description:                                                               |
  485. |    handles WM_COMMAND messages for the main window (hwndApp)           |
  486. |        of the parent window's messages.                                       |
  487. |                                                                               |
  488. \*----------------------------------------------------------------------------*/
  489. LONG AppCommand (HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
  490. {
  491.     static char achFileName[128];
  492.     OPENFILENAME ofn;
  493.     ostrstream Out(aBuffer,sizeof(aBuffer));
  494.  
  495.     switch(wParam)
  496.     {
  497.         case MENU_ABOUT:
  498.         DialogBox(hInstApp,"AppAbout",hwnd,AppAbout);
  499.             break;
  500.  
  501.         case MENU_TIMEALL:
  502.         {
  503.             HCURSOR Arror = SetCursor(0);
  504.  
  505.             for(int Counter = 0;Counter < NumberOfTimings;Counter++)
  506.             {
  507.                 SetWindowText(hwndApp,aTimings[Counter].pDescription);
  508.  
  509.                 (*aTimings[Counter].pTimer)(aTimings+Counter,hwnd);
  510.             }
  511.  
  512.             SetCursor(Arror);
  513.             SetWindowText(hwndApp,aDescription);
  514.  
  515.             PrintTimingResults(Out);
  516.             MessageBox(0,aBuffer,"Timing Results",MB_OK);
  517.  
  518.             break;
  519.         }
  520.  
  521.         case MENU_1TO1:
  522.         case MENU_1TO2:
  523.         {
  524.             HMENU Menu = GetMenu(hwnd);
  525.  
  526.             // uncheck current selection
  527.             CheckMenuItem(Menu,MENU_1TO1 - 1 + StretchFactor,MF_UNCHECKED);
  528.  
  529.             // get the stretch factor
  530.             StretchFactor = 1 + wParam - MENU_1TO1;
  531.  
  532.             Iterations = (StretchFactor == 1) ? 100 : 20;
  533.  
  534.             CheckMenuItem(Menu,wParam,MF_CHECKED);
  535.  
  536.             // @todo should clear timing results
  537.         
  538.             break;
  539.         }
  540.  
  541.         default:
  542.         {
  543.             int Index = (int)LOWORD(wParam) - MENU_TIME;
  544.  
  545.             if(Index >= 0 && Index < NumberOfTimings)
  546.             {
  547.                 HCURSOR Arror = SetCursor(0);
  548.  
  549.                 SetWindowText(hwndApp,aTimings[Index].pDescription);
  550.                 
  551.                 (*aTimings[Index].pTimer)(aTimings+Index,hwnd);
  552.  
  553.                 SetCursor(Arror);
  554.                 SetWindowText(hwndApp,aDescription);
  555.             }
  556.  
  557.             PrintTimingResults(Out);
  558.             MessageBox(0,aBuffer,"Timing Results",MB_OK);
  559.             InvalidateRect(hwnd,0,TRUE);
  560.             UpdateWindow(hwnd);
  561.  
  562.             break;
  563.         }
  564.  
  565.     case MENU_OPEN:
  566.     {
  567.             /* prompt user for file to open */
  568.             ofn.lStructSize = sizeof(OPENFILENAME);
  569.             ofn.hwndOwner = hwnd;
  570.             ofn.hInstance = NULL;
  571.             ofn.lpstrFilter = szAppFilter;
  572.             ofn.lpstrCustomFilter = NULL;
  573.             ofn.nMaxCustFilter = 0;
  574.             ofn.nFilterIndex = 0;
  575.             ofn.lpstrFile = achFileName;
  576.             ofn.nMaxFile = sizeof(achFileName);
  577.             ofn.lpstrFileTitle = NULL;
  578.             ofn.nMaxFileTitle = 0;
  579.             ofn.lpstrInitialDir = NULL;
  580.             ofn.lpstrTitle = NULL;
  581.             ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
  582.             ofn.nFileOffset = 0;
  583.             ofn.nFileExtension = 0;
  584.             ofn.lpstrDefExt = NULL;
  585.             ofn.lCustData = 0;
  586.             ofn.lpfnHook = NULL;
  587.             ofn.lpTemplateName = NULL;
  588.  
  589.             if(GetOpenFileName(&ofn))
  590.             {
  591.                 AppOpenFile(hwnd,achFileName);
  592.                 break;
  593.             }
  594.     }
  595.  
  596.             break;
  597.  
  598.         case MENU_EXIT:
  599.             PostMessage(hwnd,WM_CLOSE,0,0L);
  600.             break;
  601.     }
  602.     return 0L;
  603. }
  604.  
  605.  
  606.  
  607.  
  608. /*----------------------------------------------------------------------------*\
  609. |    ErrMsg - Opens a Message box with a error message in it.  The user can       |
  610. |             select the OK button to continue                                   |
  611. \*----------------------------------------------------------------------------*/
  612. int ErrMsg (LPSTR sz,...)
  613. {
  614.     char ach[128];
  615.  
  616.     wvsprintf (ach,sz,(LPSTR)(&sz+1));     /* Format the string */
  617.     MessageBox(hwndApp,ach,szAppName,MB_OK|MB_ICONEXCLAMATION|MB_TASKMODAL);
  618.     return FALSE;
  619. }
  620.  
  621. /*****************************************************************************
  622.  *
  623.  * dprintf() is called by the DPF macro if DEBUG is defined at compile time.
  624.  *
  625.  * The messages will be send to COM1: like any debug message. To
  626.  * enable debug output, add the following to WIN.INI :
  627.  *
  628.  * [debug]
  629.  * QA=1
  630.  *
  631.  ****************************************************************************/
  632.  
  633. #ifdef DEBUG
  634.  
  635. #define MODNAME "QA"
  636.  
  637. #if !defined(WIN32) || !defined(_WIN32)
  638.     #define lstrcatA lstrcat
  639.     #define lstrcpyA lstrcpy
  640.     #define lstrlenA lstrlen
  641.     #define wvsprintfA        wvsprintf
  642.     #define GetProfileIntA    GetProfileInt
  643.     #define OutputDebugStringA OutputDebugString
  644. #endif
  645.  
  646. #define _WINDLL
  647. #include <stdarg.h>
  648.  
  649. void FAR CDECL dprintf(LPSTR szFormat, ...)
  650. {
  651.     char ach[128];
  652.     va_list va;
  653.  
  654.     static BOOL fDebug = -1;
  655.  
  656.     if (fDebug == -1)
  657.     fDebug = GetProfileIntA("Debug", MODNAME, TRUE);
  658.  
  659.     if (!fDebug)
  660.         return;
  661.  
  662.     lstrcpyA(ach, MODNAME ": ");
  663.     va_start(va, szFormat);
  664.     wvsprintfA(ach+lstrlenA(ach),szFormat,(LPSTR)va);
  665.     va_end(va);
  666.     lstrcatA(ach, "\r\n");
  667.  
  668.     OutputDebugStringA(ach);
  669. }
  670.  
  671. #endif
  672.  
  673.  
  674. void PrintTimingResults( ostream &Out )
  675. {
  676.     int CurrentOffset = 0;
  677.  
  678.     for(int Counter = 0;Counter < NumberOfTimings;Counter++)
  679.     {
  680.         Out<<aTimings[Counter].pDescription
  681.             <<":\t";
  682.  
  683.         if(aTimings[Counter].Time)
  684.         {
  685.             Out<<(Iterations / (aTimings[Counter].Time / 1000.0));
  686.         }
  687.         else
  688.         {
  689.             Out<<"N/A";
  690.         }
  691.         
  692.         Out<<" per Second"<<endl;
  693.     }
  694.  
  695.     Out<<ends;
  696. }
  697.  
  698.  
  699.  
  700. /*----------------------------------------------------------------------------
  701.  
  702. StretchBlt
  703.  
  704. */
  705.  
  706. void TimeStretchBlt( timing_result *pResult, HWND Window )
  707. {
  708.     int Counter;
  709.     HDC Screen = GetDC(Window);
  710.     DWORD Time;
  711.  
  712.     // setup here
  713.  
  714.     HDC Buffer = CreateCompatibleDC(Screen);
  715.     HBITMAP Bitmap = CreateCompatibleBitmap(Screen,DibWidth(pCurrentDIB),
  716.                         DibHeight(pCurrentDIB));
  717.     Bitmap = SelectBitmap(Buffer,Bitmap);
  718.  
  719.     HPALETTE OldPalette = SelectPalette(Buffer,hpalApp,FALSE);
  720.     SelectPalette(Screen,hpalApp,FALSE);
  721.     RealizePalette(Screen);
  722.     RealizePalette(Buffer);
  723.     SetStretchBltMode(Buffer,COLORONCOLOR);
  724.  
  725.     StretchDIBits(Buffer,0,0,DibWidth(pCurrentDIB),DibHeight(pCurrentDIB),
  726.         0,0,DibWidth(pCurrentDIB),DibHeight(pCurrentDIB),DibPtr(pCurrentDIB),
  727.         DibInfo(pCurrentDIB),DIB_PAL_COLORS,SRCCOPY);
  728.  
  729.     SetStretchBltMode(Screen,COLORONCOLOR);
  730.     
  731.     Time = timeGetTime();
  732.  
  733.     for(Counter = 0;Counter < Iterations;Counter++)
  734.     {
  735.         // some drivers, like the #9GXE cheat on BitBlt to increase
  736.         // their winbench scores...a SetPixel usually makes them
  737.         // play fair.
  738.  
  739.         SetPixel(Screen,0,0,0);
  740.  
  741.         StretchBlt(Screen,Counter,Counter,
  742.             StretchFactor * DibWidth(pCurrentDIB),
  743.             StretchFactor * DibHeight(pCurrentDIB),
  744.             Buffer,0,0,DibWidth(pCurrentDIB),DibHeight(pCurrentDIB),
  745.             SRCCOPY);
  746.     }
  747.  
  748.     Time = timeGetTime() - Time;
  749.  
  750.     pResult->Time = Time;
  751.  
  752.     // clean up
  753.  
  754.     SelectPalette(Buffer,OldPalette,FALSE);
  755.     SelectPalette(Screen,OldPalette,FALSE);
  756.     DeleteObject(SelectBitmap(Buffer,Bitmap));
  757.     DeleteDC(Buffer);
  758.  
  759.     ReleaseDC(Window,Screen);
  760. }
  761.  
  762.  
  763. /*----------------------------------------------------------------------------
  764.  
  765. WinGStretchBlt
  766.  
  767. */
  768.  
  769. void TimeWinG( timing_result *pResult, HWND Window )
  770. {
  771.     int Counter;
  772.     HDC Screen = GetDC(Window);
  773.     DWORD Time;
  774.  
  775.     void far *pBits;
  776.  
  777.     // setup here
  778.  
  779.     HDC WinGDC = WinGCreateDC();
  780.  
  781.     WinGRecommendDIBFormat((BITMAPINFO far *)&Info);
  782.  
  783.     Info.Header.biWidth = DibWidth(pCurrentDIB);
  784.  
  785.     // keep orientation
  786.     Info.Header.biHeight *= DibHeight(pCurrentDIB);
  787.  
  788.     HBITMAP WinGBitmap = WinGCreateBitmap(WinGDC,(BITMAPINFO far *)&Info,
  789.                                 &pBits);
  790.  
  791.     WinGBitmap = SelectBitmap(WinGDC,WinGBitmap);
  792.  
  793.     HPALETTE OldPalette = SelectPalette(Screen,hpalApp,FALSE);
  794.     RealizePalette(Screen);
  795.  
  796.     SetStretchBltMode(WinGDC,COLORONCOLOR);
  797.  
  798.     // set orientation positive to blt bottom-up DIB into WinGBitmap
  799.  
  800.     Info.Header.biHeight = DibHeight(pCurrentDIB);
  801.  
  802.     StretchDIBits(WinGDC,0,0,DibWidth(pCurrentDIB),DibHeight(pCurrentDIB),
  803.         0,0,DibWidth(pCurrentDIB),DibHeight(pCurrentDIB),DibPtr(pCurrentDIB),
  804.         (BITMAPINFO far *)&Info,DIB_RGB_COLORS,SRCCOPY);
  805.  
  806.     _fmemset(pBits,0xff,10);
  807.  
  808.     // WinG does a lot of work on the first blt, do it outside the loop
  809.  
  810.     WinGStretchBlt(Screen,0,0,
  811.             StretchFactor * DibWidth(pCurrentDIB),
  812.             StretchFactor * DibHeight(pCurrentDIB),
  813.             WinGDC,0,0,DibWidth(pCurrentDIB),
  814.             DibHeight(pCurrentDIB));
  815.  
  816.     Time = timeGetTime();
  817.  
  818.     for(Counter = 0;Counter < Iterations;Counter++)
  819.     {
  820.         // this SetPixel is here for fairness, see comment in TimeBitBlt        
  821.         SetPixel(Screen,0,0,0);
  822.  
  823.         WinGStretchBlt(Screen,Counter,Counter,
  824.             StretchFactor * DibWidth(pCurrentDIB),
  825.             StretchFactor * DibHeight(pCurrentDIB),
  826.             WinGDC,0,0,DibWidth(pCurrentDIB),
  827.             DibHeight(pCurrentDIB));
  828.     }
  829.  
  830.     Time = timeGetTime() - Time;
  831.  
  832.     pResult->Time = Time;
  833.  
  834.     // clean up
  835.  
  836.     SelectPalette(Screen,OldPalette,FALSE);
  837.     DeleteObject(SelectBitmap(WinGDC,WinGBitmap));
  838.     DeleteDC(WinGDC);
  839.  
  840.     ReleaseDC(Window,Screen);
  841. }
  842.  
  843.  
  844.  
  845. /*----------------------------------------------------------------------------
  846.  
  847. StretchDIBits
  848.  
  849. */
  850.  
  851. void TimeStretchDIBits( timing_result *pResult, HWND Window )
  852. {
  853.     int Counter;
  854.     HDC Screen = GetDC(Window);
  855.     DWORD Time;
  856.  
  857.     // setup here
  858.  
  859.     HPALETTE OldPalette = SelectPalette(Screen,hpalApp,FALSE);
  860.     RealizePalette(Screen);
  861.  
  862.     Time = timeGetTime();
  863.  
  864.     for(Counter = 0;Counter < Iterations;Counter++)
  865.     {
  866.         // this SetPixel is here for fairness, see comment in TimeBitBlt        
  867.         SetPixel(Screen,0,0,0);
  868.  
  869.         StretchDIBits(Screen,Counter,Counter,
  870.             StretchFactor * DibWidth(pCurrentDIB),
  871.             StretchFactor * DibHeight(pCurrentDIB),
  872.             0,0,DibWidth(pCurrentDIB),DibHeight(pCurrentDIB),
  873.             DibPtr(pCurrentDIB),DibInfo(pCurrentDIB),DIB_PAL_COLORS,SRCCOPY);
  874.     }
  875.  
  876.     Time = timeGetTime() - Time;
  877.  
  878.     pResult->Time = Time;
  879.  
  880.     // clean up
  881.  
  882.     SelectPalette(Screen,OldPalette,FALSE);
  883.  
  884.     ReleaseDC(Window,Screen);
  885. }
  886.