Monday, April 19, 2010

menutoolbar

Menutoolbar
1) Run application wizard and choose single document
2) Create a Menu bar IDR_MAINFRAME and Toolbar IDR_MAINFRAME in Resource tab
3) Define a Rich Edit Control to transfer and store data
4) In the Doc class
Define the functions
i)OnNewDocument
ii)OnEditClearall
4)In the View class
Define the functions
i)OnDrawSquare
ii)OnDrawCircle
iii)OnDrawPattern
iv)OnUpdateDrawSquare
v)OnUpdateDrawCircle
vi)OnUpdateDrawPattern
vii)OnTransferGetData
viii)OnTransferStoreData
ix)OnCreate
x)OnSize
b)Build and Execute the functions
CODE
Menudoc.h
Public:
CString m_strText;
Menudoc.cpp
BOOL CMenuDoc::OnNewDocument()
{
If(!CDocument::OnNewDocument())
return FALSE;
m_strText=”Hello(from CMenuDoc::OnNewDocument)”
return TRUE;
}
Void CMenuDoc::OnEditClearall(CCmdUI *pCmdUI)
{
pCmdUI->Enable(!m_strText.IsEmpty());
}

Menuview.h
Public:
CRichEditCtrl m_rich;
Private:
CRect m_rect;
BOOL m_bCircle;
BOOL m_bPattern;
Menuview.cpp
CMenuView::CMenuView():m_rect(0,0,100,100)
{
m_bCircle=TRUE;
m_bPattern=FALSE;
}

Void CMenuView::OnDraw(CDC *pDC)
{
CBrush brush(HS_BDIAGONAL,0L);
If(m_bPattern)
{
pDC->SelectObject(&brush);
}
else
{
pDC->SelectStockObject(WHITE_BRUSH);
}
If(m_bCircle)
{
pDC->Ellipse(m_rect);
ValidateRect(m_rect);
}
else
{
pDC->Rectangle(m_rect);
ValidateRect(m_rect);
}
pDC->SelectStockObject(WHITE_BRUSH);
}
Void CMenuView::OnTransferGetData()
{
CMenuDoc *pDoc=GetDocument();
m_rich.SetWindowText(pDC->m_strText);
m_rich.SetModify(FALSE);
}
Void CMenuView::OnTransferStoreData()
{
CMenuDoc *pDoc=GetDocument();
m_rich.GetWindowText(pDC->m_strText);
m_rich.SetModify(FALSE);
}
Int CMenuView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CRect rect(0,0,0,0);
If(CView::OnCreate(lpCreateStruct==-1)
return -1;
m_rich.Create(ES_MULTILINE|ES_WANTRETURN|WS_CHILD|WS_VISIBLE|WS_VSCROLL,rect,this,1);
return0;
}

Void CMenuView::OnSize(UINT nType,int cx,int cy)
{
CView::OnSize(nType,cx,cy);
CRect rect;
GetClientRect(rect);
M_rich.SetWindowPos(&wndTop,0,0,rect.right-rect.left,rect.bottom-rect.top,SWP_SHOWWINDOW);
}

void CMenuView::OnDrawCircle()
{
m_bCircle=TRUE;
m_rect+=CPoint(25,25);
InvalidateRect(m_rect);
}

Void CMenuView::OnDrawPattern()
{
m_bPattern^=1;
}

void CMenuView::OnDrawSquare()
{
m_bCircle=FALSE;
m_rect+=CPoint(25,25);
InvalidateRect(m_rect);
}

void CMenuView::OnUpdateDrawCircle(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!m_bCircle);
}

void CMenuView::OnUpdateDrawPattern(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_bPattern);
}
void CMenuView::OnUpdateDrawSquare(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bCircle);

}

No comments:

Post a Comment