www.pudn.com > 2003090514065121890.zip > spBufferWnd.h
#ifndef __BUFFER_WND_H_
#define __BUFFER_WND_H_
//#pragma once
/*
CBufferWnd:完成屏幕输出类
功能:类似与Console屏幕的输出方式
1 管理光标,光标定义在输入后的待输入位置
2 向屏幕输出字符,通过在光标后面添加字符串,或者通过指定行列设置字符
3 管理滚动
功能限制:
1 不会对字符进行处理,只会直接将字符进行显示
*/
namespace spBase
{
// CBufferWnd
#define WYYBUFFER_WND "WYY_BUFFER_WND"
//定义滚动时每页的尺寸
#define HSCROLL_PAGE_SIZE 5
#define VSCROLL_PAGE_SIZE 5
#define WM_BW_NOTIFY WM_USER + 188 // add by wenyy 2003/08/20
/*
WPARAM = 0 时表示 ScrollTxtUp ,LPARAM为参数
HIWORD(LPARAM) = 滚动行数
LOBYTE(LOWORD(LPARAM)) = 填充字符
WPARAM = 1 时表示 AppendTxtAtCaret
LPARAM = 指向结构 struct CBufferWnd::strAppendTxt 的指针
*/
class CConsoler;
class CBufferWnd : public CWnd
{
DECLARE_DYNAMIC(CBufferWnd)
friend class CConsoler;
public:
CBufferWnd();
virtual ~CBufferWnd();
BOOL RegisterWindowClass(void);
public:
// ASSERT(iWidthBuf>20 && iWidthBuf<=512 && iHeightBuf>4 && iHeightBuf<512 );
// dwFlagsAdd 附加的窗口风格,window style attributes,默认的风格:WS_CHILD | WS_VSCROLL | WS_HSCROLL;
//创建子窗口
BOOL CreateChildWnd(DWORD dwFlagsAdd, CWnd * parent, LPCSTR pszTitle,const CRect & rect,int nID,
int iTabSize, int iFontSize, int iWidthBuf, int iHeightBuf);
//创建弹出窗口
// 默认的风格: WS_OVERLAPPED | WS_VSCROLL | WS_HSCROLL;
BOOL CreateAppWnd(DWORD dwFlagsAdd,LPCSTR pszTitle,const CRect & rect,
int iTabSize, int iFontSize, int iWidthBuf, int iHeightBuf);
//设置退出标记
void SetCanExitFlag(BOOL fCan){m_fCanExit = fCan;};
public://滚动功能
void ReCalcScrollSize( void);
void ScrollTo(int iX,int iY);
//检查指定行列是否能够显示,如果不能显示,则进行滚动
BOOL ScrollIfPointNotShown(int iX,int iY);
public://光标功能
BOOL OpenCaretAsNecessary(void);
void CloseCaret(void);
void GetCaretPoint(CPoint& ptCaret){ptCaret = m_ptCaret;};
//将光标移动到指定行列
void SetCaretPoint(int iX,int iY){m_ptCaret=CPoint(iX,iY);SetCaretPoint();};
void SetCaretPoint(CPoint ptCaret){m_ptCaret = ptCaret;SetCaretPoint();};
void SetCaretPoint(void);
public://绘图功能
void PaintWnd(CDC* pDC);
public://文字功能
struct strAppendTxt
{
BOOL fShowY;
BOOL fShowX;
int iTxtLen;
LPCSTR pszTxt;
};
//在光标处添加文字,同时改变光标位置
//BOOL fShowY=TRUE,BOOL fShowX=FALSE
//在添加文字后是否强制滚动到文字的最后位置
void AppendTxtAtCaret(LPCSTR pszText,BOOL fShowY=TRUE,BOOL fShowX=FALSE){ASSERT(pszText);AppendTxtAtCaret((int)strlen(pszText),pszText,fShowY,fShowX);};
//在光标处添加文字
void AppendTxtAtCaret(int iTxtLen,LPCSTR pszText,BOOL fShowY=TRUE,BOOL fShowX=FALSE);
//滚动文字,并在后面填入空行,不改变光标位置
void ScrollTxtUp(int iLines,char cFill=0x20);
public://属性
//检查某行列在窗口内是否可见
BOOL IsPosVisible(int iX,int iY);
//得到经过计算的显示全部缓冲区内容需要的显示区域大小
CSize GetNeedSize(void){return m_sizeNeed;};
//得到指定位置的值
BYTE& GetXY(int iX,int iY){ASSERT(m_pbBuffer && iXGetXY(iX,iY);};
CBufferWnd* GetWindow(void){return m_pBufWnd;};
protected:
//将字符串格式化成具体数据
//将Tab键进行转换,将\n , \r进行转换,处理中文作为最后一个字符时换行,
//返回实际使用的字符数量
int FormatCharsAndOutput(LPCSTR pszSrc,int iLen);
//
BOOL IsCtrlChar(char c){return (c=='\t' || c=='\n' || c=='\r');};
protected:
CBufferWnd* m_pBufWnd;
};
class CMemDC : public CDC
{
public:
// constructor sets up the memory DC
CMemDC(CDC* pDC) : CDC()
{
ASSERT(pDC != NULL);
m_pDC = pDC;
m_pOldBitmap = NULL;
m_bMemDC = !pDC->IsPrinting();
if (m_bMemDC) // Create a Memory DC
{
pDC->GetClipBox(&m_rect);
CreateCompatibleDC(pDC);
m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
m_pOldBitmap = SelectObject(&m_bitmap);
SetWindowOrg(m_rect.left, m_rect.top);
}
else // Make a copy of the relevent parts of the current DC for printing
{
m_bPrinting = pDC->m_bPrinting;
m_hDC = pDC->m_hDC;
m_hAttribDC = pDC->m_hAttribDC;
}
}
// Destructor copies the contents of the mem DC to the original DC
~CMemDC()
{
if (m_bMemDC) {
// Copy the offscreen bitmap onto the screen.
m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
this, m_rect.left, m_rect.top, SRCCOPY);
//Swap back the original bitmap.
SelectObject(m_pOldBitmap);
} else {
// All we need to do is replace the DC with an illegal value,
// this keeps us from accidently deleting the handles associated with
// the CDC that was passed to the constructor.
m_hDC = m_hAttribDC = NULL;
}
}
// Allow usage as a pointer
CMemDC* operator->() {return this;}
// Allow usage as a pointer
operator CMemDC*() {return this;}
private:
CBitmap m_bitmap; // Offscreen bitmap
CBitmap* m_pOldBitmap; // bitmap originally found in CMemDC
CDC* m_pDC; // Saves CDC passed in constructor
CRect m_rect; // Rectangle of drawing area.
BOOL m_bMemDC; // TRUE if CDC really is a Memory DC.
};
};
#endif