Archive

Posts Tagged ‘window’

How to Make the Whole Form Behave Like the Title Bar

December 15th, 1999 m3Rlin No comments

Sometimes you want to create a fancy looking form from a bitmap, like WinAMP or K-J?fol. This part isn’t too hard. All you have to do is make a cool graphic, use the TImage component and set the form’s border style to bsNone. Well, all’s good until we want to move the form… Since there is no title bar there may be a problem with this:) Well, as you should already know Delphi can get over any problem. All we have to do is manually take care of the WM_NCHITTEST Windows message.

In this example a TImage component named imgTitle will act like the form’s title bar.

uses
  Messages;
...
  public
    procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
  end;
...
procedure TForm1.WMNCHitTest(var Message: TWMNCHitTest);
var
  P: TPoint;
begin
  inherited;
  P := ScreenToClient(SmallPointToPoint(Message.Pos));
  with imgTitle do
    if (P.X >= Left) and (P.X < Left + Width) and (P.Y >= Top) and (P.Y < Top + Height) then
      Message.Result := htCaption;
end;

How to Set / Remove the Form’s StayOnTop Style

December 15th, 1999 m3Rlin No comments

To set or remove the form’s StayOnTop style you can just set the form’s FormStyle property. But this has side effects. For example: if you modify the form’s system menu using the Windows API. After the form’s style is changed the system menu will return to it’s normal state. You can get around this in a very easy and easy way: using the SetWindowPos() function.

  (* hStyle - (HWND) The form's style. This can be:
  ** - HWND_NOTOPMOST - Removes the StayOnTop atribute.
  ** - HWND_TOPMOST - Sets the StayOnTop atribute
  *)
  SetWindowPos(Handle, hStyle, Left, Top, Width, Height, SWP_SHOWWINDOW);