按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
// mainfrm。cpp : implementation of the DMainFrame class
//
#include 〃stdafx。h〃
#include 〃filelist。h〃
#include 〃mainfrm。h〃
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE'' = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// DMainFrame
IMPLEMENT_DYNCREATE(DMainFrame; CFrameWnd)
BEGIN_MESSAGE_MAP(DMainFrame; CFrameWnd)
//{{AFX_MSG_MAP(DMainFrame)
ON_MAND(ID_FILE_OPEN; CmdFileOpen)
ON_MAND(ID_FORMAT_FONT; CmdFormatFont)
ON_MAND(ID_FORMAT_TABS; CmdFormatTabs)
ON_UPDATE_MAND_UI(ID_FORMAT_TABS; UpdFormatTabs)
ON_WM_CREATE()
…………………………………………………………Page 476……………………………………………………………
ON_WM_PAINT()
ON_WM_SIZE()
ON_WM_VSCROLL()
ON_WM_WININICHANGE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// DMainFrame construction/destruction
DMainFrame::DMainFrame()
{
// Init all data members to a known value。
d_pOpenFile = 0;
d_lpTextBuffer = 0;
d_dwFileLength = 0;
d_pFont = 0;
// Init desired font。
memset (&d_lf; 0; sizeof(LOGFONT));
// Initial font face name is Courier New。
lstrcpy (d_lf。lfFaceName; _T(〃Courier New〃));
// Initial font size is 10 pt。
CWindowDC dc(NULL);
int cyPixels = dc。GetDeviceCaps(LOGPIXELSY);
d_lf。lfHeight = (…1) * MulDiv(10; cyPixels; 72);
// Initial tab setting is OFF。
d_bTabs = TRUE;
// Tab table initially empty (set when font selected)。
…………………………………………………………Page 477……………………………………………………………
d_pnTabs = 0;
}
DMainFrame::~DMainFrame()
{
if (d_pFont) delete d_pFont;
if (d_pnTabs) delete '' d_pnTabs;
if (d_pOpenFile) delete d_pOpenFile;
if (d_pSetFont) delete d_pSetFont;
}
///////////////////////////////////////////////////////////////////////////////
// DMainFrame helper functions。
//…………………………………………………………………………………………………………………………………………………………………………………………………………
// BuildStringArray …Parses text file to create a CString array。
void DMainFrame::BuildStringArray()
{
// Scan buffer to calculate line count。
LPTSTR lpNext = d_lpTextBuffer;
LPTSTR lpEnd = d_lpTextBuffer + d_dwFileLength 1;
*lpEnd = 'n';
for (d_cLines = 0; lpNext 《 lpEnd; d_cLines++; lpNext++)
{
// Search for next character。
lpNext = strchr(lpNext; 'n');
// Discontinue if NULL encountered。
if (lpNext == NULL) break;
}
…………………………………………………………Page 478……………………………………………………………
// Set array size。
d_saTextInfo。SetSize(d_cLines);
// Scan buffer to build array of pointers & sizes。
STRING string;
lpNext = d_lpTextBuffer;
for (int iLine = 0; iLine 《 d_cLines; iLine++)
{
// Char count for current line。
string。ccLen = 0;
string。pText = lpNext;
// Loop to end…of…line。
while ((*lpNext != 'n') && (*lpNext != 'r'))
{
lpNext++; // Check next char。
string。ccLen++; // Increment length counter。
}
// Enter value in array。
d_saTextInfo'iLine' = string;
// Skip over
lpNext += (2 * sizeof(char));
}
}
//…………………………………………………………………………………………………………………………………………………………………………………………………………
// CreateNewFont …Creates new CFont for use in drawing text。
BOOL DMainFrame::CreateNewFont()
{
…………………………………………………………Page 479……………………………………………………………
// Delete any previous font。
if (d_pFont)
delete d_pFont;
// Create a new font
d_pFont = new CFont();
if (!d_pFont) return FALSE;
d_pFont…》CreateFontIndirect(&d_lf);
// Calculate font height
CClientDC dc(this);
TEXTMETRIC tm;
dc。SelectObject(d_pFont);
dc。GetTextMetrics(&tm);
d_cyLineHeight = tm。tmHeight + tm。tmExternalLeading;
// Calculate left margin。
d_cxLeftMargin = tm。tmAveCharWidth * 2;
// Rebuild tab setting table。
if (d_pnTabs) delete '' d_pnTabs;
d_pnTabs = new INT'g_nTabCount';
for (int i=0; i