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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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
MadshiCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.