Wednesday, March 2, 2011

How to maximize without maximizing

When you maximize a Windows program, it will usually resize to fill up the full screen (minus the space occupied by primary controls such as the task bar). What if you don't want your application to change it's size to the size of the screen, yet you don't want to disable the maximize function? All you have to do is catch and handle the WM_GetMinMaxInfo message.
Assuming that the name of your main form's class is TForm1 and that you want your application to "maximize" to half the size of the screen:

  1. Add the following declaration to the interface section of your application's main form (inside the private, public or protected declarations section):

    procedure _WM_GETMINMAXINFO( 
      var mmInfo : TWMGETMINMAXINFO );
        message wm_GetMinMaxInfo;

  2. In the implementation section, type in the following code:

    procedure TForm1._WM_GETMINMAXINFO( 
      var mmInfo : TWMGETMINMAXINFO );
      // set the position and the size of 
      // your form when maximized:
      with mmInfo.minmaxinfo^ do
        ptmaxposition.x :=
          Screen.Width div 4;
        ptmaxposition.y :=
          Screen.Height div 4;
        ptmaxsize.x     :=
          Screen.Width div 2;
        ptmaxsize.y     :=
          Screen.Height div 2;

Twitter Delicious Facebook Digg Stumbleupon Favorites More

Design by Kang Iwan K-sev | Thank's for your visit To My Site - Ridwan Mulyana | Cibeureum