| class CBMPDocument : public CDocument { … public: unsigned char bmpBit[MAX_BITMAP]; } void CBMPDocument::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here CFile *file = ar.GetFile(); for(int i=0;i<file->GetLength();i++) { ar >> bmpBit[i]; } } } |
| class CBMPChildFrame : public CMDIChildWnd { … public: CSplitterWnd m_wndSplitter; //定义拆分 … } |
| BOOL CBMPChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext *pContext) { // TODO: Add your specialized code here and/or call the base class CRect rect; GetClientRect(&rect); m_wndSplitter.CreateStatic(this, 1, 2); m_wndSplitter.CreateView(0, 0, pContext->m_pNewViewClass, CSize(rect.right /2, 0), pContext); m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CBMPDataView), CSize(0, 0),pContext); m_wndSplitter.SetActivePane(0, 0); return true; } |
| void CBMPDataView::OnDraw(CDC* pDC) { CBMPDocument* pDoc = GetDocument(); // TODO: add draw code here CString str; char tmp[3]; for(int i=0;i<20;i++)//假设只显示20行,每行20个字符 { str = ""; for (int j =0;j<20;j++) { memset(tmp,0,4); itoa(pDoc->bmpBit[10*i+j],tmp,16); str+=CString(tmp)+" "; } pDC->TextOut(0,20*i,str); } } |
![]() 图7.7 用两种视图来显示位图的界面 ![]() 图7.8 "多视图+多文档"的界面 |