Multiple Windows and Displays

by Gordon Sweet

[http://www.gsweet.fsnet.co.uk/LBcode.htm]

[gordon@gsweet.fsnet.co.uk]


Home

Using WINMM.DLL

Liberty BASIC Default Variables

Updating in LB

Internet - Downloading a File to Disk

API Corner - Easy Font Manipulations

Multiple Windows and Displays

Mapping Real World Coordinates

Linear and Non-Linear Equations

About Ingemar Bjerle

Submission Guildlines

Newsletter Help

Index

For a long time I have been in the bad habit of using more that one window on display at a time, and only using the 800 X 600 screen display, because at the time I was using a 14 inch monitor. The text on the popular 1024 X 768 display is really too small for me on a 14 Inch screen.

I gave all my programs at the time to a friend of mine who periodically builds and upgrades my systems, who uses the larger display. I noticed he consistently adopted the habit of dragging the 800 X 600 windows to the centre of the screen, thus exposing other windows, which should not be active at the time. As result there was a risk he or anyone could cause the program to crash, by activating a button etc from the wrong window.

Now that I have upgraded to the use of a larger 15 inch monitor, I decided it was time I amended all my programs to avoid these problems. If you study the code below you will see it involves the use of 3 different types of windows, a separate window for each option, and at no time is more than one window active. Beginners should bear in mind that closing a window does not mean you lose all the variables such in a DIM array, but they all remain active until the END statement is reached on total closure of the program.

You will notice each window creates a relevant variable, such as win1, win2 etc. So when one window is closed and another opened, the value of the win1 or win2 variables need to be changed. As a result when the QUIT option is activated, the program knows which window is still active and needs to be closed. However note the process shown in the [quit] section of re-setting the win1 or win2 etc variable to zero, is only needed here because of the CONFIRM option requesting confirmation of closing the program.

You can see the problem of attempting to make the windows compatible with either size of display, is solved with each window by the parameters ux and uy determined in relation to the DisplayWidth. As the opening win1 and the text win3 are set at the smaller windows, ux and uy are just used to ensure the window appears in the centre of a larger display. With the full screen display of win2, you can see the ux and uy parameters are used to set both the printing and the buttons in the same position for either display.

I regret my patience is exhausted to tackle the problem of making programs to suit ALL the various screen displays possible, but no doubt others can use the principles outlined to cope with these problems if needed. Gordon Sweet


' USE OF MULTIPLE WINDOWS & ATERNATIVE DISPLAYS
    nomainwin
[start]
    ux = 1 : uy = 1
    if DisplayWidth > 1000 then ux = 120 : uy = 90
    UpperLeftX = ux : UpperLeftY = uy
    WindowWidth = 800 : WindowHeight = 580
    button #1, " BMP PICS", [bmp], ll, 200, 50
    button #1, "   TEXT  ", [text], ll, 350, 50
    button #1, " * QUIT *", [quit], ll, 500, 50
    open "OPENING MENU" for graphics_nsb as #1
    #1 "trapclose [quit]; discard; font arial 36 bold"
    #1 "fill cyan; backcolor cyan; place 330 100"
    #1 "\MENU"
    #1 "font arial 14 bold italic; place 170 180"
    #1 "\This window is fixed at 800  x 600 whatever screen"
    #1 "\display is used. Notice how the position of the"
    #1 "\window is centered in the larger 1024 X 768 display"
    playwave "xxx.wav" ' Non existent wav instead of beep
    win1 = 1 : wait

[bmp]
    close #1 : win1 = 0 : win2 = 1
    UpperLeftX = ux : UpperLeftY = uy
    WindowWidth = 800 : WindowHeight = 580
    button #2, "Find a BMP", [pick], ll, 310+ux, 20
    button #2, " * ABORT *", [quit], ll, 440+ux, 20
    open "FULL SCREEN BMP DISPLAY" for graphics_fs_nsb as #2
    #2 "trapclose [quit]; font arial 36 bold; down"
    #2 "fill 0 0 50; backcolor 0 0 50; color yellow; place ";190+ux;" ";100+uy
    #2 "\This is a Full Screen"
    #2 "font arial 14 bold italic; place ";120+ux;" ";200+uy
    #2 "\Notice this print and the buttons stay in the same postion whether"
    #2 "\using a 800 X 600 or a 1024 X 768 display by the use of ux and uy"
    DefaultDir$ = left$(DefaultDir$,2) + "\"
    playwave "xxx.wav" ' Non existent wav instead of beep
    wait

[pick]
    filedialog "ONLY BMP files","*.BMP",bmp$ 
    if bmp$ = "" then [abort]
    loadbmp "image", bmp$
    #2 "background image";
    #2 "drawsprites";
    wait
    loadbmp "title", fil$ 
    #1 "redraw; drawbmp title ";x;" ";y

[text]
    close #1 : win1 = 0 : win3 = 1
    UpperLeftX = ux : UpperLeftY = uy
    WindowWidth = 800 : WindowHeight = 580
    texteditor #3.tb 20,20,0,0 'this is invisible
    menu #3, "ABORT", "Quit",[quit]
    tl$ = trig$+" values from "+str$(first)+"  to "+str$(P)
    open "Sine Calculations" for text as #3
    #3 "!trapclose [quit]"
    #3 "!font fixedsys"
    RAD = 3.141592654 / 180 ' radians to degrees
    lin = 1 : col = 12
    #3.tb "TABLE OF SINE CALCULATIONS. WINDOW IN CENTRE OF A 1024 X 768 display"
    gosub [tbox] : lin = 3 : col = 1
    FOR F = .5 TO 90 STEP .5 ' degrees
        N = F * RAD
        Z = SIN(N)
        IF Z < 1 THEN YC = 175: YS = 150
        #3.tb USING("####.#", F);
        IF Z > 99 THEN #3.tb USING("########", INT(Z));
        IF Z < 100 THEN #3.tb USING("###.####", Z);
        gosub [tbox]
        lin = lin + 1
        if lin > 32 then col = col + 15 : lin = 3
    NEXT F
    #3 "!origin 1 1"; ' move scroll bars back
    wait

[tbox]  ' locates text on screen to avoid flicker
    #3.tb, "!selectall";
    #3.tb, "!cut";
    #3 "!select ";col;" ";lin;
    #3 "!paste";
    return

[quit]
    if win1 = 1 then close #1 : win1 = 0
    if win2 = 1 then close #2 : win2 = 0
    if win3 = 1 then close #3 : win3 = 0
    confirm "OK to Quit?"; quit$
    if quit$ = "no" then [start]
    end


Home

Using WINMM.DLL

Liberty BASIC Default Variables

Updating in LB

Internet - Downloading a File to Disk

API Corner - Easy Font Manipulations

Multiple Windows and Displays

Mapping Real World Coordinates

Linear and Non-Linear Equations

About Ingemar Bjerle

Submission Guildlines

Newsletter Help

Index