1
votes
  1. Create an empty Delphi VCL project
  2. Remove all BorderIcons of main form
  3. Set WindowState to wsMaximized
  4. Run application. Main window appears maximized.
  5. Double click on window title. Main window restores it's size and there is no possibility to maximize it again.

How to prevent window restoring on title double click without hiding title bar?

3
Leaving biMaximize TRUE gives the user the ability to double click the window caption in both ways (also maximizing it again) without showing system icons. Why not just leaving this and instead forcing a crippled window that would still have its problems when the desktop resolution changed? - AmigoJack
My comment shows an approach with advantages only and even points out why yours still has flaws - did you even try it? - AmigoJack
AmigoJack: The solution from Sertac Akyuz fulfills my needs and needs of my customer by 100%. Together with setting of this app as shell it works very well. - Paul
Those are details not mentioned elsewhere, not even in the question - hence I imagined a window plus taskbars and/or multiple monitors. - AmigoJack

3 Answers

4
votes

You can intercept the restore and additionally the move system commands to prevent restoring by dragging the caption.

type
  TForm1 = class(TForm)
  protected
    procedure WMSysCommand(var Message: TWMSysCommand); message WM_SYSCOMMAND;

...

procedure TForm1.WMSysCommand(var Message: TWMSysCommand);
begin
  case Message.CmdType and $FFF0 of
    SC_MOVE, SC_RESTORE: Exit;
  end; 
  inherited;
end;
1
votes

Answer has been edited!

If I got you right, you might want to forbid double-click by title bar in order to prevent restoring form to its original size. You can do that by intercepting WM_NCLBUTTONDBLCLK.

In the example below I've overridden WndProc method of main form and hook forementioned message.

procedure TForm1.WndProc(var Message: TMessage);
begin
  case Message.Msg of
    WM_NCLBUTTONDBLCLK:
      begin
        case TWMNCHitMessage(Message).HitTest of
          HTCAPTION:
            Exit
        else  // Another HitTest-codes are handled here
          Inherited WndProc(Message);
        end;
      end
  else
    Inherited WndProc(Message);
  end;
end;

Important note

Although now you cannot restore maximized form by double-clicking, it still can be restored just by moving it while mouse is captured by title bar. At least, on Windows 7 this effect is presented.
Steps to reproduce:

  • Run application;
  • Press left mouse button while it hovered over title bar;
  • Don't release LMB and move mouse softly - now form restores its size.

Addendum

Fixed bug with incorrect handling another non-client HitTest-codes excepting HTCAPTION (thanks to user Dsm for pointing this out!).

0
votes

I tested some solutions and the one that worked was:

  1. Set Align property to alClient;
  2. Remove biMaximize from BorderIcons property;
  3. Let WindowState wsNormal (default).