Click here to Skip to main content
Click here to Skip to main content

Tagged as

Button behavior - single button multiple behaviour

, 15 May 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
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 on...
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 on OnPrepareDC first to set the mapping mode and factor.
 

For example: Here is a WM_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 to OnLButtonDown and other mouse message handlers
always contain device coordinates so conversion is essetial.
 
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
  }
 
 
}
 

...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

About me:
I attended programming college and I have a degree in three most famous and successful programming languages. C/C++, Visual Basic and Java. So i know i can code. And there is a diploma hanging on my wall to prove it.
.
I am a professional, I am paid tons of cash to teach or do software development. I am roughly 30 years old .
 
I hold lectures in programming. I have also coached students in C++, Java and Visual basic.
 
In my spare time i do enjoy developing computer games, and i am developing a rather simple flight simulator game
in the c++ programming language using the openGL graphics libray.

I've written hundreds of thousands of code syntax lines for small simple applications and games.

Comments and Discussions

 
GeneralMy vote of 2 PinprofessionalManikandan1024-Jun-14 22:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 15 May 2010
Article Copyright 2010 by Software_Developer
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid