support: Customer Portal
Focused on delivering choice, investment protection and flexibility to organizations with valuable COBOL assets
 

Veryant Knowledge Base
Home > All Categories > isCOBOL General > User Interface > How do I center a window on the desktop?
Question Title How do I center a window on the desktop?

To center a window, you could follow the example shown in the $ISCOBOL/sample/iscontrolset/isControlSet.cbl source code:

For example, to obtain the physical screen width in pixels:

   accept terminal-abilities from terminal-info

After executing the statement above, the physical-screen-width and the physical-screen-height items in the terminal-info group contain the screen dimensions measured in pixels.

The isControlSet.cbl sample uses these measurements to obtain the column and line positions for the centered window:

          compute win-col   = (physical-screen-width - 829 ) / 2                              
          compute win-line  = (physical-screen-height - 597 ) / 2

The isControlSet.cbl sample uses fixed window dimensions, 829 pixels width and 597 pixels height.

However, in the general case a window's real pixel dimensions are based on the font used for the window. If you want to create a generic routine for centering a window, you can use the W$TEXTSIZE library routine to obtain the pixel dimensions of the window. For example, the following subprogram centers a window given a window handle and control font handle:

       IDENTIFICATION DIVISION.
       PROGRAM-ID. W_CENTER.
       DATA DIVISION.

       WORKING-STORAGE SECTION.
       copy "iscobol.def".
       copy "isgui.def".
       copy "iscrt.def".
       copy "isfonts.def".
       77 w-lines pic 9(4).
       77 w-size pic 9(4).
       77 w-col pic 9(4).
       77 w-line pic 9(4).
       77 unit-x pic 9(4).
       77 unit-y pic 9(4).

       LINKAGE SECTION.
       01 lks-h-win handle of window.
       01 lks-h-font handle of font.

       PROCEDURE DIVISION USING lks-h-win, lks-h-font.

       MAIN.
           inquire lks-h-win lines in w-lines
                         size in w-size
        
           move lks-h-font to textsize-font.
           move lks-h-win   to textsize-window.
           set textsize-strip-spaces to true .
           call "W$TEXTSIZE" using   0 , textsize-data.
           
           compute unit-x rounded = textsize-base-x / textsize-cells-x. 
           compute unit-y rounded = textsize-base-y / textsize-cells-y.
           
           compute w-lines rounded = w-lines * unit-y
           compute w-size rounded = w-size * unit-x
           
           accept terminal-abilities from terminal-info .            
           compute w-col   = (physical-screen-width - w-size) 
                                  / 2 .                             
           compute w-line  = (physical-screen-height - w-lines)
                                  / 2 .      
                                  
           modify lks-h-win screen line w-line
                        screen col w-col
                        visible 1                             
           .

Please consider that the dimensions obtained do not include the title-bar because it is not part of the client area of the window.

Example:

    display standard  window background-low                      
       screen line 41                                            
       screen column 91                                          
       size 64.0                                                 
       lines 48.0                                                
       cell width 10                                             
       cell height 10                                            
       visible 0                                            
       label-offset 20                                           
       control font default-font                                 
       color 257                                                 
       modeless                                                  
       title "Screen"                                            
       handle h-win                                              
    .                                                            
    call "W_CENTER" using h-win, default-font.

The attached file, w_center.cbl, contains the W_CENTER routine shown above.

Authored by: Veryant Support This question has been viewed 4241 times so far.
Click Here to View all the questions in User Interface category.
File Attachments File Attachments
How helpful was this article to you?
User Comments User Comments Add Comment
There are no user comments for this question. Be the first to post a comment. Click Here
Related Questions Related Questions
  1. Does isCOBOL provide GUI design support?
  2. iscobol.font.default and DEFAULT-FONT
  3. What are the specific fonts that isCOBOL uses by default?
  4. Does isCOBOL provide Graph modules to show statistics?
  5. Can I have an entry-field that more or less works the same as Google Search? So I would like to be able to change the contents of the list while the user is typing...
  6. Working with a grid control is there a way to get the double-click event?
  7. How can I refresh the current contents of the paged grid?
  8. Is there a way to show leading zeros when numeric data items are displayed on a character based screen?
  9. UNC Paths with Browser Control don't work. What can I do to solve it?
  10. Is it possible to sort dates in a grid control?
  11. How can I show an animated gif with isCOBOL?
  12. Is it possible to configure the color of the read-only entry-fields?
  13. Did you know that you can protect a Grid from editing without coding any event?
  14. Did you know isCOBOL supports a tip inside the entry-field and combo-box controls when they are empty?
  15. Did you know isCOBOL has the Accordion control?
  16. Did you know how to customize color of the borders of some controls?
Article Information Additional Information
Article Number: 154
Created: 2010-11-01 10:28 AM
Rating: 1 Star
 
Article Options Article Options
Print Question Print this Question
Email Question Email Question to Friend
Export to Adobe PDF Export to PDF File
Export to MS Word Export to MS Word
Bookmark Article
Subscribe to Article Subscribe to Article
 
Search Knowledge Base Search Knowledge Base



 
 

© Veryant - All Rights Reserved
Veryant and isCOBOL are trademarks or registered marks of Veryant in the United States and other countries. All other marks are the property of their respective owners.