Capture window movement message on Linux lazarus / 8-Other ---------------------------------------------------------------------- Gl3nn · 2009-11-16 22:05 Hi there I remember from the Delphi days that you could intercept the window movement message and make a borderless form moveable by sending a custom movement message. As i understand the LCL correctly its best practice not to use messages when possible. However im stuck finding out how the LCL handles movement messages on Linux. What is the best practice in this area? In short, i want to move a borderless form on Linux. best regards Glenn ---------------------------------------------------------------------- Mike J · 2009-11-19 01:16 Select the parent form. Change border style to none. Goto Events. Double Click 'OnMouseMove' event: Pattern after: Code: [Select]procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,   Y: Integer);     var P : TPoint; begin      if Shift = [ssLeft] then begin   P := ClientToScreen(Point(X, Y)); SetBounds(P.X, P.Y, Width, Height);      end; end;  Adapted from: http://bugs.freepascal.org/print_bug_page.php?bug_id=14687 Note: The mouse OFFSET into the form really needs to be taken into account to prevent the 'JUMP' when you first click it. This code does not do that. ---------------------------------------------------------------------- Mike J · 2009-11-21 15:23 How to take mouse position on form into account: Create a new project. Create a blank form. Change border type to none. For this example, I will leave the default name of 'Form1'. //for this example Save all your files. Goto the global var section for Form1. Add: Code: [Select]  MouseX, MouseY: Integer; Using the object inspector on Form1, create an event handler for 'OnMouseDown'. The purpose of this event handler is to record the mouse position on the form for use later. Code: [Select]procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;   Shift: TShiftState; X, Y: Integer); begin      if [ssLeft] <= Shift then begin //only interested in left mouse button...                                   //using <= as we are dealing with SETS.         MouseX := X; //used later as an offset for the move         MouseY := Y; //used later as an offset for the move      end; end; Now for the actual movement. We will respond the OnMouseMove event, as the setbounds sets the upper left corner of the mainform, we have to subtract out the form relative position of the mouse pointer from the new screen position so that the top left corner stays relative to the mouse during the move. Code: [Select]procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,   Y: Integer);     var P : TPoint; begin      if [ssLeft] <= Shift then begin //only left mouse button again.                                   //using <= as we are dealing with SETS.   P := ClientToScreen(Point(X, Y)); //convert to screen relative numbers instead of form relative numbers. SetBounds(P.X-MouseX, P.Y-MouseY, Width, Height); //Move form to new location. //Note that we subtract the mouse's relative position in regards to the upper left of the form.      end; end; ---------------------------------------------------------------------- Gl3nn · 2009-11-22 10:52 Wow thanks a lot to mjoyner and Paul Ishenin especially the second post did the trick. this solution is more versatile across platforms than the Delphi way now im finally able progress with an open source skinning system for Lazarus application. thanks again ./Glenn ---------------------------------------------------------------------- Mike J · 2009-11-22 13:01 You also need to thank "Paul Ishenin" from the bug report I referenced. It was his code fragment that I deciphered and expanded to provide the answer. ---------------------------------------------------------------------- Gl3nn · 2009-11-22 13:33 true, and its corrected now fairs fair maybe one should start writing a book about all the aspects of cross platform programming with Lazarus/Free Pascal which also can act as a reference for both beginners and advanced users? even though we have the wiki, its still good (in my opinion) to have a physical book which explains all the pitfalls one should be aware of when programming towards a specefic or different platforms best regards Glenn ---------------------------------------------------------------------- Mike J · 2009-11-22 13:39 At the moment I am following along in "Sams Teach Yourself Borland Delphi 4" and it is matching up pretty good. Available on Amazon used for like $0.90 + $3.99 shipping. The biggest thing I am have run into so far though, is when I go through the LCL, etc documentation, I can't figure out the different properties, etc for the different forms and other objects in any type of coherent fashion. Also still trying to find a decent book that teaches both procedural programming *and* object oriented programming in Pascal. Waiting on one more book to look inside of before going out and shopping again. ---------------------------------------------------------------------- Gl3nn · 2009-11-22 13:58 Quote from: mjoyner on November 22, 2009, 02:39:01 pmThe biggest thing I am have run into so far though, is when I go through the LCL, etc documentation, I can't figure out the different properties, etc for the different forms and other objects in any type of coherent fashion. It isn't that difficult to get the hang of Try posting some of the issues here you have difficulties to understand and i'll try to explain it as best as i can Quote from: mjoyner on November 22, 2009, 02:39:01 pmAlso still trying to find a decent book that teaches both procedural programming *and* object oriented programming in Pascal. Waiting on one more book to look inside of before going out and shopping again. The book "Mastering Delphi 7" by Marco Cantú is really good and thorough. Even though its a whopping 1000 pages book it has many things that reflect the way one work with Lazarus/Free Pascal. Personally i use it a lot as reference best regards Glenn ---------------------------------------------------------------------- Mike J · 2009-11-22 14:11 I have been spoiled. Looking for something like 'C: A Reference Manual'. ---------------------------------------------------------------------- Gl3nn · 2009-11-22 14:15 if you dont want to chew through 1000 pages, then the Delphi 3 manual is also a good choice best regards Glenn ---------------------------------------------------------------------- Mike J · 2009-11-22 14:20 It's not the page count, structured reference of available functions and variations thereof in a non-teaching format is what I am used to referencing... ---------------------------------------------------------------------- Gl3nn · 2009-11-22 14:32 hmm maybe Delphi 5 Object Pascal Language Reference by Borland is what you're seeking? it has a lot about classes and objects too. best regards Glenn