Solved

making a form snap-to the edge of the screen

Posted on 2000-04-15
5
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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 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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

738 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