Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_TITLE and extended ASCII characters.
#1
I'd like to put CHR$(240), three small horizontal lines, in my title bar, but the _TITLE function cannot convert extended ASCII characters. Is there another method that wold print the 3 horizontal bars into the title bar so it doesn't look like this: ð

Pete
Reply
#2
CHR$(240) is a mapped unicode character, so it's going to display, by default, whatever code page your OS is configured for. (In this case, you're getting the o with the accent over it.)

As far as I can guess, the only way you'd work around this is to use wide characters and call the windows call to set the title yourself.

https://learn.microsoft.com/en-us/window...indowtextw <-- use this for the windows API call to the unicode characters.

Code: (Select All)
_TITLE CHR$(240) + "Foo"

i% = _MAPUNICODE(240)
t$ = MKI$(i%)
title$ = t$ + "F o o "

^ And I'm thinking the above should give you the actual unicode characters that you'd bee looking for.

I'm lazy (and running back and forth to the kitchen cooking breakfst), so I haven't tested putting the pieces together yet, but it seems as if they should do what you want.
Reply
#3
I also tried using unicode, but no success either. Your code displayed an a with two small vertical '' above it.

I'm using CHR$(4) + "Foo" in the _TITLE function to display a transparent box for now. That's right, box, not a diamond.

Maybe we are missing something with the _MAPUNICODE function, I don't know. I haven't worked with it in QB64 before and it maybe especially difficult trying to get the _TITLE function to accept it.

I'm busy running back and forth the Arby's eating breakfast. Dammit I wish they'd stop forgetting to put the horsey sauce in the take out bag!

Pete

[Image: Screenshot-774.png]
Reply
#4
I've played with it a little as well. I think I've got it working, more or less, but there's still no printing of the "menu" icon in the title bar. Instead, it does a substitution as shown below:

Code: (Select All)
DECLARE DYNAMIC LIBRARY "user32"
    FUNCTION SetWindowTextW (BYVAL Handle AS _OFFSET, title$)
END DECLARE

'_TITLE CHR$(240) + "Foo"

i% = _MAPUNICODE(240)
t$ = MKI$(i%)
PRINT t$ 'this is chr$(34) and "a", but they need to be reversed to do anything.  Endianness issue, I guess?
SLEEP 'so we have time to make certain that the _WINDOWHANDLE is properly assigned to this window


title$ = "a" + CHR$(34) + "F" + CHR$(0) + "o" + CHR$(0) + "o" + CHR$(0) + CHR$(0)
result = SetWindowTextW(_WINDOWHANDLE, title$) 'IF the line with _TITLE is uncommented above, this does nothing.
SLEEP

All that effort just to get "=Foo" to display! Tongue
Reply
#5
Strange. It doesn't print the three horizontal marks in the title bar, only 2. More like an equals sign instead of CHR$(240).

Pete
Reply
#6
(11-15-2022, 06:39 PM)Pete Wrote: Strange. It doesn't print the three horizontal marks in the title bar, only 2. More like an equals sign instead of CHR$(240).

What is also weird is it didn't work with another method using MID$() to extract the "a"...   It beeps, so the two strings, title1$ and title2$, are the same, but only the later one creates a title.

Pete

That's why I mentioned, "all that effort just to get "=Foo" as the title."  I don't know if it's some windows specific replacement routine going on with the title, or what the heck it is, but the triple line ends up only becoming a double line.  IF anyone else has any ideas over what's wrong here, I'd love to hear them, as it seems to me that it should be working as written.  

I've also noticed the glitch with not building the string character by character.  You can't RIGHT$ + LEFT$ to reverse the letters, and make it work either.   ANd, let you tested, one string is equal to the other string, but windows works with one and not the other...  Now, explain that to me!  ???

Maybe you should just go with "|||Foo" and tell people your bars toppled over sideways in the wind. Tongue
Reply
#7
Right. I edited the other stuff out to avoid confusing others. One rabbit hole at a time.

Weird that _MAPUNICODE correctly equals 8801 but only shows up as 2 bars. Maybe its poor tower reception and we need to upgrade to QB64-PE 5G?

https://www.codetable.net/decimal/8801

See folks, Steve and I aren't crazy, three bars!

Maybe I should try the QB64 "Official" version, but every time I walk over there, I come back with cricket juice on my shoes.

Pete
Reply
#8
Ah, maybe it has something to do with the configuration. It seems to be that = sign is something Windows throws in. Also "?" marks and a few other symbols with different values, but we are actually not seeing the UNICODE character here. It's a red herring.

Code: (Select All)
DECLARE DYNAMIC LIBRARY "user32"
    FUNCTION SetWindowTextW (BYVAL Handle AS _OFFSET, title$)
END DECLARE
_CONTROLCHR OFF
DO
    j = j + 1
    i% = _MAPUNICODE(126 + j)

    t$ = MKI$(i%)
    PRINT 126 + j, i%, MID$(t$, 1, 1), t$

    _DELAY .1

    title$ = CHR$(64 + j) + CHR$(34) + "F" + CHR$(0) + "o" + CHR$(0) + "o"
    result = SetWindowTextW(_WINDOWHANDLE, title$)
    SLEEP
LOOP

Watch the title bar change to ?Foo to =Foo at 159.

Pete
Reply
#9
Give this a try, @Pete. This is a function set I use to convert to and from Unicode:
Code: (Select All)
$If UNICODETOANSI = UNDEFINED Then
    $Let UNICODETOANSI = DEFINED
    Declare CustomType Library
        Function WideCharToMultiByte& (ByVal CodePage As _Unsigned Long, Byval dwFlags As Long, Byval lpWideCharStr As _Offset, Byval cchWideChar As Integer, Byval lpMultiByteStr As _Offset, Byval cbMultiByte As Integer, Byval lpDefaultChar As _Offset, Byval lpUsedDefaultChar As _Offset)
        Function MultiByteToWideChar& (ByVal CodePage As _Unsigned Long, Byval dwFlags As Long, Byval lpMultiByteStr As _Offset, Byval cbMultiByte As Integer, Byval lpWideCharStr As _Offset, Byval cchWideChar As Integer)
    End Declare

    Function UnicodeToANSI$ (buffer As String)
        Dim As String ansibuffer: ansibuffer = Space$(Len(buffer))
        Dim As Long a: a = WideCharToMultiByte(437, 0, _Offset(buffer), Len(buffer), _Offset(ansibuffer), Len(ansibuffer), 0, 0)
        UnicodeToANSI = Mid$(ansibuffer, 1, InStr(ansibuffer, Chr$(0)) - 1)
    End Function

    Sub UnicodeToANSI (buffer As String, __dest As String)
        Dim As String ansibuffer: ansibuffer = Space$(Len(buffer))
        Dim As Long a: a = WideCharToMultiByte(437, 0, _Offset(buffer), Len(buffer), _Offset(ansibuffer), Len(ansibuffer), 0, 0)
        __dest = Mid$(ansibuffer, 1, InStr(ansibuffer, Chr$(0)) - 1)
    End Sub

    Function ANSIToUnicode$ (buffer As String)
        Dim As String unicodebuffer: unicodebuffer = Space$(Len(buffer) * 2)
        Dim As Long a: a = MultiByteToWideChar(65001, 0, _Offset(buffer), Len(buffer), _Offset(unicodebuffer), Len(unicodebuffer))
        ANSIToUnicode = unicodebuffer
    End Function

    Sub ANSIToUnicode (buffer As String, __dest As String)
        Dim As String unicodebuffer: unicodebuffer = Space$(Len(buffer) * 2)
        Dim As Long a: a = MultiByteToWideChar(65001, 0, _Offset(buffer), Len(buffer), _Offset(unicodebuffer), Len(unicodebuffer))
        __dest = unicodebuffer
    End Sub
$End If
Tread on those who tread on you

Reply
#10
I'm going to post this, and try Spriggsy's solution and post back.

This just shows _MAPUNICODE gets the right number, but converting it to a string fails to create the correct character...

Code: (Select All)
t$ = MID$(MKI$(_MAPUNICODE(240)), 1, 1)
    PRINT t$

Pete
Shoot first and shoot people who ask questions, later.
Reply




Users browsing this thread: 14 Guest(s)