Solved

making a form snap-to the edge of the screen

Posted on 2000-04-15
5
274 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Making delphi communicate with a c# service 16 112
Delphi IDE crash without error message ... 7 99
control image tags in a string ? 12 142
How to convert memory stream to PDF file 6 123
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 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