How to capure mouse move with child window overlapping ?
-
Hi, I have a window that has a some drawing in it and I have this child window that I would use to display information where the mouse is on the drawing. How do I capture mouse movement in the chart window even when the mouse moves over the child window ? I added a handler for WM_MOUSEMOVE to the chart window but when I pass over the child window I don't receive any WM_MOUSEMOVE messages, just when I am over the chart window. I need to get messages also when I am over that child window. I know I could use GetCapture(), but I don't want to click the chart to initiate a GetCapture(), so if I use GetCapture() on that chart window, what would be the best way to know when to call release capture, in other words how do i know, for certain, that the mouse has left the chart window ? thanks, Louis.
-
Hi, I have a window that has a some drawing in it and I have this child window that I would use to display information where the mouse is on the drawing. How do I capture mouse movement in the chart window even when the mouse moves over the child window ? I added a handler for WM_MOUSEMOVE to the chart window but when I pass over the child window I don't receive any WM_MOUSEMOVE messages, just when I am over the chart window. I need to get messages also when I am over that child window. I know I could use GetCapture(), but I don't want to click the chart to initiate a GetCapture(), so if I use GetCapture() on that chart window, what would be the best way to know when to call release capture, in other words how do i know, for certain, that the mouse has left the chart window ? thanks, Louis.
From MSDN: CWnd::SetCapture Causes all subsequent mouse input to be sent to the current CWnd object regardless of the position of the cursor. When CWnd no longer requires all mouse input, the application should call theReleaseCapture function so that other windows can receive mouse input. I think that is what you want to do. MS
-
From MSDN: CWnd::SetCapture Causes all subsequent mouse input to be sent to the current CWnd object regardless of the position of the cursor. When CWnd no longer requires all mouse input, the application should call theReleaseCapture function so that other windows can receive mouse input. I think that is what you want to do. MS
Ok, I tried the SetCapture() and it works fine but I have a problem with the child window that I use to display information. This child window is moveable, but when SetCapture() is called for the chart window I cannot move the child window anymore (not receiving any messages)...I guess I could check with a hit test if the cursor is on the title bar of the child window...but this seems to be becoming a lot of work...is there another way ? thanks for your help I am half way there. Louis
-
Ok, I tried the SetCapture() and it works fine but I have a problem with the child window that I use to display information. This child window is moveable, but when SetCapture() is called for the chart window I cannot move the child window anymore (not receiving any messages)...I guess I could check with a hit test if the cursor is on the title bar of the child window...but this seems to be becoming a lot of work...is there another way ? thanks for your help I am half way there. Louis
You should also be able to trap these messages with PreTranslateMessge. You need to add the handler for PreTranslateMessage (class wizzard). There you can "look" at the mouse messages and see for which window they are. Don' forget to pass them on to their destination. MS
-
You should also be able to trap these messages with PreTranslateMessge. You need to add the handler for PreTranslateMessage (class wizzard). There you can "look" at the mouse messages and see for which window they are. Don' forget to pass them on to their destination. MS
Good idea. I added the handler seems to be working but again when mouse is in child window I dont receive messages. I don't get it, this child (chart info window) is just a child like the chart control. Here's exactly what I have and did: - A dialog that I use for a graph window. - This dialog contains controls and one of those controls is a CStatic derived class that act as a chart control. There is nothing special about the control in how it handles messages except for drawing. - At runtime I create a new dialog that is child of this dialog. This child dialog is the chart info window. To me it should be the same as another control in the dialog. It does nothing special, just contains a static control in which I display text. It has a title bar so I can move it around. - I added a PreTranslateMessage handler to the main dialog and check for the WM_MOUSEMOVE message. If the point lies in the client rectangle of the chart control I display text in the chart info window (static control on that child dialog). So far it works, just that when the mouse is over the chart info window, the main dialog does not receive any WM_MOUSEMOVE in PreTranslateMessage. I really don't understand why I receive message when I am over the chart control in the main dialog but not in the chart info window that is also a child of the main dialog. ?? I hope you get the 'picture', maybe a screenshot of the layout would help ? If so, how do I add an image to a post ? thanks for all your help, Louis.
-
You should also be able to trap these messages with PreTranslateMessge. You need to add the handler for PreTranslateMessage (class wizzard). There you can "look" at the mouse messages and see for which window they are. Don' forget to pass them on to their destination. MS
Seems I found the problem. There is a difference in using a dialog as a child of another dialog then using a basic control. What I did is that I substituted the chart info window (child dialog) for a CStatic control and now it works. Just that I don't have a title bar to move the control around...I should be able to find a way move it by clicking anywhere on it. I beleive there must be a way to make a child dialog work as a basic control...I guess there is a message handler in the dialog that consumes the messages and are not relayed to the parent. Louis.
-
Hi, I have a window that has a some drawing in it and I have this child window that I would use to display information where the mouse is on the drawing. How do I capture mouse movement in the chart window even when the mouse moves over the child window ? I added a handler for WM_MOUSEMOVE to the chart window but when I pass over the child window I don't receive any WM_MOUSEMOVE messages, just when I am over the chart window. I need to get messages also when I am over that child window. I know I could use GetCapture(), but I don't want to click the chart to initiate a GetCapture(), so if I use GetCapture() on that chart window, what would be the best way to know when to call release capture, in other words how do i know, for certain, that the mouse has left the chart window ? thanks, Louis.
I don't know if this will help. But in this entire thread, no one mentioned that a control is another window and only the window over which the mouse is moving gets the WM_MOUSEMOVE messages (not its parents). You don't want to capture the mouse in your main window, because then your child windows will not receive mouse message (they will all go to your main window). If you need to keep track of the cursor position, even when the mouse cursor is over a child window. Then you should start a timer in you main window (in this case your dialog window) and call GetCursorPos to get the screen coordinates of the cursor. Then there is an API function some where (I forgot the name of it), that can be used to get the handle of a window given the screen coordinates, that you need to call to determine which window you are over. If you need to display the coordinates, then you'll probably need to convert the screen coordinates to the local client coordinates. INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen