?? 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為參數(shù)
HIWORD(LPARAM) = 滾動行數(shù)
LOBYTE(LOWORD(LPARAM)) = 填充字符
WPARAM = 1 時表示 AppendTxtAtCaret
LPARAM = 指向結(jié)構(gòu) 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;
//創(chuàng)建子窗口
BOOL CreateChildWnd(DWORD dwFlagsAdd, CWnd * parent, LPCSTR pszTitle,const CRect & rect,int nID,
int iTabSize, int iFontSize, int iWidthBuf, int iHeightBuf);
//創(chuàng)建彈出窗口
// 默認的風格: 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://屬性
//檢查某行列在窗口內(nèi)是否可見
BOOL IsPosVisible(int iX,int iY);
//得到經(jīng)過計算的顯示全部緩沖區(qū)內(nèi)容需要的顯示區(qū)域大小
CSize GetNeedSize(void){return m_sizeNeed;};
//得到指定位置的值
BYTE& GetXY(int iX,int iY){ASSERT(m_pbBuffer && iX<m_iWidthBuf && iY<m_iHeightBuf);return m_pbBuffer[iX +iY*m_iWidthBuf];};
BYTE& operator [] (int iIndex){ASSERT(m_pbBuffer && iIndex<m_iWidthBuf *m_iHeightBuf);return m_pbBuffer[iIndex];};
//得到緩沖區(qū)指針
const BYTE* GetBuffer(void){return m_pbBuffer;};
//得到緩沖區(qū)大小
int GetBufferLen(void){ASSERT(m_pbBuffer);return m_iLenBuffer;};
//得到文字窗口尺寸
void GetBufferWindowSize(int &iWidth,int &iHeight){iWidth = m_iWidthBuf;iHeight= m_iHeightBuf;};
//得到光標位置
CPoint GetCaretPoint(void){return m_ptCaret;};
protected:
DECLARE_MESSAGE_MAP()
protected:
BOOL CreateEx(DWORD dwFlagsEx,DWORD dwFlags,CWnd * parent,LPCSTR pszTitle, const CRect & rect,int nID,
int iTabSize, int iFontSize, int iWidthBuf, int iHeightBuf);
protected://參數(shù)設置功能
void SetBaseParameter(int iTabSize,int iFontSize, int iWidthBuf, int iHeightBuf);
//消息通知
void NotifyParent(UINT msg);
//判斷指定位置字符是否為中文字符的第二個字節(jié)
BOOL IsSecondByteOfDBCS(int iX,int iY);
protected:
CWnd *m_pwndParent;
BYTE *m_pbBuffer; //緩沖區(qū)
int m_iTabSize;
int m_iWidthBuf,m_iHeightBuf,m_iLenBuffer;
CFont *m_ftDraw; //屏幕字體 宋體
int m_iFontWidth,m_iFontHeight; //字體大小
int m_iFontMarginX,m_iFontMarginY;//每行,每列需要留出的空間
COLORREF m_crFont,m_crBackground;
CSize m_sizeNeed;//顯示全部緩沖區(qū)內(nèi)容需要的顯示區(qū)域大小
CSize m_sizeIndeed;//當前窗口實際可以顯示的窗口大小
CSize m_sizeIndeedDraw;
CPoint m_ptCaret;//記錄光標位置
BOOL m_fCaret; //光標是否顯示
int m_nWndID;//窗口ID
BOOL m_fPopupWnd,m_fCanExit;
public:
afx_msg LRESULT OnBWndNotifyMsg(WPARAM wP, LPARAM lP);
afx_msg void OnPaint();
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnSetFocus(CWnd* pOldWnd);
afx_msg void OnKillFocus(CWnd* pNewWnd);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnRButtonDblClk(UINT nFlags, CPoint point);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnDestroy();
afx_msg void OnClose();
};
/*
CConsoler : 完成各種類似與控制臺的輸出功能:
1 通過printf方式輸出
2 指定位置輸出字符
*/
class CConsoler
{
public:
CConsoler();
~CConsoler();
void SetBufferWnd(CBufferWnd* pWnd);
public:
void printfX(const char *pszFormat,...);
BYTE& GetXY(int iX,int iY){ASSERT(m_pBufWnd); return m_pBufWnd->GetXY(iX,iY);};
CBufferWnd* GetWindow(void){return m_pBufWnd;};
protected:
//將字符串格式化成具體數(shù)據(jù)
//將Tab鍵進行轉(zhuǎn)換,將\n , \r進行轉(zhuǎn)換,處理中文作為最后一個字符時換行,
//返回實際使用的字符數(shù)量
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
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -