download
In this Visual c++ menu example we Top level Move with 4 pop_up items Up ,Down ,Left and Right to move a rectangle rcRect inside the borders of a bigger rectangle rcBorder .
working example
To create the program
1- Start new Single document MFC exe application and deselect printing and print view options
2-In the resource View to IDR_MAINFRAME menu and make add the following items as shown in Fig 1
Downloadshttp://www.4shared.com/file/88832447/4d0b1fea/Menu_Move_Rect.html
3- In your derived view class add the following member functions and make them public
BOOL m_bLeft,m_bRight ,m_bDOWN , m_bUp ; // these are the left right top bottom borders indicators
CRect rcRect ,rcBorder ; // small rectangle and the bigger rectangle rcBorder
4-In your derived view class initilise the date as shown
CMove_RectView::CMove_RectView():rcRect(100,100,50,50),rcBorder( 20 ,20 ,300,300)
{
m_bLeft =m_bRight = m_bDOWN =m_bUp =FALSE ;
}
5-Add messege handlers to your menuitem IDs
void CMove_RectView::OnMoveUp() { rcRect.OffsetRect(0 ,-20); m_bDOWN =FALSE ; if((rcRect.top -70) <= rcBorder.top) m_bUp =TRUE ; InvalidateRect(NULL ,TRUE ); } void CMove_RectView::OnUpdateMoveUp(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bUp); } void CMove_RectView::OnMoveDown() { rcRect.OffsetRect(0, 20); m_bUp =FALSE ; if((rcRect.bottom) >= (rcBorder.bottom -70) ) m_bDOWN =TRUE ; InvalidateRect(NULL ,TRUE ); } void CMove_RectView::OnUpdateMoveDown(CCmdUI* pCmdUI) { pCmdUI->Enable(! m_bDOWN) ; } void CMove_RectView::OnMoveLeft() { if( (rcRect.left) <=rcBorder.left + 70) m_bLeft = TRUE ; rcRect.OffsetRect(-10 , 0); m_bRight = FALSE ; InvalidateRect(NULL ,TRUE ); } void CMove_RectView::OnUpdateMoveLeft(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bLeft); } void CMove_RectView::OnMoveRight() { rcRect.OffsetRect(20 ,0); m_bLeft = FALSE ; InvalidateRect(NULL ,TRUE ); if((rcBorder.right)<= rcRect.right) m_bRight=TRUE ; } void CMove_RectView::OnUpdateMoveRight(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bRight); }
6- Finally edit the OnDraw function in your view class as follows
void CMove_RectView::OnDraw(CDC* pDC)
{
pDC->Rectangle(rcBorder) ;
if( m_bLeft |m_bRight |m_bDOWN |m_bUp)
pDC->SelectStockObject(DKGRAY_BRUSH ) ;
// if the small rect near the big rect
pDC->Rectangle(rcRect);
}
7- Build the application and see how it works
8- Try to move the small Rect with the menu options UP DOWN LEFT AND RIGHT And when move near the borders of the big rectangle you get something like in the fig 2
to download the whole project clich here
and the exe file click here
things to add are keyboad accelerators to do
This comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteoakley sunglasses, polo ralph lauren outlet, tiffany jewelry, nike roshe run, louboutin pas cher, tiffany and co, kate spade outlet, oakley sunglasses, oakley sunglasses, nike free, louboutin outlet, prada outlet, christian louboutin outlet, tory burch outlet, ray ban sunglasses, jordan shoes, louis vuitton, longchamp outlet, ralph lauren pas cher, louis vuitton outlet, ugg boots, longchamp pas cher, ray ban sunglasses, oakley sunglasses, replica watches, polo ralph lauren outlet, uggs on sale, air max, louis vuitton outlet, michael kors, louis vuitton, prada handbags, longchamp, nike free, chanel handbags, sac longchamp, burberry, louis vuitton, nike air max, gucci outlet, nike outlet, louboutin, ugg boots, nike air max, replica watches, air jordan pas cher, ray ban sunglasses, louboutin shoes, longchamp outlet, cheap oakley sunglasses
ReplyDeletejimmy choo shoes, converse outlet, north face outlet, insanity workout, soccer jerseys, wedding dresses, nike air max, ralph lauren, mcm handbags, oakley, hollister, lululemon, mont blanc, valentino shoes, vans shoes, vans, abercrombie and fitch, nike huarache, new balance, hollister, bottega veneta, nike trainers, birkin bag, celine handbags, ghd, soccer shoes, asics running shoes, instyler, timberland boots, beats by dre, nfl jerseys, converse, reebok shoes, nike roshe, hollister, ferragamo shoes, p90x workout, gucci, louboutin, north face outlet, iphone cases, babyliss, chi flat iron, baseball bats, longchamp, ray ban, nike air max, herve leger, mac cosmetics
ReplyDelete