[function] CueBanner (with a twist)

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

[function] CueBanner (with a twist)

13 Jul 2017, 10:04

Sometimes people say "it can't be done". I say "let me check that". And sometimes - just sometimes - I prove them wrong. ;)

Starting with Windows XP, M$ introduced the concept of a cue banner in Edit controls. Good and useful idea, badly implemented.
First of all, the cue banner - enabled by sending the message EM_SETCUEBANNER to the respective control - does not take into account various visual styles, resulting in the text being cut off to the left in some setups (see screenshot, second image).
Second - and more importantly - a bug prevents the cue banner from being displayed on an XP system that has the Right-To-Left support/font package installed.
Third issue is that cue text font color/attributes can't be set at all in the original implementation.
Fourth issue is that the 'persistent mode' just doesn't appear to work (that is, show cue text even when control is focused but no text was input).
Fifth - and I know you'll hate me for this :D : we 9x users get no love! :roll:

Then, ComboBox cue banner was added to Vista through CB_SETCUEBANNER. But XP users got no love this time.

Well, no mas ! (as Bevery Hills Chihuaua used to say :mrgreen: )
I present you with CueBanner - the function that can add cue banners duplicating same font family/size/weight as the control, with or without shadow/blur, to virtually any type of control*, in any version of Windows ranging from Windows 98 to… oh well, that's for you guys to test and report back. ;)
CueBanners 2.5R.png
CueBanners 2.5R.png (1.19 MiB) Viewed 4305 times
I'd like to thank Helgef for his kindness in testing and reporting issues with this function under an x64 system (which I do not have access to). Without his help I would've published a buggy script. The screenshot below was sent by him for first public version. Thank you very much, Helgef! :salute:
CueBanners U64.png
Cue Banners on Windows x64 (courtesy Helgef)
CueBanners U64.png (26.97 KiB) Viewed 4273 times
Now, there's not much to say about this function other than the comments in the code can offer. The code probably looks messy because it uses the old basic syntax - required for compatibility with 98/98SE/ME systems - and because I'm not a real programmer, but who cares as long as it works. :oops:

Windows 98SE or ME users that have the Revolutions Pack installed can make use of the shadow option (see screenshot, first image); otherwise the cue text will appear normally. No more RP9 dependency since v2.5. ;)
There still is a known bug/limitation - clearly shown in the screenshot (third image), the combobox at the bottom of first image - where unsupported Unicode characters (in this case Arabic and Hebrew, randomly picked characters in Character Map) on an English 9x system will display gibberish. I'll keep looking into that but chances of success are slim. Help would be appreciated.
Unicode is now fully working in Win9x since v2.5.

That being said, here's the function, complete with any additional dependencies and an example script:
CueBanner2.6.1.7z
(14.7 KiB) Downloaded 203 times
Older version(s) can be found at my repository in CueBanner, seeing that board's upload count is limited.

Enjoy! :wave:

* The function has only been tested on Edit, DropDownList, ComboBox, Static, Button, Radio, Checkbox type of controls so far; any further reports with other control types would be welcome.
Last edited by Drugwash on 26 Jul 2017, 07:58, edited 5 times in total.
Part of my AHK work can be found here.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [function] CueBanner (with a twist)

13 Jul 2017, 11:48

Very nice! :thumbup:
Thank you very much, Helgef!
You are welcome, it was no bother. Thanks for sharing!

Cheers

Edit:
I just happened to remember this thread, Examples of Non-Standard GUIs (ActiveX, GDI, etc.), this function might be of interest for the subscribers to that thread. You should make a post.
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: [function] CueBanner (with a twist)

14 Jul 2017, 14:43

Thanks, but seeing how "well" this function was received so far, advertising it may be equally useless.
Nevertheless, I just posted an update:

v2.4
- fixed RemoveWindowSubclass() error for ComboBoxes
- fixed DrawTextShadowEx() parameters to take into account shadow offsets in Win9x
- added new parameter 'm' for multiline cue text (see the version info field)
- minor code fixes

Most of the additional script dependencies are only used by the example script; the function script itself only depends on updates.ahk and func_GetProcAddressEx.ahk. The latter could easily be integrated in the Cue Banner script and same for the variables provided by updates.ahk (AW, PtrSz and A_CharSize - the rest already exist in AHK 1.1+) but personally I prefer modularity. Feel free to do as you please.
Part of my AHK work can be found here.
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: [function] CueBanner (with a twist)

14 Jul 2017, 16:21

Nice indeed, well done! Thank you.
burque505
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: [function] CueBanner (with a twist)

14 Jul 2017, 16:35

You're too kind, thank you. :oops:

Here's an updated screenshot as a bonus:
CueBanners 2.4.png
CueBanners 2.4.png (39.94 KiB) Viewed 4414 times
Part of my AHK work can be found here.
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: [function] CueBanner (with a twist)

16 Jul 2017, 16:00

Finally I nailed it! Full bidirectional Unicode text in Win9x. :dance:
Here's the proof (text is changed, got it in a text file that came with a project by J. Brown at Catch22):
CueBanners 2.5.png
Unicode RTL text in Windows 98SE
CueBanners 2.5.png (12.18 KiB) Viewed 4365 times
Unfortunately text alignment using the new Uniscribe functions is a bit more complicated to achieve than with DrawText(Ex) or DrawShadowText, flags must be translated, extra calculations must be done and, on top of it all, not even M$ can decide how to properly display the text in controls that may have a various combination of styles. And no, this is not exclusively related to Win9x but to other versions as well.

I've tested the very same script on the same three machines as above: 98SE, XP-SP3 without East-Asian pack and XP-SP3 with East-Asian pack. The styles tested were as following:
- WS_EX_LAYOUTRTL=0x400000
- WS_EX_RTLREADING=0x2000
- WS_EX_RIGHT=0x1000
and the results can be seen below:
Text alignment issues.png
Text alignment in controls
Text alignment issues.png (69.19 KiB) Viewed 4365 times
For this reason I'm not sure how to treat different styles and flags retrieved from the controls that are to receive the cue text and more importantly I don't know how to accurately find how the inner elements are aligned (ComboBox arrows, checkboxes and radio bitmaps etc) in order to calculate the usable rectangle where the cue should be displayed, so as not to draw over those elements.

Any help with these issues would be appreciated. In the mean time I'll try to clean things up a bit.
Part of my AHK work can be found here.
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: [function] CueBanner (with a twist)

19 Jul 2017, 10:35

New version 2.5 is up.
Now I can have a drink, considering it's my birthday.
Cheers and enjoy!
Part of my AHK work can be found here.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [function] CueBanner (with a twist)

19 Jul 2017, 11:07

Nice new example, and
:happybday: :beer:
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: [function] CueBanner (with a twist)

19 Jul 2017, 11:37

Thank you very much! :)
There's a hidden trick to using cue banners instead of actual control text: any GUI stealer will come up empty handed. :D

[EDIT]
New screenshot was posted in a hurry, forgot to edit the text too. Now I fixed it and added back your screenshot because it's only fair. ;)
Hopefully the function still works (correctly) for you on x64. :?:
Part of my AHK work can be found here.
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: [function] CueBanner (with a twist)

26 Jul 2017, 07:15

New version 2.6 is up.

- minor code improvement (replaced superfluous CueBanner_GetCls() with the built-in command WinGetClass)
- renamed callback function CueBannerCB() to CueBanner_CB() to fit library specifications
- reduced exit cleanup to a single call (unloading comctl32/usp10) thanks to Raymond Chen's hint on WM_NCDESTROY (Safer subclassing)

[EDIT]
Bugfix version 2.6.1:

- fixed error on RemoveWindowSubclass() due to duplicate call with empty buffer
(still needs investigation on why second call, but for now we just avoid that call)
Part of my AHK work can be found here.
amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: [function] CueBanner (with a twist)

25 Jan 2022, 19:19

I'm here just to say thank you for the function that works even there where original cue banner fails!
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: [function] CueBanner (with a twist)

26 Jan 2022, 02:11

Thank you kindly. :) It's been a while since building this thing. It was mostly a proof of concept, especially for Win98/ME with that shadowed text and the Unicode strings. No idea if that still works in latest Windows versions, got none here to test with. Too bad shadow doesn't work in Wine.
Part of my AHK work can be found here.
amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: [function] CueBanner (with a twist)

26 Jan 2022, 06:45

Spoiler
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: [function] CueBanner (with a twist)

26 Jan 2022, 16:08

Yay, it still works! Well, that's backward compatibility for you - unlike Linux. :)
Thanks for the undeniable proof. :)
Part of my AHK work can be found here.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: tiska and 155 guests