1 //////////////////////////////////////////////
\r
3 // Definitions for the CMainWindow class
\r
8 #include "resource.h"
\r
11 CMainWindow::CMainWindow() : m_nTestMessages(0), m_nTestWindows(0)
\r
15 CMainWindow::~CMainWindow()
\r
19 HWND CMainWindow::Create(CWnd* pParent /*= 0*/)
\r
21 CString str = _T("Main Window");
\r
23 // Create the main window
\r
24 return CreateEx(WS_EX_TOPMOST, NULL, str, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
\r
25 20 , 50, 400, 300, pParent, NULL);
\r
28 void CMainWindow::CreateTestWindows(int nWindows)
\r
30 m_nTestWindows = nWindows;
\r
32 for (int i = 0 ; i < nWindows ; i++)
\r
34 // Create the test windows
\r
35 TestWindowPtr pTestWindow = new CTestWindow();
\r
36 m_pCTestWindows.push_back(pTestWindow);
\r
37 m_pCTestWindows[i]->CreateWin(i);
\r
41 void CMainWindow::OnCreate()
\r
43 CRect r = GetClientRect();
\r
44 DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL;
\r
46 // Create an Edit window over the client area of the main window
\r
47 m_Edit.CreateEx(0L, _T("Edit"), _T(""), dwStyle, r.left, r.top, r.right - r.left, r.bottom - r.top,
\r
50 // Set a default font
\r
51 m_Font.CreateFont(16, 0, 0, 0, FW_DONTCARE, 0, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
\r
52 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_MODERN, _T("Courier New"));
\r
53 m_Edit.SendMessage(WM_SETFONT, (WPARAM)m_Font.GetHandle(), 0);
\r
56 void CMainWindow::OnInitialUpdate()
\r
58 CMyDialog MyDialog(IDD_DIALOG1, this);
\r
62 void CMainWindow::OnSize()
\r
64 CRect r = GetClientRect();
\r
66 // Resize the edit window when the main window is resized
\r
67 m_Edit.MoveWindow(0, 0, r.right - r.left, r.bottom - r.top, TRUE);
\r
70 void CMainWindow::OnAllWindowsCreated()
\r
73 str.Format(_T("%d Windows Created"), m_nTestWindows);
\r
75 SendText(_T("Ready to run performance test"));
\r
77 int nResult = MessageBox(_T("Start the Performance Test?"), _T("Ready"), MB_OKCANCEL | MB_ICONEXCLAMATION);
\r
78 if (nResult != IDOK) return;
\r
82 // Loop the performance test
\r
84 while(nResult == IDYES)
\r
86 nResult = MessageBox(_T("Run Test Again?"), _T("Ready"), MB_YESNO | MB_ICONEXCLAMATION);
\r
87 if (nResult != IDYES) break;
\r
91 SendText(_T("Testing complete"));
\r
94 void CMainWindow::PerformanceTest()
\r
101 str.Format(str, _T("Sending %d Messages"), m_nTestMessages);
\r
104 // Choose a Window handle(HWND) to send the messages to
\r
105 HWND hWnd = m_pCTestWindows[(m_nTestWindows-1)/2]->GetHwnd();
\r
107 // Store the starting time
\r
108 DWORD tStart = ::GetTickCount();
\r
110 // Send the messages
\r
111 while(nMessages++ < m_nTestMessages)
\r
112 lr = ::SendMessage(hWnd, WM_TESTMESSAGE, 0, 0);
\r
114 // Calculate the time the messages took to send
\r
115 DWORD tEnd = ::GetTickCount();
\r
116 DWORD mSeconds = tEnd - tStart;
\r
118 // Display the results
\r
119 str.Format(_T("%d milliseconds to process %d messages"), mSeconds, m_nTestMessages);
\r
122 str.Format(_T("%d total messages sent\n"), lr);
\r
125 MessageBox(str, _T("Info"), MB_OK);
\r
128 void CMainWindow::SendText(LPCTSTR str)
\r
130 // Send text to the Edit window
\r
131 m_Edit.SendMessage(EM_REPLACESEL, (WPARAM)FALSE, (LPARAM)str);
\r
132 m_Edit.SendMessage(EM_REPLACESEL, (WPARAM)FALSE, (LPARAM)_T("\r\n"));
\r
133 m_Edit.SendMessage(EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
\r
139 LRESULT CMainWindow::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
141 static int nWindowsCreated = 0;
\r
146 // End the program.
\r
147 ::PostQuitMessage(0);
\r
154 case WM_WINDOWCREATED:
\r
155 // Message recieved when a test window is created
\r
156 if (++nWindowsCreated == m_nTestWindows)
\r
157 OnAllWindowsCreated();
\r
161 return WndProcDefault(uMsg, wParam, lParam);
\r