Centering Window with Win 1.5 
Author Message
 Centering Window with Win 1.5

I need the code or information to Center my Window program on the screen.  When
I use the sw_maximize function my window will go to the upper left hand corner.

What code is needed to ensure my program window is displayed in the center of
my screen.  Screen size is 80 by 25.

thanks



Wed, 18 Jun 1902 08:00:00 GMT  
 Centering Window with Win 1.5
Try this

procedure CenterWindow(Wnd: hWnd; X_Offset, Y_Offset : Integer);
var
  Wnd_Rect, Appl_Rect : TRect;
  Client_XY, Appl_XY : TPoint;
  X, Y: Integer;
Begin
  GetWindowRect(Wnd, Wnd_Rect);
  If Application <> nil then
  Begin
    if IsIconic(Application^.MainWindow^.HWindow) then
      EXIT;
    if IsZoomed(Application^.MainWindow^.HWindow) then
    Begin
      X := GetSystemMetrics(SM_CXScreen) div 2;
      Y := GetSystemMetrics(SM_CYScreen) div 2;
      with Wnd_Rect do
      SetWindowPos(Wnd, 0, x -  ((Right-Left) div 2),
        y - ((Bottom-Top) div 2), Wnd_Rect.Right,  Wnd_Rect.Bottom,
        swp_NoSize or swp_NoZOrder);
    End
    else
    Begin
      ClientToScreen(Wnd, Client_XY);
      ClientToScreen(Application^.MainWindow^.HWindow, Appl_XY);
      GetWindowRect(Application^.MainWindow^.HWindow, Appl_Rect);
      X := ( (((Appl_Rect.Right-Appl_Rect.Left) div 2)-
             ((Wnd_Rect.Right-Wnd_Rect.Left) div 2)) div 2);
      Y := ( (((Appl_Rect.Bottom-Appl_Rect.Top) div 2)-
             ((Wnd_Rect.Bottom-Wnd_Rect.Top) div 2)) div 2);
      SetWindowPos(Wnd, 0, X, Y, 0, 0, swp_NoSize or swp_NoZOrder);
    End;
  end;
End;

Regards


Dmhusa skrev i meldingen

Quote:
>I need the code or information to Center my Window program on the screen.
When
>I use the sw_maximize function my window will go to the upper left hand
corner.

>What code is needed to ensure my program window is displayed in the center
of
>my screen.  Screen size is 80 by 25.

>thanks




Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. WIN 1.5 Pascal - Centering text window on screen

2. Pascal for WIN 1.5 - Centering Window on Screen

3. Win 1.5 Pascal - Displaying Lines in/on Screens/Window

4. WIN 1.5 - ICON in Window

5. WIN 1.5, Icon question (place icon in title window

6. Win 1.5 Pascal - CRT Unit - Window positioning

7. Adding an Icon to my Window Bar - Win 1.5

8. Win 1.5 Debugger Fix for Windows 95

9. Centering my WINDOW ON THE SCREEN

10. Turbo Debugger - TP Win ver 1.5

11. WIN 1.5 - POSITIONWINDOW MACRO

12. Win 1.5 Function LineTo - MoveTo

 

 
Powered by phpBB® Forum Software