home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_01 / GDISpeed / GDISpeed.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-16  |  3.4 KB  |  112 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.h                                                             //
  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_TU);
  35.  
  36.     return MessageBoxIndirect(¶m);
  37. }
  38.  
  39. const void * LoadRes(HMODULE hModule, int resid, const TCHAR * typ, int & size)
  40. {
  41.     HRSRC   hRes = FindResource(hModule, MAKEINTRESOURCE(resid), typ);
  42.  
  43.     if ( hRes==NULL )
  44.         return NULL;
  45.  
  46.     HGLOBAL hGlb = LoadResource(hModule, hRes);
  47.  
  48.     if ( hGlb==NULL )
  49.         return NULL;
  50.  
  51.     size = SizeofResource(hModule, hRes);
  52.  
  53.     return LockResource(hGlb);
  54. }
  55.  
  56. const void * LoadOneIcon(HMODULE hModule, int resid, int width, int height, int & size)
  57. {
  58.     const void * pResource = LoadRes(hModule, resid, RT_GROUP_ICON, size); 
  59.  
  60.     if ( pResource==NULL )
  61.         return NULL;
  62.  
  63.     int nID = LookupIconIdFromDirectoryEx((BYTE *) pResource, TRUE, width, height, LR_DEFAULTCOLOR); 
  64.  
  65.     return LoadRes(hModule, nID, RT_ICON, size);
  66. }
  67.  
  68.  
  69. int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR lpCmd, int nShow)
  70. {
  71.     KTimer timer;
  72.     TCHAR  mess[128];
  73.  
  74.     timer.Start(); 
  75.     Sleep(1000); 
  76.     unsigned cpuspeed10 = (unsigned)(timer.Stop()/100000);
  77.     
  78.     timer.Start(); 
  79.     CreateSolidBrush(RGB(0xAA, 0xAA, 0xAA));
  80.     unsigned time = (unsigned) timer.Stop();
  81.  
  82.     wsprintf(mess, _T("CPU speed       %d.%d mhz\n")
  83.         _T("KTimer overhead %d clock cycles\n")
  84.         _T("CreateSolidBrush %d clock cycles %d ns"),
  85.         cpuspeed10 / 10,  cpuspeed10 % 10,
  86.         (unsigned) timer.m_overhead,
  87.         time, time * 10000 / cpuspeed10);
  88.         
  89.     MyMessageBox(NULL, mess, _T("How fast is GDI?"), MB_OK);
  90.  
  91.     int size;
  92.  
  93.     const BYTE * pData = (const BYTE *) LoadOneIcon(hInst, IDI_TU, 16, 16, size);
  94.  
  95.     if ( pData )
  96.     {
  97.         for (int i=0; i<size; i++)
  98.         {
  99.             char temp[16];
  100.  
  101.             wsprintf(temp, "0x%02x, ", pData[i]);
  102.             OutputDebugString(temp);
  103.             if ( (i % 16)==15 )
  104.                 OutputDebugString("\n");
  105.         }
  106.  
  107.         OutputDebugString("\n");
  108.     }
  109.  
  110.     return 0;
  111. }
  112.