--- /dev/null
+//////////////////////////////////////////////\r
+// MDIChildRect.cpp\r
+// Definitions for the CViewRect and CMDIChildRect class\r
+\r
+#include "stdafx.h"\r
+#include "MDIChildRect.h"\r
+#include "resource.h"\r
+\r
+\r
+////////////////////////\r
+// CViewRect definitions\r
+LRESULT CViewRect::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
+{\r
+ switch (uMsg)\r
+ {\r
+ case WM_CREATE:\r
+ SetTimer (1, 250, NULL) ;\r
+ break;\r
+ case WM_CLOSE:\r
+ KillTimer(1);\r
+ break;\r
+\r
+ case WM_TIMER: // Display a random rectangle\r
+ {\r
+ int nRed, nGreen, nBlue;\r
+ int xLeft, xRight, yTop, yBottom;\r
+ xLeft = rand () % m_cxClientMax;\r
+ xRight = rand () % m_cxClientMax;\r
+ yTop = rand () % m_cyClientMax;\r
+ yBottom = rand () % m_cyClientMax;\r
+ nRed = rand () & 255;\r
+ nGreen = rand () & 255;\r
+ nBlue = rand () & 255;\r
+\r
+ CClientDC dcRect(this);\r
+ dcRect.CreateSolidBrush (RGB (nRed, nGreen, nBlue));\r
+\r
+ int Left = (xLeft < xRight) ? xLeft : xRight;\r
+ int Top = (yTop < yBottom) ? yTop : yBottom;\r
+ int Right = (xLeft > xRight) ? xLeft : xRight;\r
+ int Bottom = (yTop > yBottom) ? yTop : yBottom;\r
+ dcRect.Rectangle(Left, Top, Right, Bottom);\r
+ }\r
+ break;\r
+\r
+ case WM_SIZE: // If not minimized, save the window size\r
+ if (wParam != SIZE_MINIMIZED)\r
+ {\r
+ m_cxClientMax = LOWORD (lParam) ;\r
+ if (m_cxClientMax < 1) m_cxClientMax = 1;\r
+ m_cyClientMax = HIWORD (lParam) ;\r
+ if (m_cyClientMax < 1) m_cyClientMax = 1;\r
+ }\r
+ break ; // WM_SIZE must be processed by DefMDIChildProc\r
+ }\r
+\r
+ return WndProcDefault(uMsg, wParam, lParam);\r
+}\r
+\r
+////////////////////////////\r
+// CMDIChildRect definitions\r
+CMDIChildRect::CMDIChildRect()\r
+{\r
+ HINSTANCE hResource = GetApp()->GetResourceHandle();\r
+ HMENU hChildMenu = LoadMenu(hResource, _T("MdiMenuRect"));\r
+ SetHandles(hChildMenu, NULL);\r
+ SetView(m_RectView);\r
+}\r
+\r
+CMDIChildRect::~CMDIChildRect()\r
+{\r
+}\r
+\r
+void CMDIChildRect::OnInitialUpdate()\r
+{\r
+ SetWindowText(_T("Rectangle Window"));\r
+ SetIconLarge(IDI_RECT);\r
+ SetIconSmall(IDI_RECT);\r
+}\r
+\r