home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_01 / GDISpeed / GDISpeed.cpp next >
Encoding:
C/C++ Source or Header  |  2000-05-17  |  2.3 KB  |  64 lines

  1. //-----------------------------------------------------------------------------------//
  2. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  3. //                             ISBN  0-13-086985-6                                   //
  4. //                                                                                   //
  5. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  6. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  7. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  8. //                                                                                   //
  9. //  FileName   : gdispeed.cpp                                                         //
  10. //  Description: GDI speed test demo, Chapter 1                                      //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. #define STRICT
  15. #define WIN32_LEAN_AND_MEAN
  16.  
  17. #include <windows.h>
  18. #include <tchar.h>
  19.  
  20. #include "..\..\include\timer.h"
  21. #include "resource.h"
  22.  
  23. int MyMessageBox(HWND hWnd, const TCHAR * text, const TCHAR * caption, DWORD style)
  24. {
  25.     MSGBOXPARAMS param;
  26.  
  27.     memset(& param, 0, sizeof(param));
  28.     param.cbSize      = sizeof(param);
  29.     param.hwndOwner   = hWnd;
  30.     param.hInstance   = GetModuleHandle(NULL);
  31.     param.lpszText    = text;
  32.     param.lpszCaption = caption;
  33.     param.dwStyle     = style | MB_USERICON;
  34.     param.lpszIcon    = MAKEINTRESOURCE(IDI_GRAPH);
  35.  
  36.     return MessageBoxIndirect(¶m);
  37. }
  38.  
  39.  
  40. int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR lpCmd, int nShow)
  41. {
  42.     KTimer timer;
  43.     TCHAR  mess[128];
  44.  
  45.     timer.Start(); 
  46.     Sleep(1000); 
  47.     unsigned cpuspeed10 = (unsigned)(timer.Stop()/100000);
  48.     
  49.     timer.Start(); 
  50.     CreateSolidBrush(RGB(0xAA, 0xAA, 0xAA));
  51.     unsigned time = (unsigned) timer.Stop();
  52.  
  53.     wsprintf(mess, _T("CPU speed       %d.%d mhz\n")
  54.         _T("KTimer overhead %d clock cycles\n")
  55.         _T("CreateSolidBrush %d clock cycles %d ns"),
  56.         cpuspeed10 / 10,  cpuspeed10 % 10,
  57.         (unsigned) timer.m_overhead,
  58.         time, time * 10000 / cpuspeed10);
  59.         
  60.     MyMessageBox(NULL, mess, _T("How fast is GDI?"), MB_OK);
  61.  
  62.     return 0;
  63. }
  64.