Solved

making a form snap-to the edge of the screen

Posted on 2000-04-15
5
269 Views
Last Modified: 2010-04-04
I should be able to figure this out by myself, but i keep on generating exceptions that crash my machine everytime i try.  So..

here is the question.  I'm trying to make my form (its a non-standard 'skinnable' form shape) snap to the edge of the screen once it reaches a certain distance from it.  I'm thinking I should be able to do this with with the WM_WINDOWPOSCHANGING message, but i'm not all that great with windows messageing yet.
0
Comment
Question by:felonious
  • 2
  • 2
5 Comments
 

Expert Comment

by:perkley
ID: 2719966
This is probably the easiest to understand and control, check it out.  You will want to read the article, and look at Option 3 in particular.

http://www.delphipages.com/news/detaildocs.cfm?ID=24
0
 
LVL 3

Accepted Solution

by:
bryan7 earned 10 total points
ID: 2721554
this is how you do it.. works like winamp


     type
        TMovingSide = wmsz_Left..wmsz_BottomRight;
        TMovingSides = set of TMovingSide;

        TwmMoving = record
          Msg: Cardinal;
          Side: TMovingSides;
          Rect: PRect;
          Result: Longint;
        end;

  private
    DispLeft, DispTop, DispRight, DispBottom: Integer;
    procedure wmEnterSizeMove(var Message: TMessage); message wm_EnterSizeMove;
    procedure wmMoving(var Message: TwmMoving); message wm_Moving;

const
        SnapArea = 25;

procedure TForm1.wmEnterSizeMove(var Message: TMessage);
begin
 DispLeft:=0; DispTop:=0; DispRight:=0; DispBottom:=0;
end;

procedure TForm1.wmMoving(var Message: TwmMoving);
var
 OfsX, OfsY: Integer;
begin
 with Message.Rect^ do begin

  if Abs(DispLeft+Left)<SnapArea then begin
    OfsX:=-Left;
    DispLeft:=DispLeft+Left;
  end
  else begin
    OfsX:=DispLeft;
    DispLeft:=0;
  end;

  if Abs(DispRight+Right-Screen.Width)<SnapArea then begin
    OfsX:=Screen.Width-Right;
    DispRight:=DispRight+Right-Screen.Width;
  end
  else begin
    OfsX:=OfsX+DispRight;
    DispRight:=0;
  end;

  if Abs(DispTop+Top)<SnapArea then begin
    OfsY:=-Top;
    DispTop:=DispTop+Top;
  end
  else begin
    OfsY:=DispTop;
    DispTop:=0;
  end;

  if Abs(DispBottom+Bottom-Screen.height)<SnapArea then begin
    OfsY:=Screen.height-Bottom;
    DispBottom:=DispBottom+Bottom-Screen.height;
  end
  else begin
    OfsY:=OfsY+DispBottom;
    DispBottom:=0;
  end;

  end;
OffsetRect(Message.Rect^,OfsX,OfsY);
end;
0
 

Author Comment

by:felonious
ID: 2721707
sorry perkley, i guess i should have made myself more clear about this question.  i HAVE to work through messageing (as MouseUp MouseMove MouseDown are not usable for my program).

bryan7:  works beautifuly.  thanks very much.
0
 

Author Comment

by:felonious
ID: 2721776
one small problem though.  the form snaps to the the top of the screen just fine, but when the left mouse button is released it jumps down 2-4 pixels.  strange.
0
 
LVL 3

Expert Comment

by:bryan7
ID: 2725061
"ouse button is released it jumps down 2-4 pixels.  s

it doesn't happen in my app..

?¿
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now