Solved

Getting the boundary of a button

Posted on 1998-12-13
10
273 Views
Last Modified: 2013-11-20
How can I get the boundary of a button? I wish to get the cursor's co-ordinate such that when the cursor's co-ordinate is within the boundary of a button, a particular function is performed.
0
Comment
Question by:thankyouall
10 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1326125
Use GetWindowRect() in conjunction with GetCursorPos() will get you that information.
0
 
LVL 1

Expert Comment

by:V245
ID: 1326126
I guess in this case it is better to override CButton::OnMouseMove.
0
 

Author Comment

by:thankyouall
ID: 1326127
It gaves me the co-ordinate of the window, how can I determine if the cursor has entered within the boundary of a component within the window? Please help.
0
 

Author Comment

by:thankyouall
ID: 1326128
It gaves me the co-ordinate of the window, how can I determine if the cursor has entered within the boundary of a component within the window? Please help.
0
 
LVL 2

Expert Comment

by:wyy_cq
ID: 1326129
you 'd better redefine the WM_SETCUSROR message map in the parent window.
when the cursor move in the button , the
afx_msg BOOL OnSetCursor( CWnd* pWnd, UINT nHitTest, UINT message ); will be called .
from the pWnd you can get the control's ID or HWND, and know which control it is.

by this way you can deal with all the child button in the same method.




0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:wyy_cq
ID: 1326130
define a timer to get the curent cursor position.(onSetCursor is also a good idea ,as my last comment)
you 'd better not to define mouseMove because the mouse move message will not send to parent window .

i recommend all the operation will be done in parent window.
code:
in OnTimer or OnSetCursor
{
 CPoint ptCursor
 ::GetCursorPos(&ptCursor);//in screen coordinates
 CRect rcBtn;
 GetDlgItem(IDC_BTN)->GetWindowRect(rcBtn);// in screen coordinates
 // if in onSetCursor handler, you will retrieve the CWnd* from the parameter
 
 if(ptCursor.x< rcBtn.Width()/2+rcBtn.left
     && ptCursor.x>rcBtn.left)
 {// in the left of the button
    do your function here
 }
}


0
 

Author Comment

by:thankyouall
ID: 1326131
thanks!... please gimme sometime to try it out!
0
 

Author Comment

by:thankyouall
ID: 1326132
I've tried it out... but it seems that sometimes when my mouse doesn't even go near or go within the boundary of the button, it also performs the function which I wrote them at the "do your function here" line. Why is this so? I just insert a simple MessageBox function.
I used the OnSetCursor function and after running, when my mouse go near or within the boundary of the button, the messagebox keeps on appearing after I terminate it. It just keep on appearing non-stop. Please help...thanks!
0
 
LVL 2

Accepted Solution

by:
wyy_cq earned 20 total points
ID: 1326133
1, in OnTimer(...) you must conver the point between screen and window coordinates .

2,so i recommend you'd better work with the OnSetCursor(....)
you must add some flag to you application to identify when will popup the message box.

there are some false code:

BOOL fP;

in OnSetCursor(...)
{
  check the point is in area.
  if in
   {
    fP=FALSE;
    AfxMessageBox(...);
    // fP=TRUE; do not do this ,
   }
  else
   {
     fP=TRUE;
   }
   ....
}
0
 

Author Comment

by:thankyouall
ID: 1326134
Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ BOOL WINAPI ReadFile fails on windows 10 when reading from USB cable 9 378
no14 challenge 14 62
twoTwo  challenge 35 93
Is there a simple front-end menu system. 9 70
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now