Posts: 2,169
Threads: 222
Joined: Apr 2022
Reputation:
103
11-15-2022, 08:01 PM
(This post was last modified: 11-15-2022, 08:01 PM by Pete.)
@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
Posts: 733
Threads: 30
Joined: Apr 2022
Reputation:
43
11-15-2022, 08:08 PM
(This post was last modified: 11-15-2022, 08:14 PM by SpriggsySpriggs.)
@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
Posts: 2,169
Threads: 222
Joined: Apr 2022
Reputation:
103
11-15-2022, 08:17 PM
(This post was last modified: 11-15-2022, 08:17 PM by Pete.)
@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
Posts: 2,169
Threads: 222
Joined: Apr 2022
Reputation:
103
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
Posts: 733
Threads: 30
Joined: Apr 2022
Reputation:
43
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
Posts: 2,169
Threads: 222
Joined: Apr 2022
Reputation:
103
@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...
Posts: 2,169
Threads: 222
Joined: Apr 2022
Reputation:
103
Here is a screenshot if we just PRINT the results to the screen...
Power of 2 sign:
Shoot first and shoot people who ask questions, later.
Posts: 733
Threads: 30
Joined: Apr 2022
Reputation:
43
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
Posts: 733
Threads: 30
Joined: Apr 2022
Reputation:
43
And this gives you the o with the accent:
Notice, I've changed SetWindowTextW to SetWindowText A
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
Posts: 1,586
Threads: 59
Joined: Jul 2022
Reputation:
52
11-15-2022, 08:39 PM
(This post was last modified: 11-15-2022, 08:45 PM by mnrvovrfc.)
^
|
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
|