Jump to content
TimRude

SplashTextOn with Ampersand in Text

Recommended Posts

TimRude

If the text parameter of the SplashTextOn function includes an ampersand, it's displayed as a mnemonic prefix.

Example: SplashTextOn("Sample", "This&That", 200, 100) displays the text as ThisThat instead of This&That.

I know I could double the ampersand (i.e. "This&&That") to avoid this, but in this case the text being displayed is a filename which may or may not contain an ampersand.

Since the text displayed in the SplashText dialog isn't a hotkey-capable control caption, it makes no sense for the text to be treated as such. Therefore the underlying code which produces the dialog should use the style flag that prevents the mnemonic prefix handling (such as $DT_HIDEPREFIX for example).

SplashTextOn.gif

Share this post


Link to post
Share on other sites
AdamUL

A simple workaround is to use StringReplace to replace single ampersands with double ampersands.  Example below.  

Global $sText = "This&That"
If StringInStr($sText, "&") Then $sText = StringReplace($sText, "&", "&&") 
 SplashTextOn("Sample", $sText, 200, 100)
 
 Sleep(1000)
 
 SplashOff()

 

Adam

 

Share this post


Link to post
Share on other sites
BrewManNH
14 minutes ago, TimRude said:

Since the text displayed in the SplashText dialog isn't a hotkey-capable control caption

Blame Microsoft for that, it's a Windows default action for controls with text.

You can always create your own splash screen and have it work however you'd want. See my signature for an example.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
TimRude
22 minutes ago, AdamUL said:

A simple workaround is to use StringReplace to replace single ampersands with double ampersands.

Yeah, that'll work. I still think it's a bug in the SplashTextOn code.

19 minutes ago, BrewManNH said:

Blame Microsoft for that, it's a Windows default action for controls with text.

Yes, it's dumb for MS to make that the default. But it's also something that should be overridden when the default is not the desired behavior, as in this case.

Share this post


Link to post
Share on other sites
BrewManNH

Who says it's not the desired behavior? Just because it's not your desired behavior doesn't make your desire the default either.

There are workarounds to this, you been shown how to do it, it's the default Windows API behavior, you need to adapt to it, not the other way around.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
TimRude
On ‎6‎/‎4‎/‎2018 at 7:48 AM, BrewManNH said:

Who says it's not the desired behavior? Just because it's not your desired behavior doesn't make your desire the default either.

There are workarounds to this, you been shown how to do it, it's the default Windows API behavior, you need to adapt to it, not the other way around.

Can you think of a valid use-case where it would be desirable that a control which cannot respond to a hot-key should display a hotkey mnemonic?

Just because something is the default Windows API behavior doesn't mean that it's appropriate in all situations. OK, I shouldn't have said it was dumb for MS to make that the default. Forget that. My point was that in this particular case (the SplashTextOn dialog), it makes no sense to allow the default behavior to apply when there is no value to displaying a mnemonic hotkey indicator in this context.

Share this post


Link to post
Share on other sites
BrewManNH

I don't work for Microsoft, ask them.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
spudw2k
Posted (edited)

Looking at the control displaying the text--it is a Static control, so the behavior makes sense since it appears to be a default style.  Static controls support a style called SS_NOPREFIX which, "...Prevents interpretation of any ampersand (&) characters in the control's text as accelerator prefix characters" which can be used to address this behavior. 

Here's a demo on one way to apply the NOPREFIX style to the Static control inside the SplashTextOn window:

#include <WinAPI.au3>
#include <Constants.au3>
#include <StaticConstants.au3>

$hWnd = SplashTextOn("Splash Screen","B&efore NOPREFIX Style")
sleep(5 * 1000)
$hWndStatic = ControlGetHandle($hWnd,"","Static1")
$iStyle = _WinAPI_GetWindowLong($hWndStatic,$GWL_STYLE)
$iNewStyle = BitOR($iStyle, $SS_NOPREFIX)
_WinAPI_SetWindowLong($hWndStatic, $GWL_STYLE, $iNewStyle)
_WinAPI_SetWindowText ($hWndStatic, "A&fter NOPREFIX Style")
sleep(5 * 1000)

 

Either way, it's going to take extra work to make it behave the way you want/need it to.

Edited by spudw2k

Share this post


Link to post
Share on other sites
TimRude
On ‎5‎/‎30‎/‎2018 at 2:00 PM, AdamUL said:

A simple workaround is to use StringReplace to replace single ampersands with double ampersands...

On ‎6‎/‎7‎/‎2018 at 2:15 AM, spudw2k said:

Here's a demo on one way to apply the NOPREFIX style to the Static control inside the SplashTextOn window...

The workarounds are appreciated, so thanks for those.

 

On ‎6‎/‎6‎/‎2018 at 11:12 AM, BrewManNH said:

I don't work for Microsoft, ask them.

This isn't a Microsoft forum. It's an AutoIt forum. I wasn't suggesting a global change in Microsoft's defaults or questioning their motivation. I was suggesting that whoever coded the SplashText routine in AutoIt should have specified the $SS_NOPREFIX style flag for this specific dialog, since a mnemonic hotkey indicator isn't useful in this specific dialog.

I really love AutoIt, but not to the extreme that I believe it's 100% perfect, with no quirks that could be improved. Replies along the lines of 'that's how it is, it can't be changed, if you don't like it roll your own' don't encourage improvement.

I give up. :mad2:

Share this post


Link to post
Share on other sites
TimRude
18 minutes ago, Jos said:

No need to give up on anything, just create an ticket in trac to ask for the change of the behavior of the Function.

Jos

Done. Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×