Sign in to follow this  
szecs

setcapture + titlebar issue

Recommended Posts

szecs    2990
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
szecs    2990
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
pablo24    156
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this