Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 Adjusting form size to accommodate a required client size


How do I adjust my form size to accommodate a required client size?   

    You can make a call to the Windows API function AdjustWindowRectEx(). This function takes in a rectangle of your requested client size in screen space, and returns a rectangle containing the required window size and position to accommodate the request. Notes: 1) The returned rectangle may be larger than the screen. 2) The form's client area may be reduced by the automatic addition of scroll bars. 3) Windows containing title bars have a minimum size allowed by the system, and cannot be made smaller. 4) Menus may form multiple menu bars if the Window is sized too small for the menu to display on a single line. The AdjustWindowRect() function does not take this into account. Example:

    procedure TForm .Button Click(Sender: TObject);
    var
      pt : TPoint;
      r : TRect;
    begin
      pt := ClientToScreen(Point(0, 0));
      r.Left := pt.x;
      r.Top := pt.y;
      pt := ClientToScreen(Point( 28,  28));
      r.Right := pt.x;
      r.Bottom := pt.y;
      AdjustWindowRectEx(r,
                         GetWindowLong(Form .Handle, GWL_STYLE),
                         Form .Menu = nil, {if Form  has a menu}
                         GetWindowLong(Form .Handle, GWL_EXSTYLE));
      Form .Top := r.Top;
      Form .Left := r.Left;
      Form .Width := r.Right - r.Left;
      Form .Height := r.Bottom - r.Top;
    end;
    

     



  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use