Creating a View

[Previous] [Next]

Because we have a toolbar and a status bar taking up space in the client area of the main frame window, we'll go ahead and create a child window that will show the actual drawing strokes. The window will occupy all the usable client area of the frame not covered by the toolbar and the status bar. To create the window, we need to derive a class from CWindowImpl with the appropriate styles for a view window. The CView class declaration shown here will do the trick:

 typedef CWinTraits<WS_CHILD | WS_VISIBLE, WS_EX_CLIENTEDGE>     CViewWinTraits; class CView : public CWindowImpl<CView, CWindow, CViewWinTraits> { public:     CView();     virtual ~CView();     DECLARE_WND_CLASS(_T("InAtl:View"))     BEGIN_MSG_MAP(CView)     END_MSG_MAP() }; 

In the class declaration, we've defined a new window class for our view as well as a default message map. Now all we need to do is add a CView data member to CMainFrame, create it in OnCreate, and size it to the unused client area in the OnSize handler. There isn't anything special about the creation code. The CViewWinTraits class provides all our styles, so we won't specify any to the Create function, as shown here:

 // Create the view. m_wndView.Create(m_hWnd, CWindow::rcDefault, _T("View"),     0, 0, 0); 

The OnSize handler positions and sizes the view to fill the remaining client area in CMainFrame. The application frame with the toolbar, status bar, and view is shown in Figure 16-3.

Figure 16-3. ATL Scribble with a toolbar, a status bar, and a view.



Inside Atl
Inside ATL (Programming Languages/C)
ISBN: 1572318589
EAN: 2147483647
Year: 1998
Pages: 127

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net