Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

making a form snap-to the edge of the screen

Posted on 2000-04-15
5
Medium Priority
?
282 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 40 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

715 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