# setcapture + titlebar issue

## 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

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

#### Share this 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

##### Share on other sites
Quote:
 Original post by szecsThanks 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

##### Share on other sites
Yup, I looked at the macro:

(int)(short)stuff

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

## 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

• ### Forum Statistics

• Total Topics
627737
• Total Posts
2978873

• 10
• 10
• 21
• 14
• 12