case WM_MOUSEMOVE:
if(SelectedEvent)
{
p1.x = p2.x = LOWORD(lParam);
p1.y = p2.y = HIWORD(lParam);
ClientToScreen(this->Handle, &p1); //convert this windows pos to screen space
ScreenToClient(this->mhGraph, &p1); //convert the screen space, to the parent window, of the selected window
SetWindowPos(SelectedEvent->Handle, 0,p1.x - 5, p1.y - 5, 0, 0, SWP_NOSIZE);
}
return 0;
case WM_LBUTTONDOWN:
MessageBeep(1);
SelectedEvent = this;
return 0;
case WM_LBUTTONUP:
SelectedEvent = 0;
return 0;
Moving a child window
Hi,
I have a child window, which has no title bar or anything, and would like to implement my own moving code, so that when the user clicks on the area of the client window, they can then drag it.
The problem im having is that the WM_MOUSEMOVE commands, dont seem to update often enough, and unless you move the mouse really slow, the cursor goes out of the window while you still have it clicked.
im doing the following at the moment, and its behaving horrid, can anyone give me any pointers?
You only get WM_MOUSEMOVE messages while the mouse is over your window. If you want to continue to get them when the mouse leaves the window, call SetCapture when the drag starts, then ReleaseCapture when you're finished (WM_LBUTTONUP).
WOuldn't it be possible to use a boolean to track the mouse button? so if you press the mouse button, you set the boolean to true and when you release the mousebutton you set the boolean to false. then, when you drag the mouse you can just check the current state of the button by checking the boolean.
In you code you do this by remembering the mousedown event, and then taking the mouse handle from that event. I would think the mousemove event would have it's own event with it's own handler, why not pass that one on to SetWindowPos. Since this event would hold the position of the mouse at the time of the move, instead of at the time of the mousedown event.
In you code you do this by remembering the mousedown event, and then taking the mouse handle from that event. I would think the mousemove event would have it's own event with it's own handler, why not pass that one on to SetWindowPos. Since this event would hold the position of the mouse at the time of the move, instead of at the time of the mousedown event.
sorry, could you explain a little more?, how do i then get the coordinates to set the child window to? (from setcapture)
Quote:Original post by streamer
EvilSteve has the point [smile]
No, it's the wrong method.
Use a boolean as it has been said and it's automatic with HT
Let Windows do the work:
Override WM_NCHITTEST for the child window and have it return HTCAPTION for the draggable area. Windows thinks you clicked on the caption and enters its own dragging loop.
Override WM_NCHITTEST for the child window and have it return HTCAPTION for the draggable area. Windows thinks you clicked on the caption and enters its own dragging loop.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement