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.

857 lines
25 KiB

  1. //-------------------------------------------------------------------------//
  2. // NcPerf.cpp
  3. //-------------------------------------------------------------------------//
  4. #include "stdafx.h"
  5. #include "resource.h"
  6. #include <math.h>
  7. //--- globals
  8. HINSTANCE _hInst = NULL; // current instance
  9. HWND _hwndMain = NULL;
  10. HWND _hwndMdiClient = NULL;
  11. HWND _hwndCover = NULL;
  12. // resize test
  13. #define SAMPLE_SIZE 1501
  14. #define MOVE_ANGLE_INCR 20 // angle interval, in degrees
  15. SIZE _sizeOffset = {2,2}; // size offset of cover window relative to main window
  16. int _nRadius = 250; // radius
  17. int _cRep = 0; // current repitition
  18. int _nRot = 0; // angle of rotation, in degrees.
  19. //--- misc defs, helpers
  20. #define MAX_LOADSTRING 255
  21. #define MDICHILD_COUNT 6
  22. #define WC_NCPERFMAIN TEXT("NcPerfMainWnd")
  23. #define WC_NCPERFCOVERWND TEXT("NcPerfCoverWnd")
  24. #define WC_NCPERFMDICHILD TEXT("NcPerfMdiChild")
  25. #define RECTWIDTH(prc) ((prc)->right - (prc)->left)
  26. #define RECTHEIGHT(prc) ((prc)->bottom - (prc)->top)
  27. #define SAFE_DELETE(p) {delete (p); (p)=NULL;}
  28. #define WM_KICKRESIZE (WM_USER+101)
  29. #define WM_STOPTEST (WM_USER+102)
  30. //--- fn forwards
  31. BOOL RegisterClasses(HINSTANCE hInstance);
  32. void RunTests( HWND );
  33. BOOL InitInstance(HINSTANCE, int);
  34. LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
  35. LRESULT CALLBACK CoverWndProc(HWND, UINT, WPARAM, LPARAM);
  36. LRESULT CALLBACK MdiChildProc(HWND, UINT, WPARAM, LPARAM);
  37. LRESULT CALLBACK ResultsDlgProc(HWND, UINT, WPARAM, LPARAM);
  38. LRESULT CALLBACK NilDlgProc(HWND, UINT, WPARAM, LPARAM);
  39. ULONG AvgTime( ULONG, DWORD [], DWORD [][2], int, ULONG& );
  40. class CResizeResults;
  41. class CResizeData;
  42. CResizeData* _pData = NULL;
  43. //-------------------------------------------------------------------------//
  44. class CResizeData
  45. //-------------------------------------------------------------------------//
  46. {
  47. public:
  48. //-------------------------------------------------------------------------//
  49. CResizeData( HWND hwnd )
  50. : _hwnd(hwnd), _cSamples(-1), _cEraseP(0), _cNcPaintP(0),
  51. _cNcCalcR(0), _cNcPaintR(0), _cEraseR(0), _cPosChgR(0)
  52. {
  53. ZeroMemory( &_rcStart, sizeof(_rcStart) );
  54. ZeroMemory( &_rcStop, sizeof(_rcStop) );
  55. ZeroMemory( _rgdwSWP, sizeof(_rgdwSWP) );
  56. ZeroMemory( _rgdwEraseP, sizeof(_rgdwEraseP));
  57. ZeroMemory( _rgdwNcPaintP, sizeof(_rgdwNcPaintP));
  58. ZeroMemory( _rgdwNcCalcR, sizeof(_rgdwNcCalcR) );
  59. ZeroMemory( _rgdwNcPaintR, sizeof(_rgdwNcPaintR) );
  60. ZeroMemory( _rgdwEraseR, sizeof(_rgdwEraseR) );
  61. ZeroMemory( _rgdwPosChgR, sizeof(_rgdwPosChgR) );
  62. }
  63. //-------------------------------------------------------------------------//
  64. static BOOL Start( HWND hwnd )
  65. {
  66. SAFE_DELETE( _pData );
  67. if( (_pData = new CResizeData(hwnd)) == NULL )
  68. return FALSE;
  69. // set timer.
  70. if( TIMERR_NOERROR != timeBeginPeriod(_tc.wPeriodMin) )
  71. {
  72. SAFE_DELETE(_pData);
  73. return FALSE;
  74. }
  75. int cxScr = GetSystemMetrics( SM_CXSCREEN );
  76. int cyScr = GetSystemMetrics( SM_CYSCREEN );
  77. int cxWnd = MulDiv( cxScr, 9, 10 );
  78. int cyWnd = MulDiv( cyScr, 9, 10 );
  79. int x = (cxScr - cxWnd)/2;
  80. int y = (cyScr - cyWnd)/2;
  81. _nRadius = min(cxWnd, cyWnd)/4;
  82. SetWindowPos( hwnd, NULL, x, y, cxWnd, cyWnd,
  83. SWP_NOZORDER|SWP_NOACTIVATE );
  84. GetWindowRect( hwnd, &_pData->_rcStop );
  85. _cTicks = 0;
  86. _idTimer = timeSetEvent( 1, 0, TimerProc, 0, TIME_PERIODIC | TIME_CALLBACK_FUNCTION );
  87. if( !_idTimer )
  88. {
  89. timeEndPeriod(_tc.wPeriodMin);
  90. SAFE_DELETE(_pData);
  91. return FALSE;
  92. }
  93. return TRUE;
  94. }
  95. //-------------------------------------------------------------------------//
  96. static BOOL Stop( HWND hwnd )
  97. {
  98. static BOOL fInStop = FALSE;
  99. if( !fInStop )
  100. {
  101. fInStop = TRUE;
  102. if( _idTimer )
  103. {
  104. timeKillEvent( _idTimer );
  105. timeEndPeriod(_tc.wPeriodMin);
  106. _idTimer = 0;
  107. }
  108. if( _hwndCover )
  109. {
  110. if( _pData )
  111. GetWindowRect( hwnd, &_pData->_rcStop );
  112. DestroyWindow( _hwndCover );
  113. }
  114. if( _pData )
  115. {
  116. DialogBoxParam( _hInst, MAKEINTRESOURCE(IDD_RESULTS), hwnd,
  117. (DLGPROC)ResultsDlgProc, (LPARAM)_pData );
  118. SAFE_DELETE( _pData );
  119. }
  120. fInStop = FALSE;
  121. }
  122. return TRUE;
  123. }
  124. //-------------------------------------------------------------------------//
  125. static void CALLBACK TimerProc( UINT uID, UINT, DWORD, DWORD, DWORD )
  126. {
  127. _cTicks++;
  128. }
  129. //-------------------------------------------------------------------------//
  130. LPCTSTR Evaluate( INT& iEval )
  131. {
  132. ULONG nTimeMax = 0;
  133. static TCHAR szOut[MAX_PATH*4] = {0};
  134. LPCTSTR pszHdr = TEXT("Window rect: {%d,%d,%d,%d} = %d x %d\r\n")\
  135. TEXT("Test time (ms): %d\r\n")\
  136. TEXT("SetWindowPos iterations: %d\r\n");
  137. LPCTSTR pszStaticHdr = TEXT("Passive window msg stats:\r\n");
  138. LPCTSTR pszResizeHdr = TEXT("Resized window msg stats:\r\n");
  139. LPCTSTR pszMsgStats = TEXT("\t%s: %d msgs, %d-%d ms latency\r\n");
  140. switch( iEval )
  141. {
  142. case 0:
  143. wsprintf( szOut, pszHdr,
  144. _rcStop.left, _rcStop.top, _rcStop.right, _rcStop.bottom,
  145. RECTWIDTH(&_rcStop), RECTHEIGHT(&_rcStop),
  146. _cTicks, _cSamples );
  147. break;
  148. case 1:
  149. return pszStaticHdr;
  150. case 2:
  151. {
  152. DWORD nEraseTimeP0 = AvgTime( _cSamples, _rgdwSWP, _rgdwEraseP, 0, nTimeMax );
  153. DWORD nEraseTimePN = AvgTime( _cSamples, _rgdwSWP, _rgdwEraseP, 1, nTimeMax );
  154. wsprintf( szOut, pszMsgStats,
  155. TEXT("WM_ERASEBKGND"), _cEraseP, nEraseTimeP0, nEraseTimePN );
  156. break;
  157. }
  158. case 3:
  159. {
  160. DWORD nNcPaintTimeP0 = AvgTime( _cSamples, _rgdwSWP, _rgdwNcPaintP, 0, nTimeMax );
  161. DWORD nNcPaintTimePN = AvgTime( _cSamples, _rgdwSWP, _rgdwNcPaintP, 1, nTimeMax );
  162. wsprintf( szOut, pszMsgStats,
  163. TEXT("WM_NCPAINT"), _cNcPaintP, nNcPaintTimeP0, nNcPaintTimePN );
  164. break;
  165. }
  166. case 4:
  167. return pszResizeHdr;
  168. case 5:
  169. {
  170. DWORD nNcCalcTimeR0 = AvgTime( _cSamples, _rgdwSWP, _rgdwNcCalcR, 0, nTimeMax );
  171. DWORD nNcCalcTimeRN = AvgTime( _cSamples, _rgdwSWP, _rgdwNcCalcR, 1, nTimeMax );
  172. wsprintf( szOut, pszMsgStats,
  173. TEXT("WM_NCCALCSIZE"), _cNcCalcR, nNcCalcTimeR0, nNcCalcTimeRN );
  174. break;
  175. }
  176. case 6:
  177. {
  178. DWORD nPosChgTimeR0 = AvgTime( _cSamples, _rgdwSWP, _rgdwPosChgR, 0, nTimeMax );
  179. DWORD nPosChgTimeRN = AvgTime( _cSamples, _rgdwSWP, _rgdwPosChgR, 1, nTimeMax );
  180. wsprintf( szOut, pszMsgStats,
  181. TEXT("WM_WINDOWPOSCHANGED"), _cPosChgR, nPosChgTimeR0, nPosChgTimeRN );
  182. break;
  183. }
  184. case 7:
  185. {
  186. DWORD nEraseTimeR0 = AvgTime( _cSamples, _rgdwSWP, _rgdwEraseR, 0, nTimeMax );
  187. DWORD nEraseTimeRN = AvgTime( _cSamples, _rgdwSWP, _rgdwEraseR, 1, nTimeMax );
  188. wsprintf( szOut, pszMsgStats,
  189. TEXT("WM_ERASEBKGND"), _cEraseR, nEraseTimeR0, nEraseTimeRN );
  190. break;
  191. }
  192. case 8:
  193. {
  194. DWORD nNcPaintTimeR0 = AvgTime( _cSamples, _rgdwSWP, _rgdwNcPaintR, 0, nTimeMax );
  195. DWORD nNcPaintTimeRN = AvgTime( _cSamples, _rgdwSWP, _rgdwNcPaintR, 1, nTimeMax );
  196. wsprintf( szOut, pszMsgStats,
  197. TEXT("WM_NCPAINT"), _cNcPaintR, nNcPaintTimeR0, nNcPaintTimeRN );
  198. break;
  199. }
  200. default:
  201. return NULL;
  202. }
  203. return szOut;
  204. }
  205. public:
  206. HWND _hwnd;
  207. RECT _rcStart;
  208. RECT _rcStop;
  209. DWORD _cSamples; // number of SetWindowPos calls issued to resize the window.
  210. DWORD _cEraseP; // count of WM_ERASEBACKGROUNDs received by passive window
  211. DWORD _cNcPaintP; // count of WM_NCPAINTs received by passive window
  212. DWORD _cNcCalcR; // count of WM_NCCALCSIZEs received by resized window
  213. DWORD _cNcPaintR; // count of WM_NCPAINTs received by resized window
  214. DWORD _cEraseR; // count of WM_ERASEBACKGROUNDs received by resized window
  215. DWORD _cPosChgR; // count of WM_WINDOWPOSCHANGED received by resized window
  216. DWORD _rgdwSWP[SAMPLE_SIZE];
  217. DWORD _rgdwEraseP[SAMPLE_SIZE][2];
  218. DWORD _rgdwNcPaintP[SAMPLE_SIZE][2];
  219. DWORD _rgdwNcCalcR[SAMPLE_SIZE][2];
  220. DWORD _rgdwNcPaintR[SAMPLE_SIZE][2];
  221. DWORD _rgdwEraseR[SAMPLE_SIZE][2];
  222. DWORD _rgdwPosChgR[SAMPLE_SIZE][2];
  223. static TIMECAPS _tc;
  224. static UINT _idTimer;
  225. static LONG _cTicks;
  226. };
  227. TIMECAPS CResizeData::_tc = {0};
  228. UINT CResizeData::_idTimer = 0;
  229. LONG CResizeData::_cTicks = 0;
  230. //-------------------------------------------------------------------------//
  231. int APIENTRY WinMain(HINSTANCE hInstance,
  232. HINSTANCE hPrevInstance,
  233. LPSTR lpCmdLine,
  234. int nCmdShow)
  235. {
  236. // TODO: Place code here.
  237. MSG msg;
  238. HACCEL hAccelTable;
  239. // Perform application initialization:
  240. if (!InitInstance (hInstance, nCmdShow))
  241. {
  242. return FALSE;
  243. }
  244. hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_NCPERF);
  245. // Main message loop:
  246. while (GetMessage(&msg, NULL, 0, 0))
  247. {
  248. if ( !TranslateMDISysAccel(_hwndMdiClient, &msg) &&
  249. !TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  250. {
  251. TranslateMessage(&msg);
  252. DispatchMessage(&msg);
  253. }
  254. }
  255. return msg.wParam;
  256. }
  257. //-------------------------------------------------------------------------//
  258. BOOL RegisterClasses(HINSTANCE hInstance)
  259. {
  260. WNDCLASSEX wcex;
  261. ZeroMemory( &wcex, sizeof(wcex) );
  262. wcex.cbSize = sizeof(WNDCLASSEX);
  263. wcex.style = CS_HREDRAW | CS_VREDRAW;
  264. wcex.lpfnWndProc = (WNDPROC)MainWndProc;
  265. wcex.hInstance = hInstance;
  266. wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_NCPERF);
  267. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  268. wcex.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
  269. wcex.lpszMenuName = MAKEINTRESOURCE(IDC_NCPERF);
  270. wcex.lpszClassName = WC_NCPERFMAIN;
  271. wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
  272. if( !RegisterClassEx(&wcex) )
  273. return FALSE;
  274. wcex.style = 0;
  275. wcex.lpfnWndProc = (WNDPROC)CoverWndProc;
  276. wcex.hInstance = hInstance;
  277. wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_NCPERF);
  278. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  279. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  280. wcex.lpszMenuName = MAKEINTRESOURCE(IDR_COVER);
  281. wcex.lpszClassName = WC_NCPERFCOVERWND;
  282. wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
  283. if( !RegisterClassEx(&wcex) )
  284. return FALSE;
  285. ZeroMemory( &wcex, sizeof(wcex) );
  286. wcex.cbSize = sizeof(WNDCLASSEX);
  287. wcex.style = CS_HREDRAW | CS_VREDRAW;
  288. wcex.lpfnWndProc = (WNDPROC)MdiChildProc;
  289. wcex.hInstance = hInstance;
  290. wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_NCPERF);
  291. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  292. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  293. wcex.lpszClassName = WC_NCPERFMDICHILD;
  294. wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
  295. if( !RegisterClassEx(&wcex) )
  296. return FALSE;
  297. return TRUE;
  298. }
  299. //-------------------------------------------------------------------------//
  300. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  301. {
  302. _hInst = hInstance; // Store instance handle in our global variable
  303. // Initialize global strings
  304. if( !RegisterClasses(hInstance) )
  305. return FALSE;
  306. if( TIMERR_NOERROR != timeGetDevCaps( &CResizeData::_tc, sizeof(CResizeData::_tc) ) )
  307. return FALSE;
  308. HWND hwnd = CreateWindow( WC_NCPERFMAIN,
  309. TEXT("NcPerf Test Window"),
  310. WS_OVERLAPPEDWINDOW,
  311. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
  312. NULL, NULL, _hInst, NULL);
  313. if( hwnd )
  314. {
  315. ShowWindow(hwnd, nCmdShow);
  316. UpdateWindow(hwnd);
  317. }
  318. return TRUE;
  319. }
  320. //-------------------------------------------------------------------------//
  321. BOOL Deg2Rad( double* pval )
  322. {
  323. if( *pval >= 0 && *pval <= 360 )
  324. {
  325. *pval = ((*pval) * 22)/(7 * 180);
  326. return TRUE;
  327. }
  328. return FALSE;
  329. }
  330. //-------------------------------------------------------------------------//
  331. void PinCover( HWND hwndMain )
  332. {
  333. if( IsWindow(_hwndCover) )
  334. {
  335. RECT rc;
  336. GetWindowRect( hwndMain, &rc );
  337. InflateRect( &rc, -_sizeOffset.cx, -_sizeOffset.cx );
  338. SetWindowPos( _hwndCover, hwndMain, rc.left, rc.top,
  339. RECTWIDTH(&rc), RECTHEIGHT(&rc),
  340. SWP_NOZORDER|SWP_NOACTIVATE );
  341. }
  342. }
  343. //-------------------------------------------------------------------------//
  344. BOOL CirclePtNext( IN OUT INT* pnAngle /*degrees*/, OUT POINT& pt, OUT OPTIONAL BOOL* pfRoll )
  345. {
  346. if( *pnAngle < 0 || *pnAngle >= 360 )
  347. {
  348. *pnAngle = 0;
  349. if( pfRoll )
  350. *pfRoll = TRUE;
  351. }
  352. // increase angle
  353. double nAngle = _nRot + MOVE_ANGLE_INCR;
  354. // establish new x, y
  355. if( Deg2Rad( &nAngle ) )
  356. {
  357. pt.x = (long)(_nRadius * cos( nAngle ));
  358. pt.y = (long)(_nRadius * sin( nAngle ));
  359. (*pnAngle) += MOVE_ANGLE_INCR;
  360. return TRUE;
  361. }
  362. return FALSE;
  363. }
  364. //-------------------------------------------------------------------------//
  365. ULONG AvgTime( ULONG cSamples, DWORD rgdwStart[], DWORD rgdwStop[][2], int iStop, ULONG& nTimeMax )
  366. {
  367. ULONG dwTime = 0;
  368. for( ULONG i = 0, cnt = 0; i < cSamples; i++ )
  369. {
  370. if( rgdwStop[i][iStop] && rgdwStart[i] &&
  371. rgdwStop[i][iStop] > rgdwStart[i] )
  372. {
  373. dwTime += (rgdwStop[i][iStop] - rgdwStart[i]);
  374. cnt++;
  375. if( rgdwStop[i][iStop] > nTimeMax )
  376. nTimeMax = rgdwStop[i][iStop];
  377. }
  378. }
  379. return cnt ? (dwTime / cnt) : 0;
  380. }
  381. //-------------------------------------------------------------------------//
  382. inline void LogMsg( DWORD rgdwMsg[][2], ULONG& cnt )
  383. {
  384. DWORD nTick = CResizeData::_cTicks;
  385. if(!rgdwMsg[_pData->_cSamples][0] )
  386. rgdwMsg[_pData->_cSamples][0] = nTick;
  387. rgdwMsg[_pData->_cSamples][1] = nTick;
  388. cnt++;
  389. }
  390. //-------------------------------------------------------------------------//
  391. void RunTests( HWND hwndMain )
  392. {
  393. HWND hwnd = CreateWindow( WC_NCPERFCOVERWND,
  394. TEXT("NcPerf Cover Window"),
  395. WS_OVERLAPPEDWINDOW,
  396. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
  397. NULL, NULL, _hInst, NULL);
  398. if( hwnd )
  399. {
  400. _cRep = 0;
  401. PinCover( hwndMain );
  402. ShowWindow( hwnd, SW_SHOWNORMAL );
  403. UpdateWindow( hwnd );
  404. if( CResizeData::Start( hwndMain ) )
  405. {
  406. for( int i=0; i < SAMPLE_SIZE; i++ )
  407. {
  408. PostMessage( hwndMain, WM_KICKRESIZE, 0, 0 );
  409. }
  410. PostMessage( hwndMain, WM_STOPTEST, 0, 0 );
  411. }
  412. else
  413. {
  414. DestroyWindow( hwnd );
  415. }
  416. }
  417. }
  418. //-------------------------------------------------------------------------//
  419. inline void SWAP( long& x, long& y )
  420. {
  421. long z = x;
  422. x = y;
  423. y = z;
  424. }
  425. //-------------------------------------------------------------------------//
  426. inline void NORMALIZERECT( LPRECT prc )
  427. {
  428. if( prc->right < prc->left )
  429. SWAP( prc->right, prc->left );
  430. if( prc->bottom < prc->top )
  431. SWAP( prc->bottom, prc->top );
  432. }
  433. enum RECTVERTEX
  434. {
  435. LEFTTOP,
  436. RIGHTTOP,
  437. LEFTBOTTOM,
  438. RIGHTBOTTOM,
  439. };
  440. void _MoveVertex( RECTVERTEX v, IN OUT RECT& rc, const RECT& rcMain, const POINT& pt, IN OUT ULONG& fSwp )
  441. {
  442. rc.left = rcMain.left + _sizeOffset.cx;
  443. rc.top = rcMain.top + _sizeOffset.cy;
  444. rc.right = rcMain.right - _sizeOffset.cx;
  445. rc.bottom = rcMain.bottom - _sizeOffset.cy;
  446. switch( v )
  447. {
  448. case LEFTTOP:
  449. rc.left = rcMain.left + _nRadius + pt.x;
  450. rc.top = rcMain.top + _nRadius + pt.y;
  451. fSwp |= SWP_NOMOVE;
  452. break;
  453. case RIGHTTOP:
  454. rc.right = rcMain.right - (_nRadius + pt.x);
  455. rc.top = rcMain.top + _nRadius + pt.y;
  456. break;
  457. case LEFTBOTTOM:
  458. rc.left = rcMain.left + _nRadius + pt.x;
  459. rc.bottom = rcMain.bottom - (_nRadius + pt.y);
  460. break;
  461. case RIGHTBOTTOM:
  462. rc.right = rcMain.right - (_nRadius + pt.x);
  463. rc.bottom = rcMain.bottom - (_nRadius + pt.y);
  464. break;
  465. }
  466. }
  467. //-------------------------------------------------------------------------//
  468. void ResizeCover( HWND hwndMain )
  469. {
  470. POINT pt;
  471. BOOL fRollover = FALSE;
  472. CirclePtNext( &_nRot, pt, &fRollover );
  473. RECT rc, rcMain;
  474. GetWindowRect( hwndMain, &rcMain );
  475. GetWindowRect( _hwndCover, &rc );
  476. ULONG nFlags = SWP_NOZORDER|SWP_NOACTIVATE;
  477. if( fRollover )
  478. {
  479. _cRep++;
  480. PinCover( hwndMain );
  481. }
  482. RECTVERTEX v = LEFTTOP;
  483. int phase = _cRep % 20;
  484. if( phase < 5 )
  485. {
  486. v = LEFTTOP;
  487. }
  488. else if( phase < 10 )
  489. {
  490. v = RIGHTTOP;
  491. }
  492. else if( phase < 15 )
  493. {
  494. v = LEFTBOTTOM;
  495. }
  496. else
  497. {
  498. v = RIGHTBOTTOM;
  499. }
  500. _MoveVertex( v, rc, rcMain, pt, nFlags );
  501. if( _pData->_cSamples + 1 >= SAMPLE_SIZE )
  502. {
  503. CResizeData::Stop( hwndMain );
  504. }
  505. else
  506. {
  507. _pData->_rgdwSWP[_pData->_cSamples] = CResizeData::_cTicks;
  508. SetWindowPos( _hwndCover, NULL, rc.left, rc.top, RECTWIDTH(&rc), RECTHEIGHT(&rc),
  509. SWP_NOZORDER|SWP_NOACTIVATE );
  510. _pData->_cSamples++;
  511. }
  512. }
  513. //-------------------------------------------------------------------------//
  514. LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  515. {
  516. LRESULT lRet = 0L;
  517. switch (uMsg)
  518. {
  519. case WM_KICKRESIZE:
  520. ResizeCover( hwnd );
  521. break;
  522. case WM_STOPTEST:
  523. CResizeData::Stop( hwnd );
  524. break;
  525. case WM_ERASEBKGND:
  526. lRet = DefWindowProc( hwnd, uMsg, wParam, lParam );
  527. if( _pData )
  528. {
  529. LogMsg( _pData->_rgdwEraseP, _pData->_cEraseP );
  530. }
  531. break;
  532. case WM_NCPAINT:
  533. lRet = DefWindowProc( hwnd, uMsg, wParam, lParam );
  534. if( _pData )
  535. {
  536. LogMsg( _pData->_rgdwNcPaintP, _pData->_cNcPaintP );
  537. }
  538. break;
  539. case WM_PAINT:
  540. {
  541. PAINTSTRUCT ps;
  542. HDC hdc;
  543. hdc = BeginPaint(hwnd, &ps);
  544. EndPaint(hwnd, &ps);
  545. break;
  546. }
  547. case WM_TIMER:
  548. {
  549. if( _hwndCover )
  550. {
  551. ResizeCover( hwnd );
  552. }
  553. }
  554. break;
  555. case WM_CREATE:
  556. {
  557. _hwndMain = hwnd;
  558. #if 0
  559. RECT rc;
  560. GetClientRect( hwnd, &rc );
  561. CLIENTCREATESTRUCT ccs = {0};
  562. ccs.idFirstChild = 1;
  563. _hwndMdiClient = CreateWindow( TEXT("MDICLIENT"), TEXT(""),
  564. WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL,
  565. rc.left, rc.top, RECTWIDTH(&rc), RECTHEIGHT(&rc),
  566. hwnd, NULL, _hInst, &ccs );
  567. if( _hwndMdiClient )
  568. {
  569. MDICREATESTRUCT mcs = {0};
  570. mcs.szClass = WC_NCPERFMDICHILD;
  571. mcs.szTitle = TEXT("Nc Perf");
  572. mcs.hOwner = _hInst;
  573. mcs.x = CW_USEDEFAULT; mcs.y = 0; mcs.cx = CW_USEDEFAULT; mcs.cy = 0;
  574. mcs.style = WS_OVERLAPPEDWINDOW;
  575. mcs.lParam = 0;
  576. for( int i = 0; i < MDICHILD_COUNT; i++ )
  577. SendMessage( _hwndMdiClient, WM_MDICREATE, 0, (LPARAM)&mcs);
  578. SendMessage( _hwndMdiClient, WM_MDITILE, MDITILE_HORIZONTAL, 0 );
  579. return 0;
  580. }
  581. return -1;
  582. #else
  583. return 0;
  584. #endif 0
  585. }
  586. case WM_COMMAND:
  587. // Parse the menu selections:
  588. switch (LOWORD(wParam))
  589. {
  590. case ID_START:
  591. RunTests( hwnd );
  592. break;
  593. case IDM_STOP:
  594. CResizeData::Stop( hwnd );
  595. if( IsWindow( _hwndCover ) )
  596. DestroyWindow( _hwndCover );
  597. break;
  598. case IDM_ABOUT:
  599. DialogBox(_hInst, (LPCTSTR)IDD_ABOUTBOX, hwnd, (DLGPROC)NilDlgProc);
  600. break;
  601. case IDM_EXIT:
  602. DestroyWindow(hwnd);
  603. break;
  604. default:
  605. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  606. }
  607. break;
  608. case WM_DESTROY:
  609. CResizeData::Stop(hwnd);
  610. PostQuitMessage(0);
  611. break;
  612. default:
  613. return _hwndMdiClient ?
  614. DefFrameProc(hwnd, _hwndMdiClient, uMsg, wParam, lParam) :
  615. DefWindowProc(hwnd, uMsg, wParam, lParam);
  616. }
  617. return lRet;
  618. }
  619. //-------------------------------------------------------------------------//
  620. LRESULT CALLBACK CoverWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  621. {
  622. LRESULT lRet = 0L;
  623. switch (uMsg)
  624. {
  625. case WM_CREATE:
  626. _hwndCover = hwnd;
  627. return 0;
  628. case WM_COMMAND:
  629. switch( LOWORD(wParam) )
  630. {
  631. case IDM_STOP:
  632. CResizeData::Stop( hwnd );
  633. if( IsWindow( _hwndCover ) )
  634. DestroyWindow( _hwndCover );
  635. break;
  636. }
  637. break;
  638. case WM_ERASEBKGND:
  639. lRet = DefWindowProc( hwnd, uMsg, wParam, lParam );
  640. if( _pData )
  641. {
  642. LogMsg( _pData->_rgdwEraseR, _pData->_cEraseR );
  643. }
  644. break;
  645. case WM_NCCALCSIZE:
  646. lRet = DefWindowProc( hwnd, uMsg, wParam, lParam );
  647. if( _pData )
  648. {
  649. LogMsg( _pData->_rgdwNcCalcR, _pData->_cNcCalcR );
  650. }
  651. break;
  652. case WM_NCPAINT:
  653. lRet = DefWindowProc( hwnd, uMsg, wParam, lParam );
  654. if( _pData )
  655. {
  656. LogMsg( _pData->_rgdwNcPaintR, _pData->_cNcPaintR );
  657. }
  658. break;
  659. case WM_PAINT:
  660. {
  661. PAINTSTRUCT ps;
  662. HDC hdc = BeginPaint(hwnd, &ps);
  663. EndPaint(hwnd, &ps);
  664. break;
  665. }
  666. case WM_WINDOWPOSCHANGED:
  667. lRet = DefWindowProc( hwnd, uMsg, wParam, lParam );
  668. if( _pData )
  669. {
  670. LogMsg( _pData->_rgdwPosChgR, _pData->_cPosChgR );
  671. }
  672. break;
  673. case WM_NCDESTROY:
  674. _hwndCover = NULL;
  675. break;
  676. default:
  677. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  678. }
  679. return lRet;
  680. }
  681. //-------------------------------------------------------------------------//
  682. LRESULT CALLBACK MdiChildProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  683. {
  684. return DefMDIChildProc(hwnd, uMsg, wParam, lParam);
  685. }
  686. //-------------------------------------------------------------------------//
  687. LRESULT CALLBACK ResultsDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  688. {
  689. if( WM_INITDIALOG == uMsg )
  690. {
  691. if( lParam )
  692. {
  693. LPCTSTR pszRes;
  694. int i;
  695. for( i = 0; (pszRes = ((CResizeData*)lParam)->Evaluate(i)) != NULL; i++ )
  696. {
  697. SendDlgItemMessage( hwnd, IDC_RESULTS, EM_SETSEL, -1, 0 );
  698. SendDlgItemMessage( hwnd, IDC_RESULTS, EM_REPLACESEL, FALSE, (LPARAM)pszRes );
  699. }
  700. }
  701. }
  702. return NilDlgProc( hwnd, uMsg, wParam, lParam );
  703. }
  704. //-------------------------------------------------------------------------//
  705. LRESULT CALLBACK NilDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  706. {
  707. switch (uMsg)
  708. {
  709. case WM_INITDIALOG:
  710. return TRUE;
  711. case WM_COMMAND:
  712. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  713. {
  714. EndDialog(hDlg, LOWORD(wParam));
  715. return TRUE;
  716. }
  717. break;
  718. }
  719. return FALSE;
  720. }