Fun with IntControl(54) - Stay on top. An irreproducible result

Started by snowsnowsnow, March 07, 2025, 02:50:36 PM

Previous topic - Next topic

snowsnowsnow

First a few comments:
1) I use IC(54) in almost all of my scripts - I want to be able to put messages in the box with BoxText() and be sure that the user will see them, regardless of what other windows are onscreen.  I usually have this line amongst my initializations:

IntControl(54,"",1,0,0)

And normally it all works fine.

2) I know that supposedly IC(54) is "superceded" by WindowOnTop(), but is there any difference at all?  I think I remember reading somewhere that WindowOnTop() supports multi-byte character sets (i.e., i18n), and that that was the reason for its invention.  i18n is something I have zero interest in, so that would be irrelevant for me.

Anyway, on to the point.  I have this script that is relatively long (100 lines) and does a bunch of things - mostly running other programs - and was working fine up until the last round of changes (which I don't remember what they were), but now the box is no longer "on top" (it gets covered up by other windows).  I did some checking and the returned value of the IC(54,"",1,0,0) call is 1 (as expected) but when I do: IC(54,"",-1,0,0), it returns 0 (!).

After some monkeying around, I found this fix:

; This is an awful kludge, but it seems to be necessary...
Display(1,"1) Value returned by IC(54)",IntControl(54,"",1,0,0))
Display(1,"2) Value returned by IC(54)",IntControl(54,"",1,0,0))
Display(1,"3) Value returned by IC(54)",IntControl(54,"",1,0,0))
Terminate(!IntControl(54,"",-1,0,0),"Title","IC(54) didn't work (even though we tried 3 times)!")

Yes, you have to do it 3 times and yes, you need the Display (Pause also works).  If you just do the IntControl by itself, it doesn't work, and also TimeDelay() between each call doesn't work either.  It seems it has to be something that displays something (in a window).

I'd be grateful for any theories or ideas, but I'm pretty sure this is going down as not-reproducible.  The above lines are going to be part of my script unless/until I figure out something better...


td

I tried to reproduce your issue using the latest version of WinBatch on Windows 11 and couldn't. WindowOnTop changed in 2016B to support an optional parameter. The parameter allowed retrying to be turned on or off. A change in 2013c that affected both WindowOnTop and IntControl 54 only involved a workaround for a Windows bug when using the 0 (Don't stay on top) option.

The IntControl returns @True/@False when you use option -1. Otherwise, it returns @False only when one of the implementing Windows API functions returns 0 for some reason.

Sorry I can't be of more help.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

snowsnowsnow

Yeah. as I said, I doubt anyone can reproduce it. Yet, it happened.  And, as I said, it only showed up after a I made some other totally un-related change.

It could be some kind of corruption in the OS (although there is no reason for that, nothing strange has happened in the interim) - such that a reboot would fix it.  But the environment that I work in, it is easier to fix (kludge) the code than to reboot the machine.  Yes, that's an odd situation.

In any case, it seems pretty clear that the API is somehow failing to set the "on top" property, but is not reporting that failure.

FWIW, I'm thinking of re-writing it to:

n = 0
WHILE !IntControl(54,"",-1,0,0)
    Display(1,"%n%) Return value:",IntControl(54,"",1,0,0))
    n = n + 1
ENDWHILE

Or an equivalent "FOR" loop.  Also, it should be possible to use the return value of Display() to allow the user to hit Escape and exit the loop.  I need to research that again, since it's been a while since I've used Display().

cssyphus

One nice addition via the latest WB release: Display() now supports floating point duration...

display(0.25, 'Quick message:', 'How is 1/4 second for a quick message?')

snowsnowsnow

Here's an update on this Heisenbug.  I re-wrote the "Let's make sure IC54 worked" code and the bug (seems to have) gone away.  I did not reboot the machine or do anything else other than edit the script.

Here's the updated code (note that I still have IC54(1) at the top of the script, so by the time this code is reached, it should already be set).  In the current incarnation, the Display() statement is never reached (i.e., displayed).

(By the way, I sure wish there was some kind of "code blocks" facility on this board - with syntax highlighting like in the old days)

FOR I = 1 TO 20
    IF IntControl(54,"",-1,0,0) THEN Break
    Terminate(Display(1,"%I%) Returned value of IC54 is:",IntControl(54,"",1,0,0)),ProgDate,"You hit escape, so we're out of here!")
NEXT
Terminate(!IntControl(54,"",-1,0,0),ProgDate,"Window on top (IC54) didn't work!")

td

A "code blocks" widget exists in the menubar above the text area. It places \[code\]\[code\]* BB tags in the text editor area. But, as you rightly mention, there is no syntax coloring.

*backslashes were added to prevent the tags from being interpreted by the forum software.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

snowsnowsnow

I see.  Thanks.  (Yes, I edited my previous post, putting the code in a code block.  It is nicer, but still missing the highlighting...)