Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Koen

capturing the mouse and WM_COMMAND

This topic is 5594 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a pushbutton in a window. When the user presses the left mouse button over the pushbutton, the mouse gets captured by the pushbutton. Once he releases the button, the capture is released. I need this to be able to detect dragging. The problem is that the pushbutton doesn''t generate any WM_COMMAND messages when the mouse is captured. Does anyone know a way around this? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
I suppose a good question is "what are you trying to do that for?"

I can think of a few scenarios when you might want something looking like that, but in all of them it tends to be better to do something a tad more custom than trying to force a button to behave.

I suppose you can always process the WM_LBUTTONDOWN and see if you''re over the pushbutton area, then call the button''s usual message handler.

-fel

Share this post


Link to post
Share on other sites
I''m trying to make a AWT-like set of classes to make GUIs with. I don''t really like any of the toolkits I''ve seen, and I really like the AWT way of doing things. I thought it would be a good (and hopefully useful) exercise. AWT allows all its components to listen to MouseMotion (moving and dragging). To detect dragging correctly I need to capture the mouse every time the left mouse button is pressed. (There probably are other methods that involve more state-information, but it would be nice to use just the windows messages and functions).
Does anyone know why it''s impossible for the button to detect the click if the mouse is captured?

Share this post


Link to post
Share on other sites
Why do you feel you need to do a mouse capture, first off?

Generally mouse captures are used to handle the possibility of moving your cursor entirely outside of the window you''re dealing with.

Unless you''re using "mouse capture" as a term for something other than an actual mouse capture?

-fel

Share this post


Link to post
Share on other sites
No, I mean the same thing you do: using SetCapture(componentHWND) so the mouse can be dragged outside of the control. I want to use this because I want my events to be as close as possible to the java-events. And mousedragging in java lasts as long as the left mousebutton is pressed (even if the mouse is moved outside of the control).

Share this post


Link to post
Share on other sites
Have you considered not capturing until after the button''s event fires? Caputuring on WM_LBUTTONDOWN is generally a bad idea, because it entirely lacks context. That''s why you''re having trouble capturing the click... a CButton is technically a CWnd, and does a good deal of processing internal to its own window scope... if the mouse is captured the messages are forced to the capture context, so the CButton''s CWnd underbelly isn''t going to be getting it to process (which is technically the point of mouse capture, though more to prevent desktop and third party windows from processing mouse events if you want a specific window to be in control regardless).

-fel

Share this post


Link to post
Share on other sites
quote:
Original post by felisandria
if the mouse is captured the messages are forced to the capture context

And why would that be a problem? That''s exactly what I want: every mouse-related message should be sent to the button (even if it actually occured on the parent window, or somewhere else)...
Or am I missing something here?

Share this post


Link to post
Share on other sites
I Think you are talking about mfc, right? I''m not using mfc at all. Only the pure win32 api. So all I have for this button is it''s window handle.

Share this post


Link to post
Share on other sites
That''s why I put the "or" in there. The point of the question is whether or not you''re using the proper window context for the button, rather than whatever construct it''s stuck on.

-fel

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!