C++ Win32 API MoveWindow to Mouse Co-ordinates

1
2
3
4
case WM_RBUTTONDOWN:
   ShowWindow (hWndChild [3], SW_SHOW);
   MoveWindow (hWndChild [3], LOWORD (lParam), HIWORD (lParam), 200, 200, false);
break;


I have that code in a window's window prcoedure function, every time I right click though it uses the window's parent window's mouse location, and not its own mouse location. I'm using different window procedure functions too.

Anyone know how to move the window's X and Y axis starting points to the location of the mouse? Thanks.
Last edited on
....

:D
You need to provide a much clearer description of your problem some random dude. Several days ago when you posted that I read through it several times trying to figure out what you were asking, and I couldn't make heads or tails out of it. I imagine others tried too. I'm quite sure you understand what you are asking, but its my guess no one else does. You need to ask questions in a clearer manner, in my opinion.
After re-reading it I see how it was messy, lol. But I actually just came to this thread to say that I figured it out, but thanks any way :)
For anyone else who wants it..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <windows.h>

BOOL MoveWindowToMouse(__in HWND hWnd)
{
  POINT p;
  RECT  pr;
  BOOL  bRET = FALSE;

  if (GetCursorPos(&p))
    if (GetWindowRect(hWnd, &pr))
      if (MoveWindow(hWnd, p.x, p.y, pr.right - pr.left, pr.bottom - pr.top, TRUE))
        bRET = TRUE;

  return bRET;
}


I think that should work :3
closed account (3pj6b7Xj)
Yup that will work only it will work ALL THE TIME lol.

He needs to capture to WM_LBUTTONDOWN and use that very same code inside a loop that remains TRUE while WM_LBUTTTONDOWN is taking place, thats the fun part! :)
Topic archived. No new replies allowed.