Author Topic: wstring vs string  (Read 2381 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Guest
wstring vs string
« on: January 27, 2019, 05:03:06 AM »

 I still haven't found a definitive way to make it. I have these functions:

Code: [Select]
FUNCTION MSGBOX(string aText) AS LONG
   string aCaption = "PluriBASIC"
   dword mOptions = 0
   FUNCTION = ¤MessageBoxa(0, aText, aCaption, mOptions)   
END FUNCTION

FUNCTION MSGBOX(wstring wText) AS LONG
   wString wCaption = "PluriBASIC"
   dword mOptions = 0 
   FUNCTION = ¤MessageBoxw(0, wText, wCaption, mOptions)   
END FUNCTION

FUNCTION MSGBOX(string aText, dword mOptions) AS LONG
   string aCaption = "PluriBASIC a"
   FUNCTION = ¤MessageBoxa(0, aText, aCaption, mOptions)   
END FUNCTION

FUNCTION MSGBOX(wstring wText, dword mOptions) AS LONG
   wString wCaption = "PluriBASIC w"
   FUNCTION = ¤MessageBoxw(0, wText, wCaption, mOptions)   
END FUNCTION

Invoking this code:

Code: [Select]
   MSGBOX (EXE.wsz(@tv, 0, 30))
   MSGBOX (EXE.chr(@tv, 60, 30))
   MSGBOX (EXE.wsz(@tv, 0, 30), 1)
   MSGBOX (EXE.chr(@tv, 60, 30), 1)

 The first 3 work fine, it picks and displays the text correctly. The fourth one picks unicode and displays nothing. It should pick the ANSI one. But it doesnt match "1" with dword, and ends up (wrongly) picking the unicode one (caption displays "PluriBASIC w").

 Attached is an image of the code being converted.

Brian Alvarez

  • Guest
Re: wstring vs string
« Reply #1 on: January 27, 2019, 05:36:00 AM »

In the above code, using int instead of dword, works fine. :)

Charles Pegge

  • Guest
Re: wstring vs string
« Reply #2 on: January 27, 2019, 07:00:21 PM »
Hi Brian,

This function will support all string combos. Ascii strings are automatically converted to wide.

Code: [Select]
FUNCTION MSGBOX(wstring wText, dword mOptions=0) AS LONG
   wString wCaption = "PluriBASIC w"
   FUNCTION = MessageBoxw(0, wText, wCaption, mOptions)   
END FUNCTION

Brian Alvarez

  • Guest
Re: wstring vs string
« Reply #3 on: January 27, 2019, 08:01:12 PM »
Thanks charles, i will download latest version to check it out. :)

The one i have displays nothing for ANSI strings when using them
in an unicode function.

Arnold

  • Guest
Re: wstring vs string
« Reply #4 on: March 04, 2020, 07:16:30 AM »
Hi Charles,

this is only a reminder, because I forgot about this example:

https://www.oxygenbasic.org/forum/index.php?topic=1911.msg20593#msg20593

I noticed that the l" (small L ?)  is important, because otherwise foreign character sets would not work:

Code: [Select]
uses corewin

messageboxw 0, l"Γεια σου κόσμο",l"Greeting",0      'Greek

MessageBoxW(null, wstring "Hello Windows", wstring "My Message", 0)
MessageBoxW(null, l"Hello Windows",  l"My Message", 0)
MessageBoxW(null, l"Привет винда!",  l"Мое сообщение", 0)  'Russian

Is there still another possible usage for l" ?

Roland

Arnold

  • Guest
Re: wstring vs string
« Reply #5 on: March 05, 2020, 01:44:38 AM »
Maybe I should think a little more sometimes. But I did not expect that this would work:

Code: [Select]
wstring cr  = wchr(13,10)
wstring tab = wchr(9)

wstring caption = L"English" tab L"Greek" tab L"Serbian" tab L"Chinese"
wstring term1   = L"House"   tab L"Σπίτι" tab L"Кућа"    tab L"屋"
wstring term2   = L"City"    tab L"Πόλη"  tab L"град"    tab L"市"

print caption + cr + term1 + cr + term2

The option L" needs to be examined a little more closely.
« Last Edit: March 05, 2020, 01:51:20 AM by Arnold »

Arnold

  • Guest
Re: wstring vs string
« Reply #6 on: March 05, 2020, 05:43:33 AM »
I am really amazed. If all of this is correct, I will start programming in Unicode.

 The HelloWin app:
Code: [Select]
$ filename "HelloWin.exe"
'uses rtl32
'uses rtl64

uses corewin
 
! PlaySoundW lib "winmm.dll"

% DT_SINGLELINE = &H20
% DT_CENTER     = &H1
% DT_VCENTER    = &H4
% SND_ASYNC        0x0001  ' play asynchronously
% SND_FILENAME    0x20000 ' name is file name


sys hInstance = GetModuleHandleW (NULL)
int iCmdShow = SW_SHOW

function WinMain () as sys
     wstring      szAppName = L"HelloWin"
     sys          hwnd
     MSG          msg
     WNDCLASS     wc

     wc.style         = CS_HREDRAW or CS_VREDRAW
     wc.lpfnWndProc   = @WndProc
     wc.cbClsExtra    = 0
     wc.cbWndExtra    = 0
     wc.hInstance     = hInstance
     wc.hIcon         = LoadIconW (NULL, IDI_APPLICATION)
     wc.hCursor       = LoadCursorW (NULL, IDC_ARROW)
     wc.hbrBackground = GetStockObject (WHITE_BRUSH)
     wc.lpszMenuName  = NULL
     wc.lpszClassName = strptr szAppName

     if not RegisterClassW (&wc) then
          MessageBoxW (NULL, L"Cannot RegisterClass wc",
                       szAppName, MB_ICONERROR)
          return 0
     end if
     
     hwnd = CreateWindowExW (0,
                             szAppName,                  // window class name
                             L" The Hello Program",      // window caption
                             WS_OVERLAPPEDWINDOW,        // window style
                             CW_USEDEFAULT,              // initial x position
                             CW_USEDEFAULT,              // initial y position
                             CW_USEDEFAULT,              // initial x size
                             CW_USEDEFAULT,              // initial y size
                             NULL,                       // parent window handle
                             NULL,                       // window menu handle
                             hInstance,                  // program instance handle
                             NULL)                       // creation parameters
     
     ShowWindow (hwnd, iCmdShow)
     UpdateWindow (hwnd)
     
     while GetMessageW (&msg, NULL, 0, 0)
          TranslateMessage (&msg)
          DispatchMessageW (&msg)
     wend

end function

function WndProc (sys hwnd, uint message, sys wParam, sys lParam) as sys callback
     sys         hdc
     PAINTSTRUCT ps
     RECT        rct
     
     select case message

     case WM_CREATE
          PlaySoundW (L"c:/windows/media/tada.wav", NULL, SND_FILENAME or SND_ASYNC) 
         
     case WM_PAINT
          hdc = BeginPaint (hwnd, &ps)
         
          GetClientRect (hwnd, &rct)
         
          DrawTextW (hdc, L"Hello World from Oxygen Basic!", -1, &rct,
                     DT_SINGLELINE or DT_CENTER or DT_VCENTER)
         
          EndPaint (hwnd, &ps) 
         
     case WM_DESTROY
          PostQuitMessage (0)
 
     end select
     return DefWindowProcW (hwnd, message, wParam, lParam)
end function

WinMain()

Edit: Modified GetModuleHandle to GetModuleHandleW
« Last Edit: March 06, 2020, 03:32:35 AM by Arnold »

Aurel

  • Guest
Re: wstring vs string
« Reply #7 on: March 05, 2020, 10:12:33 AM »
Quote
I will start programming in Unicode.
:D
heck ..what you mean by that ,convert everything to wW and start programming in german language
or maybe i can in croatian with ššššš
I mean is that unicod really so important , ok if you have in plan to build textual novels