BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Forms Docking to Desktop edges?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
qyte
Guest





PostPosted: Tue Mar 15, 2005 2:23 pm    Post subject: Forms Docking to Desktop edges? Reply with quote



Does anyone know what can i do so that a form can attach to the desktop
edges when dragging it?

I don't know anything on the matter.
a good description would be great.
Back to top
Dirk Schnitzler
Guest





PostPosted: Thu Mar 24, 2005 4:20 pm    Post subject: Re: Forms Docking to Desktop edges? Reply with quote




"qyte" <gyte (AT) vivodinet (DOT) gr> schrieb im Newsbeitrag
news:4236efc4 (AT) newsgroups (DOT) borland.com...
Quote:
Does anyone know what can i do so that a form can attach to the desktop
edges when dragging it?

I don't know anything on the matter.
a good description would be great.

My code should be very easy to follow...

Sample header file:

class TfrmMain : public TForm
{
__published:
private:
public:
__fastcall TfrmMain(TComponent* Owner);
bool AllowOutside;
void __fastcall OnFormMove(TWMMove aMsg);
protected:
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(WM_MOVE, TWMMove, OnFormMove)
END_MESSAGE_MAP(TForm)
};

Sample cpp file:

file://---------------------------------------------------------------------
------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
: TForm(Owner)
{
AllowOutside = false;
}
file://---------------------------------------------------------------------
------

void __fastcall TfrmMain::OnFormMove(TWMMove aMsg)
{
static int OldLeft = Left;
static int OldTop = Top;
if(OldLeft!=Left || OldTop!=Top){
file://Form has been moved... check distance to screen borders:
int Right = Left + Width;
int Bottom = Top + Height;
int BottomBorder = Screen->WorkAreaTop+Screen->WorkAreaHeight;
int RightBorder = Screen->WorkAreaLeft+Screen->WorkAreaWidth;

if(Left>0 || !AllowOutside){
if(Screen->WorkAreaLeft+SNAP_DIF_X >= Left){
Left = Screen->WorkAreaLeft;
}
}
if(Right<RightBorder || !AllowOutside){
if(Right >= RightBorder-SNAP_DIF_X){
Left = RightBorder-Width;
}
}
if(Top>0 || !AllowOutside){
if(Screen->WorkAreaTop+SNAP_DIF_X >= Top){
Top = Screen->WorkAreaTop;
}
}
if(Bottom<BottomBorder || !AllowOutside){
if(Bottom >= BottomBorder-SNAP_DIF_Y){
Top = BottomBorder-Height;
}
}
}
OldLeft = Left;
OldTop = Top;
}

Regards,
Dirk.




Back to top
Dirk Schnitzler
Guest





PostPosted: Thu Mar 24, 2005 4:30 pm    Post subject: Re: Forms Docking to Desktop edges? Reply with quote




Ok, since the OnMove event isnīt fired when you move
around the form and put it back on itīs original position,
you can save the static variables...

void __fastcall TfrmMain::OnFormMove(TWMMove aMsg)
{
int Right = Left + Width;
int Bottom = Top + Height;
int BottomBorder = Screen->WorkAreaTop+Screen->WorkAreaHeight;
int RightBorder = Screen->WorkAreaLeft+Screen->WorkAreaWidth;
if(Left>0 || !AllowOutside){
if(Screen->WorkAreaLeft+SNAP_DIF_X >= Left)
Left = Screen->WorkAreaLeft;
}
if(Right<RightBorder || !AllowOutside){
if(Right >= RightBorder-SNAP_DIF_X)
Left = RightBorder-Width;
}
if(Top>0 || !AllowOutside){
if(Screen->WorkAreaTop+SNAP_DIF_X >= Top)
Top = Screen->WorkAreaTop;
}
if(Bottom<BottomBorder || !AllowOutside){
if(Bottom >= BottomBorder-SNAP_DIF_Y)
Top = BottomBorder-Height;
}
}


Back to top
Dirk Schnitzler
Guest





PostPosted: Thu Mar 24, 2005 4:33 pm    Post subject: Re: Forms Docking to Desktop edges? Reply with quote

I hope this is the last time .... Sad
Change it to:

if(Top>0 || !AllowOutside){
if(Screen->WorkAreaTop+SNAP_DIF_Y >= Top)
Top = Screen->WorkAreaTop;
}

Instead of:

Quote:
if(Top>0 || !AllowOutside){
if(Screen->WorkAreaTop+SNAP_DIF_X >= Top)
Top = Screen->WorkAreaTop;
}

Regards,
Dirk.




Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.