Solved

making a form snap-to the edge of the screen

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month3 days, 15 hours left to enroll

630 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