Maybe this whole project would be a lot easier if you forgot about trying to use the console and went to a "console-like" GUI object?
Here's an example of using a listview control to simulate a console....
Use Listview control as a console. September 13 2003.
...and here's an example of showing Unicode characters on GUI screens...
Directory List with Non-ASCII (Unicode) characters in file names 5-31-08
I have not worked with console applications a whole lot, but what I have learned is the console is its own animal.
Or, maybe Perfect Sync's Console Tools product can help you?
MCM
Announcement
Collapse
No announcement yet.
Trouble formatting 'foreign text' output in chars matching console O/P code page
Collapse
X
-
Originally posted by Michael Mattias View PostJust for the heck of it, what happens if you use STDOUT instead of PRINT?
None of it helps me with my particular problem, but I guess it is useful to document the differences in that they contribute something to the pool of knowledge about how these commands and Windows interact.
Leave a comment:
-
Just for the heck of it, what happens if you use STDOUT instead of PRINT?
Or, maybe you need to ....
Code:#CONSOLE OFF FUNCTION WinMain.... AllocConsole ------------------------------------------------------ Now do all your own console manipulation I doubt the PRINT statement will work under these conditions but there are Windows' Consolexxx() functions you can call to send output to the console. ----------------------------------------------------------- ...
Leave a comment:
-
Trouble formatting 'foreign text' output in chars matching console O/P code page
The following test program demonstrates what I am trying to achieve. The attached (jpg) screenshot shows the output of the command line: TestCP502.exe P862 when run under Windows XP (SP3).
I expected at least one of the five string-literal output lines (near the end of PBMain) to match the line directly above them (output line 2), but none of them do. Does this mean that you can only output 'foreign text' written in non-Latin characters by doing something like:
print chr$(80,111,119,101,114,66,97,115,105,99) ' print "PowerBasic"
Why doesn't the conversion using the ucode$() function behave as expected? One of those specifying the use of code page 862 should have worked. Am I doing something wrong?
Code:' TestCP502.bas ' ------------- ' Compiler: PBCC 5.02 #COMPILE EXE #DIM ALL %False = 0 : %True = not %False ' The following two function declares extracted from Win32API.inc ' Last updated 27 August 2009 as shipped with PBCC 5.02 DECLARE FUNCTION SetConsoleOutputCP LIB "KERNEL32.DLL" _ ALIAS "SetConsoleOutputCP" (BYVAL dwCodePageID AS DWORD) AS LONG DECLARE FUNCTION GetConsoleOutputCP LIB "KERNEL32.DLL" _ ALIAS "GetConsoleOutputCP" () AS LONG function PBMain& ' ------- local Tail$, CP$, TailLength&, TailPos&, CodePage&, RtnVal& ' First set console output code page as determined by command line argument ' or default code page 437 OEM U.S. Tail$ = ucase$(rtrim$(command$)) TailLength& = len(Tail$) TailPos& = instr(Tail$, "P") if TailPos& > 0 _ and TailPos& < TailLength& then CP$ = extract$(TailPos& + 1, Tail$, $SPC) CodePage& = val(CP$) end if if CodePage& = 0 then CodePage& = 437 ' Default CodePage is IBM 437 OEM U.S. print "Setting code page to" CodePage& "... "; RtnVal& = FnSetOPCP& (CodePage&) if RtnVal& = 0 then print "Failed. Code page is" GetConsoleOutputCP else print "Success. Code page is" RtnVal& end if ' ------- Experimental Hebrew output ------- ' Part 1 using chr$(n) ... print chr$(128 to 154) ' Hebrew alphabet ' Part 2 using string literals (string pasted from BabelPad)... print "àáâãäåæçèéêëìíîïðñòóôõö÷øùú" print ucode$("àáâãäåæçèéêëìíîïðñòóôõö÷øùú") print ucode$("àáâãäåæçèéêëìíîïðñòóôõö÷øùú", 862) print acode$(ucode$("àáâãäåæçèéêëìíîïðñòóôõö÷øùú")) print acode$(ucode$("àáâãäåæçèéêëìíîïðñòóôõö÷øùú", 862)) print "Press any key to end ..." waitkey$ end function ' PBMain& --------------------------------------------- ' FnSetOPCP& ' ---------- ' Sets console output code page using API function. ' http://msdn.microsoft.com/en-us/library/ms686013%28VS.85%29.aspx ' An alternative method is: ' shell "mode.com con: codepage select=" + ltrim$(str$(CodePage)) ' Code page is specified in parameter CodePage. ' Return value is 0 (failure) or code page number as returned by the API ' function GetConsoleOutputCP. ' MSDN (http://msdn.microsoft.com/en-us/library/dd317756%28VS.85%29.aspx) ' says: Note ANSI code pages can be different on different computers, or ' can be changed for a single computer, leading to data corruption. For the ' most consistent results, applications should use Unicode, such as UTF-8 ' or UTF-16, instead of a specific code page. ' 437 = IBM437 = OEM United States ' 20127 = us-ascii = US-ASCII (7-bit) ' 20269 = x-cp20269 = ISO 6937 Non-Spacing Accent ' 65000 = utf-7 = Unicode (UTF-7) ' 65001 = utf-8 = Unicode (UTF-8) ' 1200 = utf-16 = Unicode UTF-16, little endian byte order (BMP of ' ISO 10646); available only to managed applications ' 1201 = unicodeFFFE = Unicode UTF-16, big endian byte order; available ' only to managed applications ' 862 = DOS-862 = OEM Hebrew; Hebrew (DOS) ' 1255 = windows-1255 = ANSI Hebrew; Hebrew (Windows) ' 10005 = x-mac-hebrew = Hebrew (Mac) ' 20424 = IBM424 = IBM EBCDIC Hebrew ' 28598 = iso-8859-8 = ISO 8859-8 Hebrew; Hebrew (ISO-Visual) ' 38598 = iso-8859-8-i = ISO 8859-8 Hebrew; Hebrew (ISO-Logical) ' Unicode subsets: Hebrew = 0590 - 05FF, Box Drawing: 2500 - 257F function FnSetOPCP& (CodePage as dword) ' ---------- local RtnVal& RtnVal& = SetConsoleOutputCP(CodePage) sleep 400 ' Give Windows time to react if isfalse RtnVal& then function = 0 ' failure else RtnVal& = GetConsoleOutputCP function = RtnVal& end if end function ' FnSetOPCP& -----------------------------------------
Leave a comment: