bug of len() or winApi for chinese

Just starting out? Need help? Post your questions and find answers here.
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

bug of len() or winApi for chinese

Post by gurj »

pb6.1;winxp

Code: Select all

Procedure SelectEditorLine(EditorID.I, LineNumber.I)
StartOfLine = SendMessage_(GadgetID(EditorID), #EM_LINEINDEX, LineNumber, 0)
Selection.CHARRANGE\cpMin = StartOfLine
Selection.CHARRANGE\cpMax = StartOfLine + Len(GetGadgetItemText(EditorID, LineNumber)) ;+ 1;1是换行符
SendMessage_(GadgetID(EditorID), #EM_EXSETSEL, 0, @Selection)
EndOfLine=Selection.CHARRANGE\cpMax
EndProcedure
OpenWindow(0,0,0,300,200,"Edit Control VCenter",#WS_SYSMENU | #WS_CAPTION | 1)
EditorGadget(0,0,30,300,180,#ES_MULTILINE|#ES_CENTER )
AddGadgetItem(0,-1,"[02:08.92][00:45.07]我醉 一片朦胧zzz")
AddGadgetItem(0,-1,"[00:02.85]剑刀如梦-董贞zzz")

Debug Len("[02:08.92][00:45.07]我醉 一片朦胧zzz")
Debug Len("[00:02.85]剑刀如梦-董贞zzz")
SelectEditorLine(0,1)
  Repeat 
   EventID.l = WaitWindowEvent()
   Select EventID
   Case #PB_Event_CloseWindow
    Quit = 1     
    EndSelect

   Until Quit = 1

my pb for chinese:
http://ataorj.ys168.com
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: bug of len() or winApi for chinese

Post by IdeasVacuum »

Are you using the Unicode Compiler option?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Puffolino
User
User
Posts: 49
Joined: Thu Jan 05, 2012 12:27 am

Re: bug of len() or winApi for chinese

Post by Puffolino »

Are you using the Version 6.1 of PureBasic? :shock:
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: bug of len() or winApi for chinese

Post by Shield »

Len reports the correct length here after enabling Unicode support,
however I found a bug in the IDE. Will report it.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: bug of len() or winApi for chinese

Post by gurj »

sorry pb4.61.

ok:Debug Len("[00:02.85]剑刀如梦-董贞zzz")
no:SelectEditorLine(0,1)
Unicode ok:SelectEditorLine(0,1)
Unicode but disorder

I use:
ok:

Code: Select all

Procedure SelectEditorLine(EditorID,LineNumber.I)
 StartOfLine = SendMessage_(GadgetID(EditorID), #EM_LINEINDEX, LineNumber, 0)
 Selection.CHARRANGE\cpMin = StartOfLine
 StartOfnextLine = SendMessage_(GadgetID(EditorID), #EM_LINEINDEX, LineNumber+1, 0)
 Selection.CHARRANGE\cpMax = StartOfnextLine-1 
 SendMessage_(GadgetID(EditorID), #EM_EXSETSEL, -1, @Selection)
 EndOfLine=Selection.CHARRANGE\cpMax
EndProcedure
my pb for chinese:
http://ataorj.ys168.com
Post Reply