>PUBLIC oform1 > >oform1=NEWOBJECT("form1") >oform1.Show >RETURN > > > ************************************************** >*-- Form: form1 (d:\project9\coreframe\core\yy.scx) >*-- ParentClass: form >*-- BaseClass: form >*-- Time Stamp: 12/28/11 04:35:02 PM >* >DEFINE CLASS form1 AS form > > > Top = 0 > Left = 0 > Height = 390 > Width = 551 > DoCreate = .T. > Caption = "Form1" > Name = "Form1" > > > ADD OBJECT text1 AS olecontrol WITH ; > Top = 72, ; > Left = 12, ; > Height = 93, ; > Width = 372, ; > Name = "text1" > > > ADD OBJECT command1 AS commandbutton WITH ; > Top = 12, ; > Left = 48, ; > Height = 25, ; > Width = 97, ; > Caption = "Assign value", ; > Name = "Command1" > > > ADD OBJECT command2 AS commandbutton WITH ; > Top = 12, ; > Left = 192, ; > Height = 25, ; > Width = 97, ; > Caption = "Get value back", ; > Name = "Command2" > > > PROCEDURE Load > CREATE CURSOR csrTest (cVal blob, nVal blob) > > INSERT INTO csrTest ; > VALUES; > (STRCONV( "Russian",5),; > STRCONV('20044304410441043A0438043904',16) ) > ENDPROC > > > PROCEDURE command1.Click > > =comprop(this.Parent.Text1, 'utf8', 1) > > this.Parent.Text1.Text = csrTest.nVal > ENDPROC > > > PROCEDURE command2.Click > local utf8, utf16Out > utf8 =m.this.Parent.text1.Text > > > = StringUtf8ToUTF16(@m.utf16Out, m.utf8) > > acti screen > ?strconv(csrTest.nval, 15) > ?strconv(utf16Out, 15) > > ?'Same value ', csrTest.nval == utf16Out > assert .f. > ENDPROC > > >ENDDEFINE >* >*-- EndDefine: form1 >************************************************** >>
>#include "Foxpro.h" >#define true .t. >#define false .f. > >*_______________________________________________________________________________ >function StringToUTF8(utf8Out, stringIn, codepageIn) > > local success > success = true > > do case > case !m.success > > case !StringToUTF16(@m.utf8Out, m.stringIn, m.codepageIn) > assert false > success = false > > case !StringUTF16ToUTF8(@m.utf8Out, m.utf8Out) > assert false > success = false > > endcase > > return m.success > >endfunc >*_______________________________________________________________________________ > > >*_______________________________________________________________________________ >*_______________________________________________________________________________ >#define CP_ACP 0 >#define CP_MACCP 2 >#define CP_OEMCP 1 >#define CP_SYMBOL 42 >#define CP_THREAD_ACP 3 >#define CP_UTF7 65000 >#define CP_UTF8 65001 >#define MB_PRECOMPOSED 0x1 >#define MB_COMPOSITE 0x2 >#define MB_USEGLYPHCHARS 0x4 >#define MB_ERR_INVALID_CHARS 0x8 > >#define WC_DEFAULTCHAR 0x00000040 >#define WC_ERR_INVALID_CHARS 0x00000080 >#define WC_NO_BEST_FIT_CHARS 0x00000400 >*_______________________________________________________________________________ >function StringToUTF16(utf16Out, stringIn, codepageIn) > > local success > success = true > > do case > case !m.success > > case empty(len(m.stringIn)) > utf16Out = '' > > otherwise > local lpWideCharStr, result > lpWideCharStr = space(len(m.stringIn)*2) > > result = MultiByteToWideChar( ; > evl(m.codepageIn, cpcurrent()), ; > MB_ERR_INVALID_CHARS, ; > @m.stringIn, ; > len(m.stringIn), ; > @m.lpWideCharStr, ; > len(m.lpWideCharStr) ; > ) > > do case > case !m.success > > case empty(m.result) > assert false > success = false > > otherwise > utf16Out = left(m.lpWideCharStr, m.result * 2) > > endcase > > endcase > > return m.success > > >endfunc >*_______________________________________________________________________________ >function StringUTF16ToUTF8(utf8Out, utf16In) > > local success > success = true > > do case > case !m.success > > case empty(len(m.utf16In)) > utf8Out = '' > > otherwise > > local lpMultiByteStr, lpUsedDefaultChar, result > lpMultiByteStr = space(len(m.utf16In) * 2) > lpUsedDefaultChar = 0 > > result = WideCharToMultiByte( ; > CP_UTF8, ; > WC_ERR_INVALID_CHARS, ; > @m.utf16In, ; > len(m.utf16In)/2, ; > @m.lpMultiByteStr, ; > len(m.lpMultiByteStr), ; > null, ; > @m.lpUsedDefaultChar ; > ) > > do case > case !m.success > > case empty(m.result) > assert false > success = false > > > otherwise > utf8Out = left(m.lpMultiByteStr, m.result) > > endcase > endcase > > return m.success > > > >endfunc >*_______________________________________________________________________________ >function StringUTF8ToUTF16(utf16Out, uft8In) > > return StringToUTF16(@m.utf16Out, uft8In, CP_UTF8) > >endfunc >*_______________________________________________________________________________ > >function MultiByteToWideChar > lparameters codepage, ; > dwFlags, ; > lpMultiByteStr, ; > cbMultiByte, ; > lpWideCharStr, ; > cchWideChar > > local success > success = true > > local result > > do case > case !m.success > > otherwise > try > declare integer MultiByteToWideChar in Kernel32.dll ; > long codepage, ; > long dwFlags, ; > string@ lpMultiByteStr, ; > integer cbMultiByte, ; > string@ lpWideCharStr, ; > integer cchWideChar > > result = MultiByteToWideChar( ; > m.codepage, ; > m.dwFlags, ; > @m.lpMultiByteStr, ; > m.cbMultiByte, ; > @m.lpWideCharStr, ; > m.cchWideChar ; > ) > catch > assert false > success = false > > endtry > endcase > > return iif(m.success, m.result, 0) > >endfunc >*_______________________________________________________________________________ >function WideCharToMultiByte > lparameters codepage, ; > dwFlags, ; > lpWideCharStr, ; > cchWideChar, ; > lpMultiByteStr, ; > cbMultiByte, ; > lpDefaultChar, ; > lpUsedDefaultChar > > local success > success = true > > local result > > do case > case !m.success > > otherwise > try > declare integer WideCharToMultiByte in Kernel32.dll ; > long codepage, ; > long dwFlags, ; > string@ lpWideCharStr, ; > integer cchWideChar, ; > string@ lpMultiByteStr, ; > integer cbMultiByte, ; > string lpDefaultChar, ; > integer @lpUsedDefaultChar > > result = WideCharToMultiByte ( ; > m.codepage, ; > m.dwFlags, ; > @m.lpWideCharStr, ; > m.cchWideChar, ; > @m.lpMultiByteStr, ; > m.cbMultiByte, ; > m.lpDefaultChar, ; > @m.lpUsedDefaultChar; > ) > catch > assert false > success = false > > endtry > endcase > > return iif(m.success, m.result, 0) > >endfunc >*_______________________________________________________________________________ >