BBC BASIC for Windows
Programming >> User Interface >> Cue banners
http://bb4w.conforums.com/index.cgi?board=ui&action=display&num=1386770282

Cue banners
Post by KenDown on Nov 21st, 2013, 07:35am

While browsing the wiki the other day I came across these and thought they might be fun. I copied the relevant code straight into my program, called the PROC *after* PROC_showdialog and looked for the results. Nothing.

Hmmmm.

A couple of questions, please: if I RUN the program from the editor will the cue banners show up? The Wiki *seems* to indicate that they won't, but it's not clear.

Do I need a special flag in the PROC_editbox? I normally use &80 but I did try 0 but perhaps something else is necessary?

Any other advice?

Thanks
Re: Cue banners
Post by admin on Nov 21st, 2013, 09:11am

on Nov 21st, 2013, 07:35am, KenDown wrote:
While browsing the wiki the other day I came across these and thought they might be fun. I copied the relevant code straight into my program, called the PROC *after* PROC_showdialog and looked for the results. Nothing.

It will almost certainly be because you are running a 64-bit version of Windows. As has been much discussed here and elsewhere, there is a nasty incompatibility whereby Unicode strings must be WORD-aligned when running under WoW64, but they need not be when running under 'genuine' 32-bit Windows.

I have updated that Wiki article to align the strings, so the code should now work (I've tested it here):

http://bb4w.wikispaces.com/Setting+an+edit+box+cue+banner

Richard.
Re: Cue banners
Post by Malvern on Nov 21st, 2013, 4:21pm

I have been using this on 64 bit Windows for several years.
Code:
 a$=FNwide(" New Cue")
      SYS "SendMessage",hbox%, EM_SETCUEBANNER ,0,!^a$

      DEF FNwide(A$)
      LOCAL M$
      M$ = STRING$(2*LENA$+2," ")
      SYS "MultiByteToWideChar", 0, 0, A$, -1, !^M$, LENA$+1
      = M$
 


Which is some of Richard's work. If alignment is needed it is done by the string handling perhaps?

Re: Cue banners
Post by admin on Nov 21st, 2013, 5:42pm

on Nov 21st, 2013, 4:21pm, Malvern wrote:
If alignment is needed it is done by the string handling perhaps?

No it's not (there's a 50% chance of it being misaligned) and sadly you can expect that code to fail on some systems. The precise circumstances when alignment is and is not required have never been established, but in my own testing of earlier today (Windows 8.1, 64-bits) it definitely was.

Incidentally I don't think your code:

Code:
SYS "SendMessage", hbox%, EM_SETCUEBANNER, 0, !^a$ 

provides any benefit over the more straightforward:

Code:
SYS "SendMessage", hbox%, EM_SETCUEBANNER, 0, a$ 

Richard.
Re: Cue banners
Post by Malvern on Nov 21st, 2013, 9:00pm

Thanks for the correction. a$ is simpler and does work fine. Can't see why I didn't write that to start with.

Incidentally I can't make it not work by moving the buffer position on Win7 64 bit. Strange.
Re: Cue banners
Post by admin on Nov 21st, 2013, 9:54pm

on Nov 21st, 2013, 9:00pm, Malvern wrote:
Incidentally I can't make it not work by moving the buffer position on Win7 64 bit. Strange.

A possible explanation is that drivers are involved as well as Windows itself.

Richard.
Re: Cue banners
Post by KenDown on Nov 24th, 2013, 06:48am

Hmmm. No, sorry, still not working.

I'm running Windows XP Professional Version 2002 with service pack 3 installed on an AMD six core processer. I don't know whether that is the version which causes problems?

I have copied and pasted the code directly from the Wiki page (in includes the wc% = wc% + 1 AND -2, which I presume does the word aligning) and have put the call to the proc *after* displaying the dialog box. I have tried both running directly from the programming window and also after compiling the program and saving it to disk.

Should the cue show up when running directly from the programming window?

Do I need any special flag in the PROC_editbox?
Re: Cue banners
Post by admin on Nov 24th, 2013, 09:35am

on Nov 24th, 2013, 06:48am, KenDown wrote:
Hmmm. No, sorry, still not working.... I'm running Windows XP Professional

I think that will be why. Although MSDN claims that cue banners work under XP, in practice they are only fully supported in Vista and later. For example, if you have installed support for Asian languages in XP (which I have) cue banners don't work at all.

See this blog post for confirmation:

http://blogs.msdn.com/b/michkap/archive/2006/02/25/538735.aspx

Richard.
Re: Cue banners
Post by KenDown on Nov 24th, 2013, 5:32pm

Ah. Thanks, Richard. I'll have to try it on my Vista laptop.
Re: Cue banners
Post by KenDown on Nov 25th, 2013, 8:09pm

Hmmmm. I had a thought during the night and have just confirmed it. Mozilla Firefox displays cue banners as large as life, so there must be more to it than just Windows XP Professional.
Re: Cue banners
Post by admin on Nov 25th, 2013, 11:42pm

on Nov 25th, 2013, 8:09pm, KenDown wrote:
Hmmmm. I had a thought during the night and have just confirmed it. Mozilla Firefox displays cue banners as large as life, so there must be more to it than just Windows XP Professional.

I don't see how you can possibly conclude that. Firefox is a cross-platform application (there are versions for all popular Operating Systems) so it's unlikely to be using the old - and Microsoft would say obsolete - Win32 API internally.

In any case you can't draw a conclusion from how another application behaves, because it may emulate the cue banner another way. It wouldn't be particularly difficult to draw some text in grey, and then clear it as soon as the user types something, which is pretty much all you need to do to reproduce the behaviour of EM_SETCUEBANNER.

Edit: I could do it in Liberty BASIC - which natively supports changing the colour of text in an edit control - in only a few lines.

Richard.