LB Booster
Programming >> BASIC code examples >> adjustWindow routine
http://lbb.conforums.com/index.cgi?board=code&action=display&num=1446558721

adjustWindow routine
Post by Richard Russell on Nov 3rd, 2015, 12:52pm

Anatoly's clever adjustWindow routine is very useful when you want to open a window which has precise (client area) dimensions. However it doesn't always work perfectly, because the values of slackX and slackY it calculates are always even numbers, so the resulting window size may be 'off by one'.

If it is important that the window dimensions are precise, to the pixel, the routine can be modified as listed below:

Code:
    desiredW = WindowWidth: desiredH= WindowHeight
    WindowWidth = 200: WindowHeight = 200
    open "" for graphics_nsb_nf as #gr ' change type as required
    #gr, "home ; down ; posxy x y"
    width = 2*x : height = 2*y
    close #gr
    slackX = 200-width: slackY = 200-height
    WindowWidth = 201: WindowHeight = 201
    open "" for graphics_nsb_nf as #gr ' change type as required
    #gr, "home ; down ; posxy x y"
    width = 2*x : height = 2*y
    close #gr
    if slackX <> 200-width  then slackX = slackX - 1
    if slackY <> 200-height then slackY = slackY - 1
    WindowWidth = desiredW + slackX
    WindowHeight =  desiredH + slackY 

The window type must of course be the same as that of the window you will eventually open, so change the graphics_nsb_nf in both places as necessary.

Richard.