Hi
I wanna do something when the user place the mouse on a static control...is there a Message i can capture(can't find one)...if not how would i do it? thnx
Printable View
Hi
I wanna do something when the user place the mouse on a static control...is there a Message i can capture(can't find one)...if not how would i do it? thnx
Hmm..but the user has to click a button
WM_LBUTTONDOWN WM_MBUTTONDOWN
WM_RBUTTONDOWN
As far as i understood it...the user has to put the Mouse over the control AND click....i want it without the click..... can someone help??
thnx
Try
TrackMouseEvent()
hmmm i don't know...what about responding to WM_LBUTTONUP
and checking the mouse position with GetCursorPos()
and checking it wether it is within the boundaries of the static
with GetWindowRect()
Is there some easier or better way then this???
hehehe....is this even possible?
thnx:confused:
Is this possible?
No
Not without SetCapture() and a WM_LBUTTONDOWN first
MSDN
"The WM_LBUTTONUP message is posted when the user releases the left mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor."
It may work on a WM_MOUSEMOVE msg after a call to SetCapture()
Use PtInRect() to test teh point is in the contols area. You may need to convert using ScreenToClient() or ClientToScreen()
hmmm...ok then i think i;ll do the following :
1.get the WM_MOUSEMOVE
2.Determine Mouse Position GetCursorPos()
3.The Point i get from 2 will be used in PtInrect()
possible?
case WM_MOUSEMOVE:
POINT pt; // Current mouse point
GetCursorPos(&pt); // Coords of cursor
// Check x position
if ((pt.x >= STATIC_X) && (pt.x <= STATIC_WIDTH)) {
if ((pt.y >= STATIC_Y) && (pt.y <= STATIC_HEIGHT)) {
// This is where you handle the mouse over
// the static control
}
}
break;
STATIC_X and STATIC_Y are the X and Y-Axis that the static control is on and STATIC_WIDTH and STATIC_HEIGHT are the width and height of the static control. This should do what you are wanting to =).
That was exactly what i had in mind....glad that that is doible hehehehe
Well thaks SyntaxBubble and all the others helping me out
if i did it via Syntax bubbles way it would be abit tedious...i am trying to do this:
GetWindowRect(Button_Up,&Up_Rect);
GetWindowRect(Button_Down,&Down_Rect);
GetWindowRect(Button_Left,&Left_Rect);
GetWindowRect(Button_Right,&Right_Rect);
break;
case WM_MOUSEMOVE:
POINT p;
GetCursorPos(&p);
if(PtInRect(&Up_Rect,p)!=0)
{
CPosUp();
}
else if(PtInRect(&Up_Rect,p)==0)
{
MessageBox(NULL,"asd","asd",MB_OK);
}
else if(PtInRect(&Down_Rect,p)!=0)
{
CPosDown();
}
else if(PtInRect(&Right_Rect,p)!=0)
{
CPosRight();
}
else if(PtInRect(&Left_Rect,p)!=0)
{
CPosLeft();
}
break;
But it doesn't work....argggg the msgbox always popsup help..
have tried GetClientRect() but still no go ahhhh!!
Your if else logic is wrong. It can never get to the third if statement as the point is either in the UP rect or not.
Call the getClientRect() under the mouse move msg or make them static. As many msg's are passing thru the callback the rects will have lost scope unless you do.
If you want to make cleaner code try this;
If you create the buttons then create them with consecutive resource IDs.
Or edit the resource.h file so all the buttons have consecutive ID numbers.
Then use a for loop.
Code:for(i=ID_FIRST_CTRL;i<ID_LAST_CTRL;i++)
{
GetClientRect( GetDlgItem(hDlg,i) ,&Rect);
if(PtInRect(&Rect,Point))
iButtonClicked=i;
}