Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_TITLE and extended ASCII characters.
#11
@Spriggsy

Must be doing something wrong here. Letters print, but no CHR$(240)

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

result = SetWindowTextW(_WINDOWHANDLE, UnicodeToANSI$(CHR$(240)) + " " + CHR$(0) + "F" + CHR$(0) + "o" + CHR$(0) + "o" + CHR$(0) + CHR$(0))

$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

Pete
Reply
#12
@Pete

You've used the wrong function. You don't want UnicodeToAnsi. You want AnsiToUnicode. Also, you have to grab the whole string, not just part of it. You want all of it to be converted to Unicode.


Code: (Select All)
Declare Dynamic Library "user32"
    Function SetWindowTextW (ByVal Handle As _Offset, title$)
End Declare

Do: Loop Until _WindowHandle

result = SetWindowTextW(_WindowHandle, ANSIToUnicode(Chr$(240) + " Foo"))

$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

Besides, I think we have to do some special stuff to enable Unicode display on the title bar. I'll have to dig through my code archives to find the one I've used for displaying foreign characters.
Tread on those who tread on you

Reply
#13
@Spriggsy

Nope. It throws a question mark in the title bar. Also the " Foo" won't show without special formatting. See below, but we still can't get the unicode chr$(240) to print.

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

DO: LOOP UNTIL _WINDOWHANDLE

result = SetWindowTextW(_WINDOWHANDLE, ANSIToUnicode(CHR$(240)) + " " + CHR$(0) + "F" + CHR$(0) + "o" + CHR$(0) + "o" + CHR$(0) + CHR$(0))

$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

Pete
Reply
#14
So lets go from the title bar to just printing the character on the screen.

Oh, this is something...

PRINT ANSIToUnicode(CHR$(240))

That displays the power of 2 symbol, not the three horizontal lines. I experienced that by messing with MKS$ I think, instead of using MKI or some other MK... statement.

Pete
Reply
#15
You've still done something wrong, Pete. You shouldn't be passing the "Foo" like that at all. Pass it as a normal string INSIDE the AnsiToUnicode function call, like I showed in my previous reply.
Tread on those who tread on you

Reply
#16
@Spriggsy

Copied and ran the code you posted.

Results...

See the "?" mark in the TITLE bar, which, as you stated, something more probably has to be done to get it to display in the title bar.

However, did you see my post that shows it prints the squared sign, instead of the 3-horizontal lines when used as a PRINT statement? So it looks like that's how it would also display on the title bar.

Here is the screen shot of the code you posted...

[Image: Screenshot-775.png]
Reply
#17
Here is a screenshot if we just PRINT the results to the screen...

Power of 2 sign:
[Image: Screenshot-776.png]
Shoot first and shoot people who ask questions, later.
Reply
#18
Right, yeah. The question mark is what Windows defaults to when it cannot make a conversion of a character to another equivalent code.
Tread on those who tread on you

Reply
#19
And this gives you the o with the accent:
Notice, I've changed SetWindowTextW to SetWindowTextA

Code: (Select All)
Declare Dynamic Library "user32"
    Sub SetWindowTextA (ByVal Handle As _Offset, title$)
End Declare

Do: Loop Until _WindowHandle

SetWindowTextA _WindowHandle, Chr$((240)) + " Foo"

$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
#20
^
|
I was going to write something in relation to that. Maybe Windows doesn't go along with "CP437" or whatever code page. Does this "three-bar" thing assume the CHR$(255) is the "y" with dieresis, or not? Because if it does then it's what Spriggsy just showed. Might have to go looking for the real Unicode value for the desired character. This is something I discovered in NPPP, which uses a different "code page" than QB64 IDE.

The "code page" Windows is using is apparently different from this one:

https://www.freebasic.net/wiki/CptAscii

Maybe involve the "UnicodetoANSI$()" API call out of this finding?

https://qb64phoenix.com/forum/showthread...59#pid9859
Reply




Users browsing this thread: 2 Guest(s)