按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!
/////////////////////////////////////////////////////////////////////////////
// DMainFrame message handlers
//…………………………………………………………………………………………………………………………………………………………………………………………………………
// Handler for File|Open mand message。
void DMainFrame::CmdFileOpen()
{
// Display File。Open。。。 dialog box。
int iRet = d_pOpenFile…》DoModal();
// Ignore when user clicks 'Cancel' button。
if (iRet != IDOK)
return;
// Fetch fully…qualified file name。
CString csFile = d_pOpenFile…》GetPathName();
// Open file in read…only mode。
CFile cfData;
if (!cfData。Open(csFile; CFile::modeRead))
{
AfxMessageBox(_T(〃Error Opening File〃));
return;
}
// Free previous buffer contents
if (d_lpTextBuffer)
{
free(d_lpTextBuffer);
…………………………………………………………Page 482……………………………………………………………
d_lpTextBuffer=0;
}
// Calculate file size & allocate buffer。
// Pad to avoid bad address reference。
d_dwFileLength = cfData。GetLength() + sizeof(char);
d_lpTextBuffer = (LPTSTR)malloc (d_dwFileLength);
if (!d_lpTextBuffer)
{
AfxMessageBox(_T(〃Cannot Allocate Memory For File〃));
return;
《 // Loop through client area coordinates to draw。
int cyLine = 0;
while (iLine 《 cLastLine)
{
// Draw a line of text。
LPTSTR lp = d_saTextInfo'iLine'。pText;
int cc = d_saTextInfo'iLine'。ccLen;
// Drawing function depends on 'respect tabs' setting。
if (d_bTabs && d_pnTabs != 0)
{
dc。TabbedTextOut(d_cxLeftMargin; cyLine; lp; cc;
g_nTabCount; d_pnTabs; 0);
}
else
{
dc。TextOut(d_cxLeftMargin; cyLine; lp; cc);
…………………………………………………………Page 483……………………………………………………………
}
// Increment various counts。
cyLine += d_cyLineHeight;
iLine++;
}
}
//…………………………………………………………………………………………………………………………………………………………………………………………………………
// WM_SIZE message handler。
void DMainFrame::OnSize(UINT nType; int cx; int cy)
{
// Notify base class of new window size。
CFrameWnd ::OnSize(nType; cx; cy);
// Save client area height。
d_cyClient = cy;
// Recalculate scroll bar info。
ResetScrollValues();
}
//…………………………………………………………………………………………………………………………………………………………………………………………………………
// WM_VSCROLL message handler。
void DMainFrame::OnVScroll(UINT nSBCode; UINT nPos; CScrollBar* pScrollBar)
{
// Temporary 〃new line〃 value。
int iTop = d_iTopLine;
// Based on particular scroll button clicked; modify top line index。
switch(nSBCode)
{
…………………………………………………………Page 484……………………………………………………………
case SB_BOTTOM:
iTop = d_cLines d_clHeight;
break;
case SB_ENDSCROLL:
break;
case SB_LINEDOWN:
iTop++;
break;
case SB_LINEUP:
iTop…;
break;
case SB_PAGEDOWN:
iTop += d_clHeight;
break;
case SB_PAGEUP:
iTop …= d_clHeight;
break;
case SB_THUMBPOSITION:
iTop = nPos;
break;
case SB_THUMBTRACK:
iTop = nPos;
break;
case SB_TOP:
iTop = 0;
break;
…………………………………………………………Page 485……………………………………………………………
}
// Check range of new index;
iTop = max (iTop; 0);
iTop = min (iTop; d_cLines d_clHeight);
// If no change; ignore。
if (iTop == d_iTopLine) return;
// Pixels to scroll = (lines to scroll) * height…per…line。
int cyScroll = (d_iTopLine iTop) * d_cyLineHeight;
// Define new top…line value。
d_iTopLine = iTop;
// Scroll pixels。
ScrollWindow(0; cyScroll);
// Adjust scroll thumb position。
SetScrollPos(SB_VERT; d_iTopLine; TRUE);
}
//…………………………………………………………………………………………………………………………………………………………………………………………………………
// WM_WININICHANGE message handler。
void DMainFrame::OnWinIniChange(LPCTSTR lpszSection)
{
CFrameWnd::OnWinIniChange(lpszSection);
// Get new background & foreground colors in case these have changed。
d_crForeground = GetSysColor(COLOR_WINDOWTEXT);
d_crBackground = GetSysColor(COLOR_WINDOW);
// Force redraw of window。
Invalidate();
}
…………………………………………………………Page 486……………………………………………………………
//Microsoft Developer Studio generated resource script。
//
#include 〃resource。h〃
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource。
//
#include 〃afxres。h〃
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Chinese (P。R。C。) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
#ifdef _WIN32
LANGUAGE LANG_CHINESE; SUBLANG_CHINESE_SIMPLIFIED
#pragma code_page(936)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
〃resource。h0〃
…………………………………………………………Page 487……………………………………………………………
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
〃#include 〃〃afxres。h〃〃rn〃
〃0〃
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
〃#include 〃〃resfilelist。rc2〃〃 // non…Microsoft Visual C++ edited resourcesrn〃
〃rn〃
〃#define _AFX_NO_SPLITTER_RESOURCESrn〃
〃#define _AFX_NO_OLE_RESOURCESrn〃