AutoHotkey Community

It is currently May 27th, 2012, 8:16 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: March 2nd, 2006, 2:48 pm 
Offline

Joined: February 9th, 2006, 8:36 pm
Posts: 339
I use this function only to get unicode text from clipboard so it doesn't have a wrapper to save clipboard text which would be useful for conversion anywhere in your code. Example is coded using info from eggheads.experts. Extremely fast and reliable. Tested with cyrillic (russian) names only.

Code:
clipAnsi()
{
   StringLen,L,Clipboard
   L:=(L+1)*4
   transform,ca_Clip,unicode ; get clipboard text in UTF-8
   varSetCapacity(ca_WideText,L,0) ; allocate buffer for 2-byte-char string
   varSetCapacity(ca_AnsiText,L,0) ; alloc for resulting ansi string
   ; Convert UTF-8 to UTF-16.   CP_UTF8=65001
   if dllCall("MultiByteToWideChar",uint,65001, uint,0, str,ca_Clip
              , unit,-1, str,ca_WideText, uint,L/2)
      dllCall("WideCharToMultiByte",uint,0, uint,0, str,ca_WideText
              , unit,-1, str,ca_AnsiText, uint,L/2, uint,0, uint,0)
      ; Convert UTF-16 to ANSI.  CP_ACP=0
   return ca_AnsiText
}


Another function is to set clipboard in unicode (through UTF-8 conversion) to an ansi string containing non-western characters from current system codepage.
Code:
clipSetUnicode(cu_AnsiText) ; copy ansi string to clipboard in unicode mode
{
   StringLen,L,cu_AnsiText
   L:=(L+1)*4
   varSetCapacity(cu_WideText,L,0)
   varSetCapacity(cu_UTFtext,L,0)
   ; ANSI to UTF-16.   CP_ACP=0
   if dllCall("MultiByteToWideChar",uint,0, uint,0, str,cu_AnsiText
              , uint,-1, str,cu_WideText, uint,L/2)
      dllCall("WideCharToMultiByte",uint,65001, uint,0, str,cu_WideText
              , uint,-1, str,cu_UTFtext, uint,L/2, uint,0, uint,0)
      ; Convert UTF-16 to UTF-8.  CP_UTF8=65001
   transform,clipboard,unicode,%cu_UTFtext%
}


Last edited by wOxxOm on January 1st, 2008, 7:16 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject: thanks for sharing
PostPosted: March 2nd, 2006, 3:00 pm 
Offline

Joined: August 15th, 2005, 2:57 pm
Posts: 57
Thanks! I might have a use for this only in reverse. I have clipboard contents in ASCII and need to change to Unicode.

Thanks for sharing!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Aravind, Google Feedfetcher, Stigg and 12 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group