Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onMouse Over for groupBox 1

Status
Not open for further replies.

bubak

Programmer
Jun 25, 2001
208
SK
I'm using groupBox to show an area in my prog, and I need to show the cursor position in it. I want to use sth like onMouseMove, but groupBox has just BNClicked and BNDblClicked msgs. How do I do that pls?
thx
bubak
 
You want to use a feature that is not by default implemented
by MFC framework

Try to add by hand a line like:
ON_MESSAGE(WM_MOUSEMOVE,OnMyMouseMove) inside your BEGIN_MESSAGE_MAP

also put a function like
void OnMyMouseMove() or
void OnMyMouseMove(WPARAM wParam, LPARAM lParam)
in your cpp

and a line like:
afxmsg void OnMyMouseMove() in the DECLARE_MESSAGE_MAP from your .h file

I am not very sure if it works, but maybe you will have a start point.

Hope this helps, s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
I've done it this way:
I created OnMOuseMove for my app, and a dataRect structure, that is initializes in OnInit :
GetDlgItem(IDC_DATA)->GetWindowRect(dataRect);
in OnMouseMove :
POINT p;
GetCursorPos(&p);
if(PtInRect(dataRect,p))
{
SetDlgItemText(IDC_ActTime,"IN");
}else
{
SetDlgItemText(IDC_ActTime,"out");
}
Everything works ok( in and out), until I move tha window. I though, that it chcecks still the old dataRect and I've moved GetDlgItem(IDC_DATA)->GetWindowRect(dataRect); int onPaint(), but it doesn't help. It stills chceks the first position of dataRect. Why?
bubak
 
Because GetCursorPos() reads the coordinates relative to the screen ,not to the window.

Use a CPoint instead of POINT and offset it with the coordinates of the upperleft corner of your dlg.

To read the Rect of the dialog use

CRect rcDialog;
GetWindowRect(&rcDialog);

Hope this helps, s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
yep, i know, but when I do GetWindoRect, I'll get upper left and bottom right point of my dialog and this will be also relative to screen, so I can do just GetCursorPos and PtInRect and it should work fine, i think. but it does not. ;-(
bubak
 
ANOTHER ONE BIG QUESTION ;-)
I have an groupbox IDC_DATAQ, and CRect dataRect.
When I do
GetDlgItem(IDC_DATA)->GetWindowRect(dataRect);
in OnInitDIalog, in dataRect will be values relative to dialog border, but when I do it in OnPaint(), the values in dataRect will be relative to screen. Why?
bubak
 
It is because probably the compiler somehow uses once the GetWindowRect from SDK(even if this takes 2 parameters as I remembewr) and another time the GetWindowRect of the CWnd class.

I didn't try what you say but to better why don't you qualify your functions with :: for the sdk and with this->for the CWnd ones and see what happens.

Also use the two API and CWnd functions
ClientToScreen and ScreenToClient.

Hopet his helps,
s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darkness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top