Center the application window on the user's screen



Is there any sample code that demonstrate how to center the application window on the user's screen?


* Use the "acucobol.def" copy file, which is included

* with the ACUCOBOL-GT product distribution.

Working-Storage Section.

01  window-height          

pic 9(9) value zero.

01  window-width           

pic 9(9) value zero.

01  screen-size-remaining  

pic 9(9) value zero.

01  screen-lines-remaining

pic 9(9) value zero.

01  computed-col-position  

pic 9(9) value zero.

01  computed-line-position

pic 9(9) value zero.

01  menu-screen-size       

pic 9(2) value 74.

01  menu-screen-lines      

pic 9(2) value 24.

01  my-var               &nbs p;                   & nbsp;      pic x.

copy "acucobol.def".

Procedure Division.

      accept terminal-abilities from terminal-info

* How many pixels wide is the screen?

      multiply menu-screen-size by 10

        giving window-width.

* How many pixels high is the screen?

      multiply menu-screen-lines

        by 10 giving window-height.

* How much horizontal space left?

      subtract window-width from usable-screen-width

        giving screen-size-remaining.

* How much vertical space left?

      subtract window-height from usable-screen-height

        giving screen-lines-remaining.

* Split leftover space in two to find centered screen

* positions

      divide screen-lines-remaining by 2

        giving computed-line-position.

      divide screen-size-remaining by 2

        giving computed-col-position.

* Display the window           

     display standard graphical window

          lines menu-screen-lines, size menu-screen-size,

          cell height 10, cell width 10,

          title "AcuProd"

          screen line computed-line-position

          screen col  computed-col-position.

     accept my-var.

     stop run.

Old KB# 2680
Comment List