// MfcTestView.cpp : implementation of the CMfcTestView class
//
#include "stdafx.h"
#include "MfcTest.h"
#include "MfcTestDoc.h"
#include "MfcTestView.h"
#include "../include/msg.h"
using namespace mycell;
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMfcTestView
IMPLEMENT_DYNCREATE(CMfcTestView, CView)
BEGIN_MESSAGE_MAP(CMfcTestView, CView)
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
ON_NOTIFY(OCN_GETCELLTEXT,100,_OnGetCellText)
ON_WM_CREATE()
ON_WM_SIZE()
END_MESSAGE_MAP()
// CMfcTestView construction/destruction
CMfcTestView::CMfcTestView()
{
// TODO: add construction code here
m_pGrid.CoCreateInstance(CLSID_Grid);
_ASSERT(m_pGrid!=NULL);
}
CMfcTestView::~CMfcTestView()
{
}
BOOL CMfcTestView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
void CMfcTestView::_OnGetCellText(NMHDR* lpnm, LRESULT*)
{
NM_GRIDVIEW* lp=(NM_GRIDVIEW*)lpnm;
LPTSTR lpszText=(LPTSTR)lp->lParam;
OnGetCellText(lp->hdr.hwndFrom,lp->row,lp->col,lpszText);
}
void CMfcTestView::OnGetCellText(HWND hWndFrom,int row,int col,LPTSTR lpszText)
{
CComBSTR label;
m_pGrid->GetColLabel(col,&label);
CString str(label);
wsprintf(lpszText,_T("%s%d"),str,row+1);
}
void CMfcTestView::init_grid()
{
int const cols=200;
m_pGrid->put_cols(cols);
m_pGrid->put_rows(99999);
TCHAR buf[50];
for(int i=0;i<cols;++i){
int const col=i+1;
if(col<27){ //A~Z
buf[0]=(col+0x40);
buf[1]=0;
}else if(col<703){ //AA~ZZ
buf[1]=(col-1)%26+'A';//0x41;
buf[0]=(col-1)/26-1+'A';//0x40;
buf[2]=0;
}
m_pGrid->SetColLabel(i,CComBSTR(buf));
}
}
int CMfcTestView::OnCreate(LPCREATESTRUCT lpcs)
{
init_grid();
RECT rc={0,0,800,600};
m_pGrid->Create((OLE_HANDLE)m_hWnd,&rc,NULL,WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN,/*WS_EX_STATICEDGE*/0,100,0);
m_pGrid->put_listener((OLE_HANDLE)m_hWnd);
return 0;
}
void CMfcTestView::OnSize(UINT, int width, int height)
{
if(width>0 && height>0 && m_pGrid.p)
{
OLE_HANDLE nWnd;
m_pGrid->GetHWnd(&nWnd);
::MoveWindow((HWND)nWnd,0,0,width,height,TRUE);
}
}
// CMfcTestView drawing
void CMfcTestView::OnDraw(CDC* /*pDC*/)
{
CMfcTestDoc* pDoc = GetDocument();
//ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: add draw code for native data here
}
// CMfcTestView printing
BOOL CMfcTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMfcTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMfcTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
// CMfcTestView diagnostics
#ifdef _DEBUG
void CMfcTestView::AssertValid() const
{
CView::AssertValid();
}
void CMfcTestView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMfcTestDoc* CMfcTestView::GetDocument() const // non-debug version is inline
{
//ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMfcTestDoc)));
return (CMfcTestDoc*)m_pDocument;
}
#endif //_DEBUG
// CMfcTestView message handlers