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 

Delphi Docking Close Event (Guide)

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Using
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Mon Jun 26, 2006 3:08 pm    Post subject: Delphi Docking Close Event (Guide) Reply with quote



Okay, well after fighting and fighting with Delphi and docking.. And
searching the groups for any information about this (which I haven't
found, just a question).. I decided, with my pride to tackle it anyway.

I am posting this to save people headaches and giving up when they are
dealing with closing a docked control. I've tested this with a form
and a panel, I'm not sure if it'll work with other scenarios but it
should. Anyway, what you want to do, is first subclass or override the
'dock site', in this case a tpanel and listen for these two messages:

CM_UnDockClient and CM_DockNotification.

It all depends on what you have your form set to, if on the close, you
set it to caFree, it will send a CM_UnDockClient event.. If it's set to
caHide (the default behaviour), it will send a CM_DockNotification.


CM_UnDockClient:

It sends this when you undock it (by grabbing it and dragging it out),
or when you close a window when it's in there.

The LParam holds the Control, so to check if it's getting free'd we do:
IF csDestroying IN TControl (Msg.LParam).ComponentState Then
UnDockStuff;

The UnDockStuff is well, whatever you want it to do.. I use it to 'hide
the panel' again.
Warning: DO NOT CALL 'DoUnDock' OR 'ManualDock' IN HERE! It will
trigger undocking messages again and cause an infinite loop.


CM_DockNotification:

This time LParam is a pointer to a TDockNotifyRec.
We want to find out if Delphi sent us a CM_VisibleChanged (because
well, if it's set to caHide, it's just changing the visibility right?
And what happens when we change the Visible property? We get sent a
CM_VisibleChanged message!)

So we check for it:
IF PDockNotifyRec (Msg.LParam)^.ClientMsg = CM_VisibleChanged Then
UnDockStuff;

Of course once again, UnDockStuff is whatever you want.


And there you have it! That's how you find out if a form was closed
when it was docked.
(P.S. No UnDock does not get called for some reason when you close it,
you have to take advantage of these methods)

Of course it might look a bit long, but really here is the only code
you'll need in your message handler (assuming the parameter is Msg).

Case Msg.Msg OF

CM_UnDockClient :
Begin
IF csDestroying IN TControl (Msg.LParam).ComponentState Then
UnDockStuff;
End; { UnDock Client }

CM_DockNotification :
Begin
IF PDockNotifyRec (Msg.LParam)^.ClientMsg = CM_VisibleChanged
Then UnDockStuff;
End; { Dock Notification }

End; { Case }

Don't forget to give me credit if you use this information and spread
it around!

- Dennis Fehr
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Using 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.