Button behavior - single button multiple behaviour
-
At 5:35 on the 13th of May 2010, AbhiHcl wrote: >>> >>> Hi, >>> >>> Can I use single button for more than one behaviour. >>> For example one button is devide into 2 parts, >>> If I click on first part minus operation should be performed >>> and click on second part + opeartion should be performed. >>> >>> Yes you can use one single button for more than one behaviour. Here is how. If you have the coordinates of a point in device coordinates and want to find the corresponding position in logcal view - use
CDC::DPtoLP
to convert the device coordinates to logcal coordinates. Call onOnPrepareDC
first to set the mapping mode and factor. For example: Here is aWM_LEFTBUTTONDOWN
handler that performs a simple hit test to determine whether the click point lies in the upper or lower half of the logcal view.CPoint
objects passed toOnLButtonDown
and other mouse message handlers always contain device coordinates so conversion is essential.void CMyView::OnLButtonDown(UINT nFlags, CPoint Point)
{
CPoint pos=Point;
CClientDC dc (this);
OnPrepareDC(&dc); //
dc.DPtoLP(&pos);
CSize size=GetTotalSize();
if(::abs( pos.y ) < (size.cy/2) )
{
//Upper half was clicked
}
else
{
//lower half was clicked
}}
...