Microsoft visual c++ toolbar example use toolbar buttons to move movable rectangle m_rect_movable in four directions up, down , left and right and when intersected with a fixed rectangle m_rect_fixed it draws new rectangle with red - hatched pattern and also it the movable rectangle become blue hatched when it approaches the border rectangle m_rectBorder .
This program is similar to a previous program that used menu items to control the position of a movable rectangleThere is 2 things to check the first one is to check the intersection between the movable rectangle and the fixed rectangle so that draw a hatched pattern in the intersection rectangle I could not use IntersectRect function because it takes LPCRECT as parameters and the other thing to check was if the movable rectangle is close to the border rectangle ,you can GetClientRect function to get the window's client area instead of the border rectangle
To build the application
1- Chose new and build single doc application and name it like TOOLBAR_MOVE_EX
2- In the resource view go to toolbar and delete some of the default buttoms and add 4 buttoms as shown in the fig below and assign the following IDs to them ID_SHIFT_LEFT ,ID_SHIFT_RIGHT ,ID_MOVE_UP and ID_MOVE_DOWN sorry for the unpretty buttoms !!
3-Add the following data members to your derived CView class ( 3 rectangles and 5 boolean variables)
CRect m_rectBorder , m_rect_movable, m_rect_fixed ; // border ,movable and fixed rectangles respectively
BOOL m_bLeftBorder ,m_bRightBorder,m_bTopBorder ,m_bButtomBorder ,m_bIntersect;
// border and intersection indicators
4- In the view class initilize your data members as follows
CTOOLBAR_MOVE_EXView::CTOOLBAR_MOVE_EXView():m_rectBorder(10 ,10,340,340),m_rect_fixed(100,100,200,200) ,m_rect_movable(40,30,90,130)
{
m_bLeftBorder =m_bRightBorder =m_bTopBorder =m_bButtomBorder =m_bIntersect==FALSE ;
}
5- In your view add windows messege handlers for command and update command as follows
void CTOOLBAR_MOVE_EXView::OnShiftLeft()
{
if(m_rect_movable.left <=(m_rectBorder.left +40)) m_bLeftBorder = TRUE ; m_rect_movable.OffsetRect(-10,0); m_bRightBorder = FALSE ; if (m_rect_fixed.PtInRect(m_rect_movable.TopLeft()) | m_rect_fixed.PtInRect(m_rect_movable.BottomRight())| m_rect_fixed.PtInRect(CPoint(m_rect_movable.right,m_rect_movable.top))|m_rect_fixed.PtInRect(CPoint( m_rect_movable.left,m_rect_movable.bottom))) { m_bIntersect =TRUE ; } InvalidateRect(NULL,TRUE); } void CTOOLBAR_MOVE_EXView::OnUpdateShiftLeft(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bLeftBorder);
}
void CTOOLBAR_MOVE_EXView::OnShiftRight()
{
if(m_rect_movable.right >= ( m_rectBorder.right -30 ))
m_bRightBorder = TRUE ;
m_rect_movable.OffsetRect(10,0);
m_bLeftBorder = FALSE ;
if (m_rect_fixed.PtInRect(m_rect_movable.TopLeft()) | m_rect_fixed.PtInRect(m_rect_movable.BottomRight())| m_rect_fixed.PtInRect(CPoint(m_rect_movable.right,m_rect_movable.top))|m_rect_fixed.PtInRect(CPoint( m_rect_movable.left,m_rect_movable.bottom))) {
m_bIntersect =TRUE ;
}
InvalidateRect(NULL,TRUE);
}
void CTOOLBAR_MOVE_EXView::OnUpdateShiftRight(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!m_bRightBorder);
}
void CTOOLBAR_MOVE_EXView::OnMoveDown()
{
if( m_rect_movable.bottom >= ( m_rectBorder.bottom -20))
m_bButtomBorder = TRUE ;
m_rect_movable.OffsetRect(0,10) ;
m_bTopBorder = FALSE ;
if (m_rect_fixed.PtInRect(m_rect_movable.TopLeft()) | m_rect_fixed.PtInRect(m_rect_movable.BottomRight())| m_rect_fixed.PtInRect(CPoint(m_rect_movable.right,m_rect_movable.top))|m_rect_fixed.PtInRect(CPoint( m_rect_movable.left,m_rect_movable.bottom))) {
m_bIntersect =TRUE ;
}
InvalidateRect(NULL,TRUE);
}
void CTOOLBAR_MOVE_EXView::OnUpdateMoveDown(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!m_bButtomBorder);
}
void CTOOLBAR_MOVE_EXView::OnMoveUp()
{
if(m_rect_movable.top <= (m_rectBorder.top + 20)) m_bTopBorder =TRUE ; m_rect_movable.OffsetRect(0,-10) ; m_bButtomBorder = FALSE ; if (m_rect_fixed.PtInRect(m_rect_movable.TopLeft()) | m_rect_fixed.PtInRect(m_rect_movable.BottomRight())| m_rect_fixed.PtInRect(CPoint(m_rect_movable.right,m_rect_movable.top))|m_rect_fixed.PtInRect(CPoint( m_rect_movable.left,m_rect_movable.bottom))) { m_bIntersect =TRUE ; } InvalidateRect(NULL,TRUE); } void CTOOLBAR_MOVE_EXView::OnUpdateMoveUp(CCmdUI* pCmdUI) { pCmdUI->Enable(!m_bTopBorder);
}
6- Edit the OnDraw member function of your generated view
pDC->Rectangle(m_rectBorder) ; // white hallow
pDC->SelectStockObject(LTGRAY_BRUSH); // outer rectangle
pDC->Rectangle(m_rect_fixed); // fixed rectangle
CBrush bluebrush(HS_DIAGCROSS, RGB(0, 0, 250)); // blue brush for border condition when moveable rect on border
pDC->SelectStockObject(BLACK_BRUSH);
if(m_bLeftBorder |m_bRightBorder |m_bTopBorder |m_bButtomBorder)
pDC->SelectObject(bluebrush) ; // if in nearby the border rectangle
pDC->Rectangle(m_rect_movable);
if(m_bIntersect) {
CRect rc_intersection ;// use red hatch pattern
rc_intersection.IntersectRect(m_rect_movable ,m_rect_fixed);
CBrush brushHatch(HS_DIAGCROSS, RGB(255, 90, 0));
pDC->SelectObject(brushHatch) ;
pDC->Rectangle(rc_intersection);
}
7- try to move the movable rectangle around when you start the application you will start with a window like this
This comment has been removed by a blog administrator.
ReplyDeletemoncler, moncler outlet, links of london, bottes ugg, moncler, moncler, doudoune canada goose, sac louis vuitton pas cher, juicy couture outlet, canada goose, moncler, pandora charms, pandora charms, replica watches, louis vuitton, pandora jewelry, lancel, canada goose, louis vuitton, ugg boots uk, swarovski, louis vuitton, canada goose uk, wedding dresses, moncler, ugg,uggs,uggs canada, hollister, supra shoes, juicy couture outlet, toms shoes, canada goose outlet, ugg pas cher, montre pas cher, canada goose, moncler, karen millen, swarovski crystal, louis vuitton, pandora jewelry, ugg,ugg australia,ugg italia, marc jacobs, thomas sabo, coach outlet, moncler, canada goose, canada goose outlet
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