--- /dev/null
+//////////////////////////////////////////////\r
+// TestWnd.cpp\r
+// Definitions for the CTestWindow class\r
+\r
+#include "stdafx.h"\r
+#include "TestWnd.h"\r
+#include "ThreadApp.h"\r
+\r
+\r
+CTestWindow::CTestWindow(int nWindow) : m_nWindow(nWindow)\r
+{\r
+}\r
+\r
+HWND CTestWindow::Create(CWnd* pParent)\r
+{\r
+ UNREFERENCED_PARAMETER(pParent);\r
+\r
+ CString Title;\r
+ Title.Format( _T("Test Window %d"), m_nWindow );\r
+ return CreateEx(0L, NULL, Title, WS_OVERLAPPEDWINDOW | WS_VISIBLE,\r
+ 70 + 20*m_nWindow, 120 + 20*m_nWindow, 300, 200, NULL, NULL);\r
+}\r
+\r
+BOOL CTestWindow::InitInstance()\r
+{\r
+ // This function runs when the thread starts\r
+\r
+ // Create a test window for this thread\r
+ Create();\r
+\r
+ return TRUE; // return TRUE to run the message loop\r
+}\r
+\r
+void CTestWindow::OnInitialUpdate()\r
+{\r
+ // Get a reference to the CMainWnd object\r
+ CMainWindow& MainWnd = ((CThreadApp*)GetApp())->GetMainWnd();\r
+\r
+ // Post a message to MainWnd when the window is created. The MainWnd window\r
+ // is in a different thread, so PostMessage is preferred over SendMessage.\r
+ // SendMessage would wait for the MainWnd thread to respond.\r
+ ::PostMessage(MainWnd.GetHwnd(), WM_WINDOWCREATED, 0, 0);\r
+}\r
+\r
+LRESULT CTestWindow::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
+{\r
+ switch (uMsg)\r
+ {\r
+ case WM_CLOSE:\r
+ {\r
+ CString str;\r
+ str.Format( _T("Closing test Window %d\n"), m_nWindow );\r
+ TRACE(str);\r
+ }\r
+ break;\r
+\r
+ case WM_DESTROY:\r
+ // Terminate the thread.\r
+ ::PostQuitMessage(0);\r
+ break;\r
+\r
+ }\r
+\r
+ return WndProcDefault(uMsg, wParam, lParam);\r
+}\r
+\r