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

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

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

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

George Shepherd, David Kruglinski

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

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

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








The Ex18b Example: A Double View Class SDI Static Splitter


In Ex18b, we'll extend Ex18a by defining a second view class and allowing a static splitter window to show the two views. (The H and CPP files are cloned from the original view class.) This time the splitter window works a little differently. Instead of starting off as a single pane, the splitter is initialized with two panes. The user can move the bar between the panes by dragging it with the mouse or by choosing the Window Split menu command.

The easiest way to generate a static splitter application is to let the MFC Application Wizard generate a dynamic splitter application and then edit the generated CMainFrame::OnCreateClient function.


CHexView


The CHexView class was written to allow programmers to appreciate poetry. It is essentially the same code used for CStringView except for the OnDraw member function:

void CHexView::OnDraw(CDC* pDC)
{
// hex dump of document strings
int i, j, k, l, n, nHeight;
CString outputLine, str;
CFont font;
TEXTMETRIC tm;
CPoemDoc* pDoc = GetDocument();
font.CreateFont(-160, 80, 0, 0, 400, FALSE, FALSE, 0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial");
CFont* pOldFont = pDC->SelectObject(&font);
pDC->GetTextMetrics(&tm);
nHeight = tm.tmHeight + tm.tmExternalLeading;
j = pDoc->m_stringArray.GetSize();
for (i = 0; i < j; i++) {
outputLine.Format("%02x ", i);
l = pDoc->m_stringArray[i].GetLength();
for (k = 0; k < l; k++) {
n = pDoc->m_stringArray[i][k] & 0x00ff;
str.Format("%02x ", n);
outputLine += str;
}
pDC->TextOut(720, -i * nHeight - 720, outputLine);
}
pDC->SelectObject(pOldFont);
}

This function displays a hexadecimal dump of all strings in the document's m_stringArray collection. Notice the use of the subscript operator to access individual characters in a CString object.



CMainFrame


As in Ex18a, the Ex18b application's main frame window class needs a splitter window data member and a prototype for an overridden OnCreateClient function. You can let the MFC Application Wizard generate the code by specifying Split Window, as in Ex18a. You don't have to modify the

MainFrm.h file.

The implementation file,

MainFrm.cpp , needs both view class headers (and the prerequisite document header), as shown here:

#include "PoemDoc.h"
#include "StringView.h"
#include "HexView.h"

The MFC Application Wizard generates dynamic splitter code in the OnCreateClient function, so you'll have to do some editing if you want a static splitter. Instead of calling CSplitterWnd::Create, you call the CSplitterWnd::CreateStatic function, which is tailored for multiple view classes. The following calls to CSplitterWnd::CreateView attach the two view classes. As the second and third CreateStatic parameters (2, 1) dictate, this splitter window contains only two panes. The horizontal split is initially 100 device units from the top of the window. The top pane is the string view; the bottom pane is the hex dump view. The user can change the splitter bar position, but not the view configuration.

BOOL CMainFrame::OnCreateClient( LPCREATESTRUCT /*lpcs*/,
CCreateContext* pContext)
{
VERIFY(m_wndSplitter.CreateStatic(this, 2, 1));
VERIFY(m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CStringView),
CSize(100, 100), pContext));
VERIFY(m_wndSplitter.CreateView(1, 0, RUNTIME_CLASS(CHexView),
CSize(100, 100), pContext));
return TRUE;
}



Testing the Ex18b Application


When you start the Ex18b application, the window should look like the one shown here. Notice the separate horizontal scroll bars for the two views.




/ 319