• Advertisement
Sign in to follow this  

setcapture + titlebar issue

This topic is 2869 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 windowed application, which has a drag function in it (doesn't really matter), so when mouse down, I use SetCapture, when mouse up ReleaseCapture(). This way the dragging works fine, except when the mouse is moved onto the titlebar. The dragged object is placed in a wrong y coordinate (it just goes down very far). When I move the mouse off the titlebar, the object will be in the perfect place, which is strange, because I use delta values to drag it. So the x coordinate is fine. Some code:
case WM_MOUSEMOVE:
	MouseX = LOWORD(lParam); 
	MouseY = HIWORD(lParam);

	MouseDX = MouseX - MousePrevX;
	MouseDY = MouseY - MousePrevY;

	MousePrevX = MouseX;
	MousePrevY = MouseY;

	Drag(MouseDX,MouseDY);
	break;

I know it's because the MouseY should be negative, but HIWORD(lParam) makes an "unsigned" value. I just don't know how to get around it in a neat way in C (a simple (int) cast isn't enough). And I feel so stupid, but I'm not a programmer. So the question is more like: How do I get the signed value of MouseY in a neat way? Sorry for the messy post, I realized the signed/unsigned issue while typing, and thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
You should use the GET_X_LPARAM/GET_Y_LPARAM macros (and #include <WindowsX.h>).

Share this post


Link to post
Share on other sites
Thanks for the tip.
But I realized that the HIWORD/LOWORD stuff are just same bitshifting/masking stuff that I would do, so it doesn't really matter, if it has a nice macro or not.
I guess the GET_Y_LPARAM is just an other stuff like that.

But thanks again anyway.

Share this post


Link to post
Share on other sites
Quote:
Original post by szecs
Thanks for the tip.
But I realized that the HIWORD/LOWORD stuff are just same bitshifting/masking stuff that I would do, so it doesn't really matter, if it has a nice macro or not.
I guess the GET_Y_LPARAM is just an other stuff like that.

But thanks again anyway.


The difference is just that GET_X_LPARAM/GET_Y_LPARAM has some casts to signed types, so it unpacks the signed values by casting to short and then to int. If you just cast it to int, it won't work because what HIWORD/LOWORD gives you is only 1 word.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement