setcapture + titlebar issue

Started by
3 comments, last by szecs 14 years, 1 month ago
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!
Advertisement
You should use the GET_X_LPARAM/GET_Y_LPARAM macros (and #include <WindowsX.h>).
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.
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.

Yup, I looked at the macro:

(int)(short)stuff

*facepalm*
I'll jump out of the window right now.

This topic is closed to new replies.

Advertisement