Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.1 KiB

  1. // DumpIcon.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include "stdio.h"
  5. #include "commctrl.h"
  6. #include "uxtheme.h"
  7. #include <tmschema.h>
  8. int __cdecl main(int cch, char* ppv[])
  9. {
  10. __int64 liStart;
  11. __int64 liEnd;
  12. __int64 liFreq;
  13. QueryPerformanceFrequency((LARGE_INTEGER*)&liFreq);
  14. InitCommonControls();
  15. CreateWindow(TEXT("Static"), TEXT(""), WS_POPUP, 0,0,0,0,0,0,0,0);
  16. HTHEME g_hTheme9Grid = OpenThemeData(NULL, L"Button");
  17. HTHEME g_hThemeSolid = OpenThemeData(NULL, L"Progress");
  18. HDC hdc = CreateCompatibleDC(NULL);
  19. HBITMAP hbmp = CreateBitmap(100, 100, 1, 32, NULL);
  20. SelectObject(hdc, hbmp);
  21. RECT rc = {0,0,76,24}; // default size of a button on 12x10 96dpi system
  22. //---- time button face vs. 9-grid ----
  23. QueryPerformanceCounter((LARGE_INTEGER*)&liStart);
  24. for (int i = 0; i < 100; i++)
  25. {
  26. DrawFrameControl(hdc, &rc, DFC_BUTTON, DFCS_BUTTONPUSH);
  27. }
  28. QueryPerformanceCounter((LARGE_INTEGER*)&liEnd);
  29. double fTimeForBaseline = (float)(liEnd - liStart) / liFreq;
  30. QueryPerformanceCounter((LARGE_INTEGER*)&liStart);
  31. for (int i = 0; i < 100; i++)
  32. {
  33. DrawThemeBackground(g_hTheme9Grid, hdc, 1, 1, &rc, 0);
  34. }
  35. QueryPerformanceCounter((LARGE_INTEGER*)&liEnd);
  36. double fTimeFor9Grid = (float)(liEnd - liStart) / liFreq;
  37. QueryPerformanceCounter((LARGE_INTEGER*)&liStart);
  38. //---- time solid rect, direct vs. uxtheme ----
  39. for (int i = 0; i < 500; i++)
  40. {
  41. //---- part=3 is the "chunk" part ----
  42. DrawThemeBackground(g_hThemeSolid, hdc, 3, 1, &rc, 0);
  43. }
  44. QueryPerformanceCounter((LARGE_INTEGER*)&liEnd);
  45. double fTimeForSolid = (float)(liEnd - liStart) / liFreq;
  46. QueryPerformanceCounter((LARGE_INTEGER*)&liStart);
  47. for (int i = 0; i < 500; i++)
  48. {
  49. COLORREF crOld = SetBkColor(hdc, RGB(0,0,0xff));
  50. ExtTextOut(hdc,0,0,ETO_OPAQUE,&rc,NULL,0,NULL);
  51. //--- restore the color as normal API service would have to ----
  52. SetBkColor(hdc, crOld);
  53. }
  54. QueryPerformanceCounter((LARGE_INTEGER*)&liEnd);
  55. double fTimeForGDI = (float)(liEnd - liStart) / liFreq;
  56. for (int i = 0; i < 500; i++)
  57. {
  58. HBRUSH hbr = CreateSolidBrush(RGB(0,0,0xff));
  59. HBRUSH hold = (HBRUSH)SelectObject(hdc, hbr);
  60. FillRect(hdc, &rc, hbr);
  61. SelectObject(hdc, hold);
  62. DeleteObject(hbr);
  63. }
  64. QueryPerformanceCounter((LARGE_INTEGER*)&liEnd);
  65. double fTimeForGDI2 = (float)(liEnd - liStart) / liFreq;
  66. TCHAR sz[256];
  67. sprintf(sz, TEXT("The total time to render a 9 Grid, 100 times is %f,\n"
  68. "which is %fx slower than baseline of %f. To render a solid color takes %f,\n"
  69. "which is %fx Slower than using ExtTextOut with a time of %f or \n"
  70. "%fx slower than PatBlt which with a time of %f"),
  71. fTimeFor9Grid, fTimeFor9Grid / fTimeForBaseline, fTimeForBaseline,
  72. fTimeForSolid, fTimeForSolid / fTimeForGDI, fTimeForGDI,
  73. fTimeForSolid / fTimeForGDI2, fTimeForGDI2);
  74. MessageBox(NULL, sz, TEXT("UxTheme times vs Raw GDI calls"), 0);
  75. return 0;
  76. }