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.

146 lines
4.2 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. #define RECTWIDTH(rc) ((rc).right - (rc).left)
  9. #define RECTHEIGHT(rc) ((rc).bottom - (rc).top)
  10. __int64 liStart;
  11. __int64 liEnd;
  12. __int64 liFreq;
  13. __int64 liTotal = 0;
  14. DWORD dwCount = 0;
  15. TCHAR g_szTestWindow[MAX_PATH];
  16. void _GetProcFromComCtl32(FARPROC* ppfn, LPCSTR pszProc)
  17. {
  18. static HMODULE g_hinstCC = 0;
  19. if (!g_hinstCC)
  20. g_hinstCC = GetModuleHandle(TEXT("comctl32.dll"));
  21. if (g_hinstCC)
  22. *ppfn = GetProcAddress(g_hinstCC, pszProc);
  23. else
  24. {
  25. // Hmm, This is a fatal error.... Dialog and Quit?
  26. *ppfn = NULL;
  27. }
  28. }
  29. #define STUB_COMCTL32_ORD(_ret, _fn, _args, _nargs, _ord, _err) \
  30. _ret __stdcall _fn _args \
  31. { \
  32. static _ret (__stdcall *_pfn##_fn) _args = (_ret (__stdcall *)_args)-1; \
  33. if (_pfn##_fn == (_ret (__stdcall *)_args)-1) \
  34. _GetProcFromComCtl32((FARPROC*)&_pfn##_fn, (LPCSTR)_ord); \
  35. if (_pfn##_fn) \
  36. return _pfn##_fn _nargs; \
  37. return (_ret)_err; \
  38. }
  39. STUB_COMCTL32_ORD(BOOL, SetWindowSubclass, (HWND hWnd, SUBCLASSPROC pfnSubclass, UINT_PTR uIdSubclass, DWORD_PTR dwRefData), (hWnd, pfnSubclass, uIdSubclass, dwRefData), 410, FALSE);
  40. STUB_COMCTL32_ORD(LRESULT , DefSubclassProc, (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam), (hWnd, uMsg, wParam, lParam), 413, 0);
  41. LRESULT CALLBACK UxThemeTestHook(HWND hWnd, UINT uMsg, WPARAM wParam,
  42. LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
  43. {
  44. switch (uMsg)
  45. {
  46. case WM_PAINT:
  47. QueryPerformanceCounter((LARGE_INTEGER*)&liStart);
  48. LRESULT l = DefSubclassProc(hWnd, uMsg, wParam, lParam);
  49. QueryPerformanceCounter((LARGE_INTEGER*)&liEnd);
  50. if (dwCount < 100)
  51. {
  52. liTotal += liEnd - liStart;
  53. dwCount++;
  54. }
  55. return l;
  56. }
  57. return DefSubclassProc(hWnd, uMsg, wParam, lParam);
  58. }
  59. LRESULT CALLBACK HostWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  60. {
  61. switch (uMsg)
  62. {
  63. case WM_CREATE:
  64. {
  65. RECT rc;
  66. GetClientRect(hwnd, &rc);
  67. for (int i=0; i < 100; i++)
  68. {
  69. HWND hwndTest = CreateWindow(g_szTestWindow, TEXT("0"), WS_CHILD | WS_VISIBLE,
  70. (RECTWIDTH(rc) / 10) * (i % 10),
  71. (RECTHEIGHT(rc) / 10) * (i / 10),
  72. RECTWIDTH(rc) / 10,
  73. RECTHEIGHT(rc) / 10,
  74. hwnd, NULL, NULL, NULL);
  75. if (hwndTest)
  76. SetWindowSubclass(hwndTest, UxThemeTestHook, 1, NULL);
  77. }
  78. }
  79. break;
  80. case WM_CLOSE:
  81. {
  82. TCHAR sz[256];
  83. double fTimeFor100 = (float)(liTotal) / liFreq ;
  84. double fTimePer = (float)fTimeFor100 / 100;
  85. sprintf(sz, TEXT("The average time to render 100 %s is %f, The time to render 100 buttons is %f"), g_szTestWindow, fTimePer, fTimeFor100 );
  86. MessageBox(NULL, sz, TEXT("Time to render"), 0);
  87. PostQuitMessage(0);
  88. }
  89. break;
  90. }
  91. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  92. }
  93. int __cdecl main(int cch, char* ppv[])
  94. {
  95. lstrcpy(g_szTestWindow, TEXT("Button"));
  96. if (cch > 1)
  97. lstrcpy(g_szTestWindow, ppv[1]);
  98. QueryPerformanceFrequency((LARGE_INTEGER*)&liFreq);
  99. InitCommonControls();
  100. WNDCLASS wc = {0};
  101. wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  102. wc.lpfnWndProc = HostWndProc;
  103. wc.lpszClassName = TEXT("UxThemeTestHost");
  104. RegisterClass(&wc);
  105. CreateWindow(TEXT("UxThemeTestHost"), TEXT("UxTheme Perf Testing"), WS_VISIBLE | WS_OVERLAPPEDWINDOW, 0, 0, 600, 600, NULL, NULL, NULL, NULL);
  106. MSG msg;
  107. while (GetMessage(&msg, NULL, 0, 0))
  108. {
  109. DispatchMessage(&msg);
  110. }
  111. return 0;
  112. }