Don't let the Form go out the desktop

Hi Expert
I'd like to move one of my form around the desktop without let it to go out the screen.
When I move it down I'd like to choose in a checkbox if it can go more down then the taskbar or not.
(I want a dock effect without resizing my form)
Can you understand me ?

Thank you in advance.

Andrea.
borgoAsked:
Who is Participating?
 
MadshiConnect With a Mentor Commented:
Removing the "then" was alright. But please do this in the last line:

  Message.result := 0;

I forget the "Message." before the result...   :-)

Regards, Madshi.
0
 
MadshiCommented:
Handle the WM_WINDOWPOSCHANGING message. There's all you need.

Regards, Madshi.
0
 
borgoAuthor Commented:
Hi Madshi
Do I have to check the form position in relation with the desktop size on the event TForm.OnMove ?

Have a good 2k without any bugs :-)
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
MadshiCommented:
No, OnMove will not help, since it's then to late to change anything. You need to use WM_WINDOWPOSCHANGING.

type
  TForm1 = class (TForm)
  private
    procedure WindowPosChanging(var Message: TMessage); message WM_WINDOWPOSCHANGING;

Then you can use SystemParametersInfo(SPI_GETWORKAREA) to ask the screen rectangle without the taskbar.

Regards, Madshi.
0
 
borgoAuthor Commented:
Hi Madshi

How many points would you like for some code ? :-)

See you.
0
 
MadshiCommented:
Well, I'll try to write something out of my mind. We'll see if you can compile it...   :-)

procedure TForm1.WindowPosChanging(var Message: TMessage);
var r1 : TRect;
begin
  SystemParametersInfo (SPI_GETWORKAREA, 0, @r1, 0) then
  with PWindowPos(Message.lParam)^ do begin
    if y + cy > r1.bottom then
      y := r1.bottom - cy;
    if y < r1.top then
      y := r1.top;
    if x + cx > r1.right then
      x := r1.right - cx;
    if x < r1.left then
      x := r1.left;
  end;
  result := 0;
end;

Regards, Madshi.
0
 
borgoAuthor Commented:
Hi Madshi
Great, it's work
I have removed the "then" on the 7 row and the "result := 0" row.
Did I the right thing ?
Thank you and please reply for the points.
(Today I have also posted a new question on EE)
Have a nice day and thank you again.
Andrea.
0
 
borgoAuthor Commented:
Thank you Madshi

please reply to this question for points:

http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10257419 

Have a nice day.

Andrea
0
All Courses

From novice to tech pro — start learning today.