Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving a window / form

Status
Not open for further replies.

mikeo2l

Technical User
Sep 27, 2001
20
IE
Can some one tell me how do I move a window/form onmousedown?
I don't need the code just a pointer to the correct functions.

I have set the form to hide the borders, menu, etc. I am simply trying to access the normal functions on a mousedown event but my Builder Help crashes.

While I'm at it when I open a popup menu it opens at 0,0 of the parent window (only one window open so it opens at top left of screen) What functio return the current position of the active window/form?

Thanks
 
I'm not sure if this is really what you're asking, but here's an answer anyway.

To set a form location, you set the Left and Top property of the form, and to read the location, you read the Left and Top property.

So, for instance, If I want to move the form top/left to where the cursor is in my MouseDown event, I would do the following:
Code:
void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button,
      TShiftState Shift, int X, int Y)
{
  Form1->Left += X;
  Form1->Top += Y;
}
This should answer your 2nd question too. The Left and Top properties give you the current position of the form.

Hope this helps.
 
Many Thanks.

I will try this out. I am adding code to move the window onmousedown mainly because I have hidden the menu bar of the window. In C I can use wherex() and wherey() to return the position of the cursor/mouse how do I do this in C++ (Borland Builder). I would have imagined this code would be freely available but I have not found it in many searches of code sites.

Could you recommend a couple of good code sites. I am new to C++ but not C.

Mike
 
Could you recommend a couple of good code sites. Start with faq101-913. Some of these are old and may not be up but there are some real gems there.

James P. Cottingham

There's no place like 127.0.0.1.
There's no place like 127.0.0.1.
 
wherex() & wherey() don't work in win32 gui apps, they are DOS holdovers.

To determine the mouse cursor position in builder you can do the following:

To get the absolute screen coordinates of the mouse cursor:
Code:
Mouse->CursorPos.x;
Mouse->CursorPos.y;
To get the relative mouse cursor coordinates do:
Code:
TPoint P = Mouse->CursorPos;
P = Form1->ScreenToClient(P);
Now, P.x & P.y give you the cursor position within Form1. To determine the absolute screen coordinates from P.x & P.y, you add these coordinates to the Form1->Left & Form1->Top coordinates.

As far as code sites, look at the thread 2ffat recommended.

There's really no substitute for a good book. If you don't want to purchase one, a place to start is with Charlie Calvert's C++ Builder Unleashed. It's a bit outdated, but is freely available in html format all over the web.

I just googled for it & came up with:

Hope this helps,

Good Luck!
 
Many Thanks Lads

The code has worked. I manage to the moving windows last night but did not know how to return the mouse position.

Strange I could not find any reference to it in the help.


"~ Mouse->CursorPos.x; Mouse->CursorPos.y; & P.x & P.y give you the cursor position within Form1." this bit is what I wanted :)

Every think I needed to know is answered in these replies.

Thanks Thanks Thanks

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top