LB Booster
« pressing ESC aborts the program »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:41am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 veryhotthread  Author  Topic: pressing ESC aborts the program  (Read 1535 times)
tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: pressing ESC aborts the program
« Reply #15 on: Sep 14th, 2016, 10:57am »

I've just found an article
Disabling Escape in modal dialog boxes
Posted August 23rd, 2006 by William Willing

and it looks like it is edit control that behaves in strange ways.

If I create window with edit (:textbox) and a button, then then opened "for window" it closes on ESC only with focus on textbox
Then then opened "for dialog" it closes on ESC all the time.
(code adapted from a helpfile)
Code:
nomainwin
    'trapclose example using a branch label event handler
  statictext #example.label, "Now close the window!!", 10, 10, 200, 25
  textbox #example.txt, 10, 40, 200, 25
  button #example.txt, "open notice", [note], ul, 10, 100


'  open "Demonstrate trapclose" for window as #example
  open "Demonstrate trapclose" for dialog as #example
  print #example, "trapclose [branch]"
  wait

[branch]
  confirm "Really close?"; answer$
  if answer$ = "no" then wait
  close #example
  end

[note]
    notice "now close it with ESC"
    wait 

EDIT
I just tried to add all the controls - normal window closes only with focus on the textbox
Dialog window closes al focus everythere but edit (multiline) control.

So it likely not the thing described in that article.
Code:
nomainwin
    'trapclose example using a branch label event handler
  statictext #example.label, "Now close the window!!", 10, 10, 200, 25
  textbox #example.txt, 10, 40, 200, 25
  button #example.txt, "open notice", [note], ul, 10, 100
  CHECKBOX #example.ext, "label", setHandler, resetHandler, 250, 10, 100, 25
  COMBOBOX #example.ext, array$(), eventHandler, 250, 40, 100, 25
  LISTBOX #example.ext, array$(), eventHandler, 10, 150, 150, 100
  RADIOBUTTON #example.ext, "label", setHandler, resetHandler, 250, 100, 100, 25
  TEXTEDITOR #example.ext, 250, 200, 100, 100

WindowWidth = 450
	

  open "Demonstrate trapclose" for window as #example
'  open "Demonstrate trapclose" for dialog as #example
  print #example, "trapclose [branch]"
  wait

[branch]

 'End the program on Close, ignore Esc
'    calldll #user32, "GetAsyncKeyState", _VK_ESCAPE as long, ret as short
'    if ret < 0 then wait

    confirm "Really close?"; answer$
  if answer$ = "no" then wait
  close #example
  end

[note]
    notice "now close it with ESC"
    wait 
« Last Edit: Sep 14th, 2016, 11:08am by tsh73 » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: pressing ESC aborts the program
« Reply #16 on: Sep 14th, 2016, 11:49am »

on Sep 14th, 2016, 10:57am, tsh73 wrote:
I've just found an article
Disabling Escape in modal dialog boxes
Posted August 23rd, 2006 by William Willing

That is indeed most interesting: not only does it answer my question about what message gets sent when Esc is pressed (WM_COMMAND + IDCANCEL), which is what I needed to know to be able to suppress the Esc action, but it also reveals that if there's a multiline Edit Control present any simple modification I might make won't work. What it gives with one hand it takes away with the other!

Richard.
« Last Edit: Sep 14th, 2016, 11:56am by Richard Russell » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: pressing ESC aborts the program
« Reply #17 on: Sep 16th, 2016, 08:38am »

on Sep 14th, 2016, 10:57am, tsh73 wrote:
it looks like it is edit control that behaves in strange ways.

Chasing this up, even Raymond Chen (author of the famous The Old New Thing blog) has commented on it as follows: "Yes, when you hit ESC in a multiline edit, it posts a WM_CLOSE to its parent in the mistaken belief that it is part of a dialog box.  This is for compatibility with Windows 2.0, which behaved this way.  It's annoying now, but compatibility means having to be bug-for-bug compatible with the previous version...".

This was written in 1999 and the fact that it appears to be still the same today, despite his admission that it does indeed qualify as a bug, means we're stuck with it - even though the argument that it is necessary for compatibility with Windows 2.0 is a bit weak now! Microsoft could easily have introduced a new style bit to disable this behavior, which wouldn't have compromised compatibility at all.

Let me know if my suggested workaround (testing in the trapclose handler for the Escape key being pressed) is effective. Clearly it can't be 100% reliable, because of the asynchronous nature of the test, but hopefully it will be good enough.

The only other way I can think of fixing it, other than by modifying LBB, would be to use WMLiberty to subclass the edit control, which is a heavyweight solution for a problem which I still think is relatively minor.

Richard.
« Last Edit: Sep 16th, 2016, 08:42am by Richard Russell » User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: pressing ESC aborts the program
« Reply #18 on: Sep 16th, 2016, 09:28am »

I would like to remind that problem occurs then single-line edit has focus in ordinary window.
So that problem with multiline edit likely different thing.

Yes I tried trapclose workaround and it worked all few times I tried.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: pressing ESC aborts the program
« Reply #19 on: Sep 16th, 2016, 10:48am »

on Sep 16th, 2016, 09:28am, tsh73 wrote:
I would like to remind that problem occurs then single-line edit has focus in ordinary window. So that problem with multiline edit likely different thing.

No, in both LB 4 and LBB a single-line TEXTBOX is a multiline edit control. You can confirm that using this code:

Code:
    textbox #w.tb, 10, 10, 200, 25
    open "Textbox style test" for window as #w
    htb = hwnd(#w.tb)
    calldll #user32, "GetWindowLongA", htb as ulong, _
      _GWL_STYLE as long, style as long
    print dechex$(style)
    wait 

You will see that in both LB 4 and LBB the following value is printed in the mainwin:

Style Code:
508100C4 

The 4 in the least-significant digit position indicates that it is a multiline edit control (ES_MULTILINE = 4), despite the fact that it has only one line!

It is clearly the case that the Edit Control bug (which I have now found many references to, including at the PowerBASIC forum) is the reason for the observed behavior.

Richard.
User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: pressing ESC aborts the program
« Reply #20 on: Sep 16th, 2016, 11:00am »

Quote:
No, in both LB 4 and LBB a single-line TEXTBOX is a multiline edit control.

Err... I remember reading something about LB TEXTBOX allows multiline.
I did not expected single line control use "multiline edit control".

I wonder why LBB uses multiline edit for singleline TEXTBOX?
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: pressing ESC aborts the program
« Reply #21 on: Sep 16th, 2016, 11:47am »

on Sep 16th, 2016, 10:48am, Richard Russell wrote:
No, in both LB 4 and LBB a single-line TEXTBOX is a multiline edit control.

Here's an even more direct demonstration. In the program below I explicitly create a single-line edit control by clearing the ES_MULTILINE bit using stylebits; in this case pressing Esc does not close the window:

Code:
    textbox #w.tb, 10, 10, 200, 25
    stylebits #w.tb, 0, _ES_MULTILINE, 0, 0
    open "Textbox style test" for window as #w
    wait 

Quote:
I wonder why LBB uses multiline edit for singleline TEXTBOX?

Because LB 4 does!! It's necessary for compatibility (there are LB programs which depend on it).

Richard.
« Last Edit: Sep 16th, 2016, 11:49am by Richard Russell » User IP Logged

metro
New Member
Image


member is offline

Avatar




PM


Posts: 8
xx Re: pressing ESC aborts the program
« Reply #22 on: Sep 16th, 2016, 2:09pm »

I have tinkered with two of my programs to get them to run in LBB both have Richards work around and am happy to say... "all good."

Each program is used daily and handle the many times I accidentally press ESC twice when closing a dialog to drop back to the main window.
User IP Logged

tsh73
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: pressing ESC aborts the program
« Reply #23 on: Sep 19th, 2016, 07:52am »

Hello Richard
If
Quote:
No, in both LB 4 and LBB a single-line TEXTBOX is a multiline edit control.


what is TEXTEDITOR control?

(after all, window closes only then focus is on TEXTBOX)
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: pressing ESC aborts the program
« Reply #24 on: Sep 19th, 2016, 1:50pm »

on Sep 19th, 2016, 07:52am, tsh73 wrote:
what is TEXTEDITOR control?

That's an Edit Control too, but I'm not sure what the stylebits settings are offhand (I'm away from home at the moment).

Richard.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: pressing ESC aborts the program
« Reply #25 on: Sep 19th, 2016, 6:45pm »

on Sep 19th, 2016, 1:50pm, Richard Russell wrote:
That's an Edit Control too

I can confirm that it's a superclassed (not subclassed) multiline Edit Control. So it has a different class name (LBBEDIT) and extended functionality - which it needs for compatibility with LB's custom TEXTEDITOR control - but is based on a standard Edit Control.

Richard.
User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls