LB Booster
Programming >> Liberty BASIC language >> Strange Button behavior
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1478108175

Strange Button behavior
Post by Alincon on Nov 2nd, 2016, 5:36pm

When I run this program fragment in LBB the "Get Student" button behaves oddly.
Does the button text 'waver' when you run the program?

r.m.

Code:
    nomainwin
    WindowWidth = DisplayWidth  :      WindowHeight = DisplayHeight
    BackgroundColor$ = "cyan"
    Button #student.btn6, "Get Student", [getStudentFile], UL, 100,50
    Button #student.btn7, "Save Student", [saveStudent], UL, 220,50
    Button #student.btn8, "Delete Student", [studentDelete], UL, 350,50
    statictext #student.statictext1, "Last Name", 30,  120,  85,  20
    textbox #student.lname, 20,  140, 140, 25
    statictext #student.statictext2, "First Name", 180,  120,  99,  20
    textbox #student.fname, 180,  140, 140,  25
    statictext #student.statictext4, "Initial", 345,  120,  70,  20
    textbox #student.initial, 340, 140, 40,  25
    Stylebits #student.initial, _ES_UPPERCASE, 0, 0, 0
    statictext #student.statictext5, "Gender", 395,  120,  60,  20
    textbox #student.gender, 400,  140, 30,  25
    Stylebits #student.gender, _ES_UPPERCASE, 0, 0, 0
    statictext #student.statictext6, "Date of Birth", 470,  100,  60,  40
    textbox #student.dob, 460,  140, 60,  25
    Stylebits #student.dob, _ES_NUMBER, 0, 0, 0
    statictext #student.statictext7, "Spec Needs", 555,  100,  60,  40
    textbox #student.special, 550,  140, 70,  25
    statictext #student.statictext1, "Address", 30,  190,  85,  20
    textbox #student.address, 20,  210, 220, 25
    statictext #student.statictext2, "City", 270,  190,  99,  20
    textbox #student.city, 260,  210, 140,  25
    statictext #student.statictext2, "State", 420,  190,  50,  20
    textbox #student.state, 420,  210, 30,  25
    Stylebits #student.state, _ES_UPPERCASE, 0, 0, 0
    statictext #student.statictext3, "Zip Code", 470,  190,  95,  20
    textbox #student.zip, 470,  210, 60,  25
    Stylebits #student.zip, _ES_NUMBER, 0, 0, 0
    statictext #student.statictext7, "Phone", 560,  190,  60,  20
    textbox #student.phone, 550,  210, 90,  25
    Stylebits #student.phone, _ES_NUMBER, 0, 0, 0   
    open "Student File Maintenance" for window as #student
    #student, "font ms_sans_serif 10"
    #student, "trapclose [studentEnd]" 
    wait
    
 [studentEnd]
    close #student
    end   
 

Re: Strange Button behavior
Post by tsh73 on Nov 2nd, 2016, 6:03pm

I don't see problem. Or cannot understand from description what a problem is.
I see button pre-selected, that's all.
Re: Strange Button behavior
Post by Richard Russell on Nov 2nd, 2016, 6:03pm

on Nov 2nd, 2016, 5:36pm, Alincon wrote:
When I run this program fragment in LBB the "Get Student" button behaves oddly.

I don't see anything "odd" here. What am I supposed to be looking for?

Richard.

Re: Strange Button behavior
Post by RobM on Nov 2nd, 2016, 6:15pm

This is what he is seeing. The text seems to morph for some reason. My program does it but none of my customers has mentioned it as a problem.

User Image
Re: Strange Button behavior
Post by Richard Russell on Nov 2nd, 2016, 6:59pm

I've no idea whether it has any connection (since I can't reproduce the effect here I can't test it) but there's a bug in the OP's code because the statictext2 extension is used multiple times:

Code:
    statictext #student.statictext2, "First Name", 180,  120,  99,  20
    statictext #student.statictext2, "City", 270,  190,  99,  20
    statictext #student.statictext2, "State", 420,  190,  50,  20 

Generally it's better not to use an extension with STATICTEXT at all (since if it's 'static' you should never have to reference it after the window is created).

Richard.

Re: Strange Button behavior
Post by RobM on Nov 2nd, 2016, 7:05pm

No connection, I stripped it down to just the bare minimum and it still does it. I did notice it only does it to the first declared button, IE switching their order in the original code changes which one "morphs'

Code:
    nomainwin
    Button #student.btn6, "Get Student", [getStudentFile], UL, 100,50  
    open "Student File Maintenance" for window as #student
    #student, "font Microsoft_Sans_Serif 10"
    #student, "trapclose [studentEnd]" 
    wait
    
 [studentEnd]
    close #student
    end 

Re: Strange Button behavior
Post by RobM on Nov 2nd, 2016, 7:21pm

No problem. Like I said, none of my customers have mentioned it. Perhaps they don't see it on their system either?

FWIW I am on Windows 7 with Aero enabled.
Re: Strange Button behavior
Post by RobM on Nov 2nd, 2016, 7:37pm

If you step through the code in the debugger, does it change the button font instantly when it get to the font command on your system? On mine you can see it changing over about a 1 second period.
Re: Strange Button behavior
Post by Richard Russell on Nov 2nd, 2016, 7:53pm

on Nov 2nd, 2016, 7:37pm, RobM wrote:
If you step through the code in the debugger, does it change the button font instantly when it get to the font command on your system?

Yes, it changes instantly. What happens if you explicitly set the button font:

Code:
    Button #student.btn6, "Get Student", [getStudentFile], UL, 100,50  
    open "Student File Maintenance" for window as #student
    #student "font Microsoft_Sans_Serif 10"
    #student.btn6 "font Microsoft_Sans_Serif 10"
    #student "trapclose [studentEnd]"
    wait 

Richard.

Re: Strange Button behavior
Post by Alincon on Nov 2nd, 2016, 7:56pm

I have found two more programs with the same behavior.
In these cases, there is only one button in the window.
I do not see any failure of the buttons to work as intended.
I am running LBB under Windows 7.

r.m.
Re: Strange Button behavior
Post by RobM on Nov 2nd, 2016, 8:00pm

on Nov 2nd, 2016, 7:53pm, Richard Russell wrote:
Yes, it changes instantly. What happens if you explicitly set the button font:

Code:
    Button #student.btn6, "Get Student", [getStudentFile], UL, 100,50  
    open "Student File Maintenance" for window as #student
    #student "font Microsoft_Sans_Serif 10"
    #student.btn6 "font Microsoft_Sans_Serif 10"
    #student "trapclose [studentEnd]"
    wait 

Richard.

Still does it. You missed the "!" in your button font command.
Re: Strange Button behavior
Post by Richard Russell on Nov 2nd, 2016, 8:16pm

on Nov 2nd, 2016, 7:56pm, Alincon wrote:
I am running LBB under Windows 7.

I wonder if Windows 7 is the common factor. I'll try to run up a Windows 7 machine and test on that.

Richard.

Re: Strange Button behavior
Post by RobM on Nov 2nd, 2016, 8:29pm

Just checked and it doesn't do it on Windows 8
Re: Strange Button behavior
Post by Alincon on Nov 2nd, 2016, 8:47pm

I have found another instance, this time in a dialog window.

I can't prove it, but I think this is a recent thing - I don't remember it happening, say, last year.

r.m.

Re: Strange Button behavior
Post by RobM on Nov 2nd, 2016, 8:54pm

on Nov 2nd, 2016, 8:47pm, Alincon wrote:
I have found another instance, this time in a dialog window.
I can't prove it, but I think this is a recent thing - I don't remember it happening, say, last year.

It has been doing it since I changed from LB to LBB around the end of 2013
Re: Strange Button behavior
Post by Richard Russell on Nov 2nd, 2016, 9:03pm

on Nov 2nd, 2016, 8:29pm, RobM wrote:
Just checked and it doesn't do it on Windows 8

Yes, I've just tried it on a Windows 7 machine and I now see an effect, but it's quite different from what I expected from the description and the screenshot. What I see is just a slow switch from the default font to the requested font - once it's changed I see no further disturbance (I assumed from the description that it stayed permanently 'morphed' or kept changing).

As far as I can see it's a 'deliberate' transition effect, no doubt designed to look 'attractive' in some common circumstances (but not this one). You can disable it (on a specific PC) by going into Control Panel... Performance Information and Tools... Advanced Tools... Adjust the appearance and performance of Windows... Visual Effects and deselecting the first checkbox ('Animate controls and elements inside windows').

So it's nothing to do with LBB, just Microsoft trying to make Windows look prettier but resulting in an undesirable side-effect in this case. It looks as though they realised their mistake and changed it in Windows 8.

Richard.

Re: Strange Button behavior
Post by RobM on Nov 2nd, 2016, 9:09pm

That makes some sense but it is strange it only does it to one button and not all of them.
Re: Strange Button behavior
Post by tsh73 on Nov 2nd, 2016, 9:24pm

Quote:
but it is strange it only does it to one button and not all of them.

Try to make other button active with !setfocus.
May be it is selected button which is animated?
Re: Strange Button behavior
Post by Richard Russell on Nov 2nd, 2016, 9:33pm

on Nov 2nd, 2016, 9:09pm, RobM wrote:
That makes some sense but it is strange it only does it to one button and not all of them.

I've long since given up trying to analyse why Windows does something. It's such an enormously complicated OS I doubt that anybody, anywhere, understands more than a tiny fraction of it.

The fact that the effect is controlled by the 'Animate controls and elements inside windows' setting proves (to my own satisfaction) that it's 'deliberate', and the fact that Windows 8 doesn't do it is suggestive that Microsoft became aware that it wasn't always a desirable behavior.

I expect, with some effort, you could change the setting from your BASIC program (and even change it back on exit).

Edit: Looks like it's the "SystemParametersInfo" API with the SPI_SETCLIENTAREAANIMATION parameter.

Richard.

Re: Strange Button behavior
Post by RobM on Nov 2nd, 2016, 9:40pm

on Nov 2nd, 2016, 9:24pm, tsh73 wrote:
Try to make other button active with !setfocus.
May be it is selected button which is animated?

Nope, no change.
Re: Strange Button behavior
Post by RobM on Nov 2nd, 2016, 9:42pm

on Nov 2nd, 2016, 9:33pm, Richard Russell wrote:
I've long since given up trying to analyse why Windows does something. It's such an enormously complicated OS I doubt that anybody, anywhere, understands more than a tiny fraction of it.

The fact that the effect is controlled by the 'Animate controls and elements inside windows' setting proves (to my own satisfaction) that it's 'deliberate', and the fact that Windows 8 doesn't do it is suggestive that Microsoft became aware that it wasn't always a desirable behavior.

I expect, with some effort, you could change the setting from your BASIC program (and even change it back on exit).

Edit: Looks like it's the "SystemParametersInfo" API with the SPI_SETCLIENTAREAANIMATION parameter.

Richard.

As stated previously it isn't a problem for me or my users. More of a curiosity.
Re: Strange Button behavior
Post by Richard Russell on Nov 2nd, 2016, 11:29pm

on Nov 2nd, 2016, 9:42pm, RobM wrote:
As stated previously it isn't a problem for me or my users. More of a curiosity.

But it wasn't you who raised the issue, and the OP (Alincon) may feel differently - unless of course you're one in the same person!

What this really illustrates is a flaw in the way Liberty BASIC is designed (and I'm not taking a pop at Carl; he had no way of knowing that Microsoft would introduce animated transitions). Conventionally one would create a control, like a button, with the required font initially selected; that way nothing untoward would happen. But in LB you can only specify the font you want after the control (and indeed its parent window) has been created, so necessarily it involves a switch from one font - the default - to another.

It's this font change that triggers the animation, and Microsoft could reasonably claim that you would not do that 'unnecessarily'. But the design of LB forces you to, and Windows detects this as a potentially 'visible' change (indeed it is) and tries to make it more interesting.

In a perfect world you'd choose the font when the control is declared, perhaps as an extra parameter to the BUTTON statement. But that's not how LB works (and, no, I don't intend to provide it as an LBB extension!).

Richard.

Re: Strange Button behavior
Post by Alincon on Nov 2nd, 2016, 11:57pm

This strange effect may be due to some intricacy in Windows 7.
But why do I not see it when I run the same programs in LB4.04 and 4.5?

r.m.
Re: Strange Button behavior
Post by Richard Russell on Nov 3rd, 2016, 02:57am

on Nov 2nd, 2016, 11:57pm, Alincon wrote:
This strange effect may be due to some intricacy in Windows 7.

Now we understand it, to a degree, I don't think it can any longer be described as "strange"! What I see here, at least, is a perfectly ordinary transition animation.

Quote:
But why do I not see it when I run the same programs in LB4.04 and 4.5?

Obviously I am not privy to the internal workings of LB 4, only Carl knows those details. But one possible explanation is that LB 4 does not enable Version 6.0 Common Controls in its manifest, and it may be that some of these animation effects are dependent on that setting. But there could be many other reasons; as I've said, Windows is enormously complex.

Richard.

Re: Strange Button behavior
Post by Richard Russell on Nov 3rd, 2016, 9:42pm

The most straightforward workaround, to create an 'invisible' dummy button as the first item in the window - which can be animated as slowly as Windows wishes - seems to be effective on my Windows 7 PC:

Code:
    nomainwin
    button #student, "", [], UL, WindowWidth, 0
    button #student.btn6, "Get Student", [getStudentFile], UL, 100,50  
    open "Student File Maintenance" for window as #student
    #student "font Microsoft_Sans_Serif 10"
    #student "trapclose [studentEnd]" 
    #student.btn6 "!setfocus"
    wait
    
[studentEnd]
    close #student
    end 

Richard.