5

I want to drag this character. Image :

enter image description here

so i use this method to get mouse position:

WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    ...
    switch (message){
    case WM_LBUTTONDOWN:
    case WM_MOUSEMOVE:
        GetCursorPos(&mousePosition);
        break;
    }
    ...
}

The program seems to be running well, but if the mouse is out of the characters location, it wouldn't follow the mouse cursor anymore.

How can I fix this problem?

1
  • Your link doesn't work. Permission denied. Commented May 3, 2014 at 9:52

1 Answer 1

5

See SetCapture on MSDN:

Sets the mouse capture to the specified window belonging to the current thread. SetCapture captures mouse input either when the mouse is over the capturing window, or when the mouse button was pressed while the mouse was over the capturing window and the button is still down. Only one window at a time can capture the mouse.

SetCapture..ReleaseCapture lets you temporarily extend your mouse event handling to space outside the window [where the event originated from].

You have some sample/demo here:

switch (uMsg) 
{ 
   case WM_LBUTTONDOWN: 

        // Capture mouse input. 
        SetCapture(hwndMain); // <<--- Here we go
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.