Programming with Microsoft Visual C++.NET 6ed [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Programming with Microsoft Visual C++.NET 6ed [Electronic resources] - نسخه متنی

George Shepherd, David Kruglinski

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
توضیحات
افزودن یادداشت جدید








The Ex18a Example: A Single View Class SDI Dynamic Splitter


In this example, the user can dynamically split the view into four panes with four separate view objects, all managed by a single view class. We'll use the document and the view code from the Ex17a example. The MFC Application Wizard lets you add a dynamic splitter window to a new application. You create an SDI project and select Split Window on the User Interface Features page, as shown here:



When you select the Split Window check box, the MFC Application Wizard adds code to your CMainFrame class. Of course, you can add the same code to the CMainFrame class of an existing application to add splitter capability.


Resources for Splitting


When the MFC Application Wizard generates an application with a splitter frame, it includes a Split menu command on the project's View menu. The ID_WINDOW_SPLIT command ID is mapped in the CView class within the MFC library.



CMainFrame


The application's main frame window class needs a splitter window data member and a prototype for an overridden OnCreateClient function. Here are the additions that the MFC Application Wizard makes to the

MainFrm.h file:

protected:
CSplitterWnd m_wndSplitter;
public:
virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs,
CCreateContext* pContext);

The application framework calls the CFrameWnd::OnCreateClient virtual member function when the frame object is created. The base class version creates a single view window as specified by the document template. The MFC Application Wizard–generated OnCreateClient override shown here (in

MainFrm.cpp ) creates a splitter window instead, and the splitter window creates the first view:

BOOL CMainFrame::OnCreateClient( LPCREATESTRUCT /*lpcs*/,
CCreateContext* pContext)
{
return m_wndSplitter.Create( this,
2, 2, // TODO: adjust the number of rows, columns
CSize(10, 10), // TODO: adjust the minimum pane size
pContext);
}

The CsplitterWnd::Create member function creates a dynamic splitter window, and the CSplitterWnd object knows the view class because its name is embedded in the CCreateContext structure that's passed as a parameter to Create.

The second and third Create parameters (2, 2) specify that the window can be split into a maximum of two rows and two columns. If you change the parameters to (2, 1), you'll allow only a single horizontal split. The parameters (1, 2) allow only a single vertical split. The CSize parameter specifies the minimum pane size.



Testing the Ex18a Application


When the application starts, you can split the window by choosing Split from the View menu or by dragging the splitter boxes at the left and top of the scroll bars. Figure 18-1 shows a typical single view window with a four-way split. Multiple views share the scroll bars.


Figure 18-1: A single view window with a four-way split.



/ 319