home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / pas / swag / oop.swg / 0001_CENTRDLG.PAS.pas next >
Pascal/Delphi Source File  |  1993-05-28  |  774b  |  27 lines

  1. {
  2.  > The title says it all. What is the accepted way of bringing up a dialog
  3.  > box in the centre of the screen.
  4. }
  5. Procedure CenterDlg (HWindow : HWnd);
  6. Var
  7.   R       : TRect;
  8.   X       : Integer;
  9.   Y       : Integer;
  10.   Frame   : Integer;
  11.   Caption : Integer;
  12. begin
  13.   Frame   := GetSystemMetrics (sm_CxFrame) * 2;
  14.   Caption := GetSystemMetrics (sm_CyCaption);
  15.   GetClientRect (HWindow, R);
  16.   With R do
  17.     begin
  18.     X := ((GetSystemMetrics (sm_CxScreen) - (Right - Left)) div 2);
  19.     Y := ((GetSystemMetrics (sm_CyScreen) - (Bottom - Top)) div 2);
  20.     MoveWindow (HWindow, X, Y - ((Caption + Frame) div 2),
  21.       Right + Frame, Bottom + Frame + Caption, False);
  22.     end;
  23.   end;
  24. end;
  25. {
  26.  Execute this Function from the dialog's SetupWindow method.
  27. }