Results 1 to 5 of 5

Thread: Clipboard.GetText has no support for unicode!

  1. #1

    Thread Starter
    Lively Member Mahdi Jazini's Avatar
    Join Date
    Feb 2014
    Location
    Iran / Tehran
    Posts
    89

    Clipboard.GetText has no support for unicode!

    Hello

    1) In Clipboard: ی

    2) Clipboard.GetText

    3) Returns: ي

    Why the Clipboard.GetText is unable to return ی

    Thank you

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,734

    Re: Clipboard.GetText has no support for unicode!

    No access to VB6 right now, but check this:
    https://msdn.microsoft.com/en-us/lib.../ff192913.aspx

  3. #3

    Thread Starter
    Lively Member Mahdi Jazini's Avatar
    Join Date
    Feb 2014
    Location
    Iran / Tehran
    Posts
    89

    Re: Clipboard.GetText has no support for unicode!

    Quote Originally Posted by Arnoutdv View Post
    No access to VB6 right now, but check this:
    https://msdn.microsoft.com/en-us/lib.../ff192913.aspx
    Actually, your link couldn't help me because i'm using VB6 but you helped me to remember API

    Finally i have found this link for VB6 and it worked very welllllll in VB6

    Link: http://www.devx.com/vb2themax/Tip/18632

    Contents:

    Code:
    Private Const WM_CUT = &H300
    Private Const WM_COPY = &H301
    Private Const WM_PASTE = &H302
    Private Const WM_CLEAR = &H303
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _
        hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
        lParam As Any) As Long
    
    ' Copy the contents of a control into the Clipboard
    Sub ControlCopy(ByVal hWnd As Long)
        SendMessage hWnd, WM_COPY, 0, ByVal 0&
    End Sub
    
    ' Cut the contents of a control into the Clipboard
    Sub ControlCut(ByVal hWnd As Long)
        SendMessage hWnd, WM_CUT, 0, ByVal 0&
    End Sub
    
    ' Paste the contents of the Clipboard into a control
    Sub ControlPaste(ByVal hWnd As Long)
        SendMessage hWnd, WM_PASTE, 0, ByVal 0&
    End Sub
    
    ' Delete the selected contents of a control
    Sub ControlDelete(ByVal hWnd As Long)
        SendMessage hWnd, WM_CLEAR, 0, ByVal 0&
    End Sub
    It supports Unicode

    Thank you again God bless you Insha-Allah

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,734

    Re: Clipboard.GetText has no support for unicode!

    Glad you found a solution, but the code in the link I provided can be used in both VBA and VB6.
    Code:
    Option Explicit
    Private Declare Function OpenClipboard Lib "user32.dll" (ByVal hWnd As Long) As Long
    Private Declare Function EmptyClipboard Lib "user32.dll" () As Long
    Private Declare Function CloseClipboard Lib "user32.dll" () As Long
    Private Declare Function IsClipboardFormatAvailable Lib "user32.dll" (ByVal wFormat As Long) As Long
    Private Declare Function GetClipboardData Lib "user32.dll" (ByVal wFormat As Long) As Long
    Private Declare Function SetClipboardData Lib "user32.dll" (ByVal wFormat As Long, ByVal hMem As Long) As Long
    Private Declare Function GlobalAlloc Lib "kernel32.dll" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
    Private Declare Function GlobalLock Lib "kernel32.dll" (ByVal hMem As Long) As Long
    Private Declare Function GlobalUnlock Lib "kernel32.dll" (ByVal hMem As Long) As Long
    Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
    Private Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyW" (ByVal lpString1 As Long, ByVal lpString2 As Long) As Long
    
    Public Sub SetClipboard(sUniText As String)
        Dim iStrPtr As Long
        Dim iLen As Long
        Dim iLock As Long
        Const GMEM_MOVEABLE As Long = &H2
        Const GMEM_ZEROINIT As Long = &H40
        Const CF_UNICODETEXT As Long = &HD
        OpenClipboard 0&
        EmptyClipboard
        iLen = LenB(sUniText) + 2&
        iStrPtr = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, iLen)
        iLock = GlobalLock(iStrPtr)
        lstrcpy iLock, StrPtr(sUniText)
        GlobalUnlock iStrPtr
        SetClipboardData CF_UNICODETEXT, iStrPtr
        CloseClipboard
    End Sub
    
    Public Function GetClipboard() As String
        Dim iStrPtr As Long
        Dim iLen As Long
        Dim iLock As Long
        Dim sUniText As String
        Const CF_UNICODETEXT As Long = 13&
        OpenClipboard 0&
        If IsClipboardFormatAvailable(CF_UNICODETEXT) Then
            iStrPtr = GetClipboardData(CF_UNICODETEXT)
            If iStrPtr Then
                iLock = GlobalLock(iStrPtr)
                iLen = GlobalSize(iStrPtr)
                sUniText = String$(iLen \ 2& - 1&, vbNullChar)
                lstrcpy StrPtr(sUniText), iLock
                GlobalUnlock iStrPtr
            End If
            GetClipboard = sUniText
        End If
        CloseClipboard
    End Function

  5. #5

    Thread Starter
    Lively Member Mahdi Jazini's Avatar
    Join Date
    Feb 2014
    Location
    Iran / Tehran
    Posts
    89

    Re: Clipboard.GetText has no support for unicode!

    Quote Originally Posted by Arnoutdv View Post
    Glad you found a solution, but the code in the link I provided can be used in both VBA and VB6.
    Code:
    Option Explicit
    Private Declare Function OpenClipboard Lib "user32.dll" (ByVal hWnd As Long) As Long
    Private Declare Function EmptyClipboard Lib "user32.dll" () As Long
    Private Declare Function CloseClipboard Lib "user32.dll" () As Long
    Private Declare Function IsClipboardFormatAvailable Lib "user32.dll" (ByVal wFormat As Long) As Long
    Private Declare Function GetClipboardData Lib "user32.dll" (ByVal wFormat As Long) As Long
    Private Declare Function SetClipboardData Lib "user32.dll" (ByVal wFormat As Long, ByVal hMem As Long) As Long
    Private Declare Function GlobalAlloc Lib "kernel32.dll" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
    Private Declare Function GlobalLock Lib "kernel32.dll" (ByVal hMem As Long) As Long
    Private Declare Function GlobalUnlock Lib "kernel32.dll" (ByVal hMem As Long) As Long
    Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
    Private Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyW" (ByVal lpString1 As Long, ByVal lpString2 As Long) As Long
    
    Public Sub SetClipboard(sUniText As String)
        Dim iStrPtr As Long
        Dim iLen As Long
        Dim iLock As Long
        Const GMEM_MOVEABLE As Long = &H2
        Const GMEM_ZEROINIT As Long = &H40
        Const CF_UNICODETEXT As Long = &HD
        OpenClipboard 0&
        EmptyClipboard
        iLen = LenB(sUniText) + 2&
        iStrPtr = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, iLen)
        iLock = GlobalLock(iStrPtr)
        lstrcpy iLock, StrPtr(sUniText)
        GlobalUnlock iStrPtr
        SetClipboardData CF_UNICODETEXT, iStrPtr
        CloseClipboard
    End Sub
    
    Public Function GetClipboard() As String
        Dim iStrPtr As Long
        Dim iLen As Long
        Dim iLock As Long
        Dim sUniText As String
        Const CF_UNICODETEXT As Long = 13&
        OpenClipboard 0&
        If IsClipboardFormatAvailable(CF_UNICODETEXT) Then
            iStrPtr = GetClipboardData(CF_UNICODETEXT)
            If iStrPtr Then
                iLock = GlobalLock(iStrPtr)
                iLen = GlobalSize(iStrPtr)
                sUniText = String$(iLen \ 2& - 1&, vbNullChar)
                lstrcpy StrPtr(sUniText), iLock
                GlobalUnlock iStrPtr
            End If
            GetClipboard = sUniText
        End If
        CloseClipboard
    End Function
    I think it's for VB 2013

    Now i have tested it

    It worked very well and supports Unicode

    Code:
    Private Sub Form_Load()
        On Error Resume Next
        
        TXT_FINAL.Text = GetClipboard
        
        Exit Sub
        
        RichTextBox1.LoadFile App.Path & "\data.rtf", RtfLoadSaveFormatRTF
        TXT_FINAL.Text = RichTextBox1.Text
    End Sub
    Thank you very much for your time God bless you

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width