unit Wordcap;
{**********************************************************************}
{** WordCap  - provides a gradient filled caption bar, with Italic   **}
{**            text, in the style of MSOffice for Win95.             **}
{** ---------------------------------------------------------------- **}
{** Author   - Warren F. Young.                                      **}
{** e-mail   - wfy@ee.ed.ac.uk,                                      **}
{** WWW      - http://www.ee.ed.ac.uk/~wfy/components.html           **}
{**            If the above email does not work then (and only then) **}
{**            try this e-mail address:  WMYoung@compuserve.com      **}
{** ---------------------------------------------------------------- **}
{** Suggested Usage                                                  **}
{**          - For a 32-bit installation you need the files          **}
{**            wordcap.pas and wordcap.dcr.                          **}
{**          - For a 16-bit installation you need the files          **}
{**            wordcap.pas and wrdcap16.dcr (renamed to wordcap.dcr).**}
{**          - Install the component "WordCap.pas" into Delphi.      **}
{**          - Place the component on your form. (TMSOfficeCaption)  **}
{**          - Set the parameters in the object inspector            **}
{**          - You have a shaded caption bar - LIVE AT DESIGN TIME!! **}
{** ---------------------------------------------------------------- **}
{** History                                                          **}
{**   - Version 1.00  (23/July/1996). Initial release (WWW).         **}
{**   - Version 1.01  (06/August/1996). Fixed a system resources bug **}
{**       caused by (bmp.left > bmp.right).                          **}
{**   - Version 1.02  (09/August/1996).                              **}
{**   - Version 1.03  (15/August/1996).                              **}
{**       with 32bit calls from 16bit apps (if available).           **}
{**   - Version 1.04  (15/August/1996).                              **}
{**       with fixed up AutoHeight routine.                          **}
{**   - Version 1.05  (20/August/1996).                              **}
{**       with AppNameText property.                                 **}
{**   - Version 1.06  (30/August/1996).                              **}
{**       with improved AUTO option for Position property.           **}
{**   - Version 1.10  (1/October/1996).                              **}
{**       re-Released on WWW.  First official release.   Sent to     **}
{**       Delphi SuperPage and Torry's Delphi Pages.                 **}
{**   - Version 1.11  (6/November/1996).                             **}
{**       Fixed problem with large borders on windows.               **}
{**   - Version 1.2   (17/December/1996).                            **}
{**       Fixed problem flickering (in 32bit version only).          **}
{**       Some code borrowed with permission from Brad Stowers.      **}
{**   - Version 1.21  (19/December/1996).                            **}
{**       Fixed drawing problems (in 32bit version only) when using  **}
{**       geWhenActive, and changing the caption.                    **}
{**   - Version 1.22  (22/December/1996).                            **}
{**       Fixed drawing problems in WinNT 4.x.  Fixed some but not   **}
{**       all MDI child drawing problems.                            **}
{**   - Version 1.23  (24/December/1996)                             **}
{**       Fixed more MDI drawing problems, and offered a band-aid    **}
{**       for another.                                               **}
{**   - Version 1.24  (26/December/1996)                             **}
{**       Corrected another MDI drawing problem, and tidied up the   **}
{**       code a bit.                                                **}
{**   - Version 1.25  (28/December/1996)                             **}
{**       Removed flicker on NCActivate Message.  Removed automatic  **}
{**       updating (after property changes) at run-time.             **}
{**   - Version 1.26  (02/January/1997)                              **}
{**       Improved the icon painting routine for the 32 bit version  **}
{**       16 bit version left the same.                              **}
{**   - Version 1.27  (03/January/1997)                              **}
{**       Moved 16 bit type declarations & global variables to the   **}
{**       implementation section.                                    **}
{**   - Version 1.28  (11/January/1997)                              **}
{**       Tidied up a bit.  Added GetWindowRgn_NoCaption.            **}
{**   - Version 1.29  (13/January/1997)                              **}
{**       Added a caption refresh when destroying.                   **}
{**   - Version 1.30  (24/January/1997)                              **}
{**       Removed MyOwner.Refresh (very minor).  Reduced spacing     **}
{**       between successive caption parts.  Sent to Delphi          **}
{**       SuperPage and Torry's Delphi Pages.                        **}
{**   - Version 1.31  (28/January/1997)                              **}
{**       Fixed 32-bit problem of drawing active after being         **}
{**       deactivated - (e.g. when focus went to the desktop).       **}
{**       Added 16-bit access to 32-bit drawing routines for icon    **}
{**       drawing but not for regions/flicker control.               **}
{**   - Version 1.32  (20/February/1997)                             **}
{**       Fixed 32-bit problem of caption flicker when the           **}
{**       CaptionText.Caption property was changed at run-time.      **}
{**   - Version 1.33  (28/February/1997)                             **}
{**       Added Freeze/UnFreeze routines to simplify updating the    **}
{**       caption without flickering - useful for MDI apps which     **}
{**       must handle this themselves.                               **}
{**   - Version 1.34  (3rd/April/1997)                               **}
{**       Fixed up a resource leak when painting icons.              **}
{**   - Version 1.35  (6th/April/1997)                               **}
{**       Fixed up MemSleuths reported resource leak when changing   **}
{**       the caption, and processing WM_NCACTIVATE.  New            **}
{**       recomendations for handling MDI problems.                  **}
{**   - Version 1.36  (10th/April/1997)                              **}
{**       Changed CaptionTexts implementation, so that the form's    **}
{**       caption = Company+AppName+Caption texts.  This brings the  **}
{**       component closer to the behaviour of MSOffice programs.    **}
{**   - Version 1.37  (22nd/April/1997)                              **}
{**       Added geSmart option to Enabled property.  geSmart         **}
{**       implements shading if there is enough color depth.  This   **}
{**       is what MSWord95 does, except that MSWord does the test    **}
{**       only once at startup.  I do it every time.  Allowed for    **}
{**       minimize button wihtout maximize button in Win3.1 style.   **}
{**       Fixed a minor bug when AppNameText was '' and invisible.   **}
{**   - Version 1.38  (25th/April/1997)                              **}
{**       Allowed Hookwin and UnHookwin to be called externally.     **}
{**       This allows users to get around the hassle of changing     **}
{**       TForm properties such as the bordericons and position at   **}
{**       run-time.  See below for some code to fix it up.           **}
{**   - Version 1.39  (28th/April/1997)                              **}
{**       Checked for TForm centering problem in Loaded method.      **}
{**       Corrected detection of biHelp button in 32 bit version.    **}
{**   - Version 1.40  (15th/May/1997)                                **}
{**       Small correction to allow compilation in Delphi 1.         **}
{**   - Version 1.41  (26/June/1997)  Tried to fix problem of every  **}
{**       window redrawing when apps start and stop.                 **}
{**       Tried to fix errors in TCaptionText.GetCaption routine.    **}
{**       Tried to fix icon drawing error for 16-bit apps on WinNT4  **}
{**       32bit apps with Win95 style captions now draw the min/max/ **}
{**       close/help buttons themselves -instead of windows doing it.**}
{**   - Version 1.42  Added an onDrawCaption event. Fixed up the bug **}
{**       of blank captions being lost when reloaded into Delphi.    **}
{**       Return form.caption to original value after deleting this  **}
{**       component.  Also added Justification property.             **}
{**       Removed the Freeze methods.                                **}
{**   - Version 1.43  (18/September/1997) Added SWP_NOACTIVATE       **}
{**       parameter to SetWindowPos call in UpdateCaption - this     **}
{**       means that the window order can't be corrupted.            **}
{**       Removed redundant GetWindowRgn_NoCaption function          **} 
{**   - Version 1.44  (02/October/1997) Now catches the              **}
{**       recreation of window handles - thanks to Jordan Russell    **}
{**       for his suggestions and sample code for this.  This fixes  **}
{**       the bug of the disappearing caption when a form property   **}
{**       was changed  (e.g. position:= poScreenCenter;              **}
{**   - Version 1.45  (11/November/1997) Allows different colours    **}
{**       at boths ends of the caption.                              **}
{** ---------------------------------------------------------------- **}
{** Copyright- copyright 1996, 1997 by Warren F. Young.             **}
{**            Free to use and redistribute, but my name must        **}
{**            appear somewhere in the source code.  No warranty     **}
{**            is given by the author, expressed or implied.         **}
{** ---------------------------------------------------------------- **}
{** Note about MDI Applications                                      **}
{**            MDI Applications will have a drawing problem with     **}
{**            this caption component which occurs when a new child  **}
{**            is created, and that child is maximized.  To work     **}
{**            around this problem, see the file MDI_Apps.txt for    **}
{**            some code to add to the Child window creation routine.**}
{**            (Yes I know it's a nuisance - if you know a better    **}
{**            solution then please e-mail me).                      **}
{** ---------------------------------------------------------------- **}
{** Known Limitations                                                **}
{**          - In D2 (Win95), when a form is maximized and restored, **}
{**            it zooms, and the caption draws non-shaded.           **}
{**          - The 16-bit version flickers on redraw.  In Win3.x     **}
{**            this is unavoidable.  In Win95 (D1) it may be         **}
{**            possible to fix it by calling some 32-bit functions.  **}
{** ---------------------------------------------------------------- **}
{** Possible Changes/Improvements                                    **}
{**          - In D1 (Win95), try accessing 32bit routines in order  **}
{**            to reduce or remove flickering when redrawing.        **}
{**            (I have tried this and failed on GetWindowRgn and     **}
{**            SetWindowRgn - it compiled but they had no effect).   **}
{**            I may try again with LockWindowUpdate.                **}
{**          - Add a property called Spacing (or similar), to        **}
{**            determine the amount of space between Company and     **}
{**            AppName text, and AppName and Caption text.           **}
{** ---------------------------------------------------------------- **}
{** Disclaimer                                                       **}
{**          - I take no responsibility for any losses suffered      **}
{**            resulting from use or misuse of this code.  It is     **}
{**            freeware, with source code, and so you use (and       **}
{**            maintain) it at your own risk.                        **}
{**********************************************************************}
Good luck and happy programming.