📄 outputwindow.cpp
字号:
// OutputWindow.cpp : implementation file
//
#include "stdafx.h"
#include "DFYSimulator.h"
#include "OutputWindow.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// COutputWindow
IMPLEMENT_DYNCREATE(COutputWindow, CMDIChildWnd)
COutputWindow::COutputWindow()
{
m_scrollRange=8;
m_nContentNum=0;
m_nFirstVisualPos=0;
}
COutputWindow::~COutputWindow()
{
}
BEGIN_MESSAGE_MAP(COutputWindow, CMDIChildWnd)
//{{AFX_MSG_MAP(COutputWindow)
ON_WM_CLOSE()
ON_WM_VSCROLL()
ON_WM_CREATE()
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COutputWindow message handlers
void COutputWindow::OnClose()
{
//change the menu to MainFrame Menu
CMDIChildWnd::OnClose();
}
void COutputWindow::ShowState(CString strState)
{
//set scroll range
SetScrollRange(SB_VERT,0,m_scrollRange);
if(m_nContentNum<8)
m_scrollRange=8;
else
{
m_scrollRange++;
}
if(m_scrollRange>200)
m_scrollRange=200;
//set content
m_strContent[m_nContentNum]=strState;//set the content
//show the content
int nScrPos=m_scrollRange-8;
if(nScrPos<0)
nScrPos=0;
SetScrollPos(SB_VERT,nScrPos);
int nPos=1;
CClientDC dc(this);
//clear the window content
CRect rect;
GetClientRect(&rect);
CBrush whiteSolidBrush(RGB(255,255,255));
dc.FillRect(&rect,&whiteSolidBrush);
//show the recent 8 lines
int temp=m_nContentNum-5;
if(temp<0)
temp=0;
for(int i=temp;i<=m_nContentNum;i++)
{
dc.TextOut(3,nPos,m_strContent[i]);
nPos+=16;
}
m_nContentNum++;
if(m_nContentNum>=1024)
m_nContentNum=0;
}
void COutputWindow::ResetContent()
{
for(int i=0;i<m_nContentNum;i++)//delete the content
m_strContent[i].Delete(0,m_strContent[i].GetLength());
m_scrollRange=8;
m_nContentNum=0;
m_nFirstVisualPos=0;
//clear the window content
CRect rect;
GetClientRect(&rect);
CBrush whiteSolidBrush(RGB(255,255,255));
CClientDC dc(this);
dc.FillRect(&rect,&whiteSolidBrush);
}
void COutputWindow::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
m_nFirstVisualPos=GetScrollPos(SB_VERT);
switch(nSBCode)
{
case SB_LINEDOWN:
m_nFirstVisualPos+=1;
break;
case SB_LINEUP:
m_nFirstVisualPos-=1;
break;
case SB_PAGEDOWN:
m_nFirstVisualPos+=8;
break;
case SB_PAGEUP:
m_nFirstVisualPos-=8;
break;
case SB_THUMBPOSITION:
m_nFirstVisualPos=nPos;
break;
case SB_THUMBTRACK:
m_nFirstVisualPos=nPos;
break;
default :
break;
}
if(m_nFirstVisualPos>999)
m_nFirstVisualPos=999;
if(m_nFirstVisualPos<0)
m_nFirstVisualPos=0;
SetScrollPos(SB_VERT,m_nFirstVisualPos);
FlushShow();
CMDIChildWnd::OnVScroll(nSBCode, nPos, pScrollBar);
}
int COutputWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
return -1;
SetScrollRange(SB_VERT,0,8);
return 0;
}
void COutputWindow::FlushShow()
{
//clear the window content
CRect rect;
GetClientRect(&rect);
CBrush whiteSolidBrush(RGB(255,255,255));
CClientDC dc(this);
dc.FillRect(&rect,&whiteSolidBrush);
//show the content
int nPos=1;
for(int i=m_nFirstVisualPos;i<m_nFirstVisualPos+8;i++)
{
dc.TextOut(3,nPos,m_strContent[i]);
nPos+=16;
}
}
void COutputWindow::OnPaint()
{
CPaintDC dc(this); // device context for painting
FlushShow();
// Do not call CMDIChildWnd::OnPaint() for painting messages
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -