View Single Post
Old 12-10-2008, 02:30 PM   #40
rps
Registered
 
Join Date: Oct 2008

Posts: 57
Originally posted by Jim Sachs:
RPS - yes, I agree with your solution. Not sure how long it will take to research how to drag the window without a titlebar, but if you say you've done it, then at least I know that it's not a wild goose chase.  
You have to write event handlers for the following events*:
mouseDown, mouseUp, and mouseMove

You need 3 global variables:

mouseIsDown: boolean;
mouseDownX,mouseDownY: integer;

And then the code for the event handlers looks like this:

event handler: MouseDown(X, Y: Integer);
{
mouseIsDown = true;
mouseDownX = X;
mouseDownY = Y;

}

event handler: MouseUp(X, Y: Integer);
{
mouseIsDown = false;
mouseDownX = 0;
mouseDownY = 0;
}

event handler: MouseMove(x,y)
var
dx, dy: integer;
{
if mouseIsDown {
dx = X - mouseDownX;
dy = Y - mouseDownY;

window.top = window.top + dy;
window.left = window.left + dx;
}
}


Hope this helps!

~Ralph S.


* If you're not using an Object-oriented programming language/framework that provides these event handlers for you, then you'll have to hook WndProc and look for the messages WM_MOUSEDOWN, WM_MOUSEUP, and WM_MOUSEMOVE

Alternatively, when you run your drawing loop, you can check on the mouse position and button status using the functions GetCursorPos and GetAsyncKeyState (with a key value of VK_LBUTTON). However, if you take this approach, you'll have to make sure that the cursor position is within the bounds of the window, and that your application has the focus during when you check for the mouse's new position.

Let me know if you have any questions - I'm a long time (dual monitor) MA fan, and I'm happy to help!
rps is offline   Reply With Quote