English 中文(简体)
检测单编码支持文体改动
原标题:Detect Clipboard text change with unicode support in vb.net

iam 采用以下代码核对纸板的文字改动,但其不支持像GE PE 这样的单编码字典。

#Region " Definitions "
     Constants for API Calls...
    Private Const WM_DRAWCLIPBOARD As Integer = &H308
    Private Const WM_CHANGECBCHAIN As Integer = &H30D
     Handle for next clipboard viewer...
    Private mNextClipBoardViewerHWnd As IntPtr
     API declarations...
    Declare Auto Function SetClipboardViewer Lib "user32" (ByVal HWnd As IntPtr) As IntPtr
    Declare Auto Function ChangeClipboardChain Lib "user32" (ByVal HWnd As IntPtr, ByVal HWndNext As IntPtr) As Boolean
    Declare Auto Function SendMessage Lib "User32" (ByVal HWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Long
#End Region

#Region " Contructor "
#End Region

#Region " Message Process "
     Override WndProc to get messages...
    Protected Overrides Sub WndProc(ByRef m As Message)
        Dim iData As IDataObject = New DataObject()
        iData = Clipboard.GetDataObject()
        Select Case m.Msg

            Case Is = WM_DRAWCLIPBOARD  The clipboard has changed...
                 ##########################################################################
                  Process Clipboard Here :)........................
                 ##########################################################################
                MsgBox(CStr(iData.GetData(DataFormats.Text)))
                SendMessage(mNextClipBoardViewerHWnd, m.Msg, m.WParam, m.LParam)

            Case Is = WM_CHANGECBCHAIN  Another clipboard viewer has removed itself...
                If m.WParam = CType(mNextClipBoardViewerHWnd, IntPtr) Then
                    mNextClipBoardViewerHWnd = m.LParam
                Else
                    SendMessage(mNextClipBoardViewerHWnd, m.Msg, m.WParam, m.LParam)
                End If
        End Select

        MyBase.WndProc(m)
    End Sub
#End Region

#Region " Dispose "
     Form overrides dispose to clean up...
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
             Set the next clipboard viewer back to the original... 
            ChangeClipboardChain(Me.Handle, mNextClipBoardViewerHWnd)
            MyBase.Dispose(disposing)
        End If
    End Sub
最佳回答

你的代码无法发现对统法协会编码案文的改动,因为它没有考虑统法协会编码格式。 Ansi和Unicode使用不同的单板格式,同时可以在纸板上共存。 DataFormats。 案文仅支持 Ansi 案文。 documentation 甚至这样说:

具体列明标准ANSI文本格式

You need to look for DataFormats.UnicodeText instead of, or in addition to, DataFormats.Text, eg:

Protected Overrides Sub WndProc(ByRef m As Message) 
    Select Case m.Msg 
        Case Is = WM_DRAWCLIPBOARD  The clipboard has changed... 
             ########################################################################## 
              Process Clipboard Here :)........................ 
             ########################################################################## 
            Dim iData As IDataObject = Clipboard.GetDataObject() 
            Dim oData as Object = iData.GetData(DataFormats.Text)
            If oData IsNot Nothing
              MsgBox(CStr(oData), MsgBoxStyle.OKOnly, "Ansi") 
            End If
            oData = iData.GetData(DataFormats.UnicodeText)
            If oData IsNot Nothing
              MsgBox(CStr(oData), MsgBoxStyle.OKOnly, "Unicode") 
            End If

        Case Is = WM_CHANGECBCHAIN  Another clipboard viewer has removed itself... 
            If m.WParam = CType(mNextClipBoardViewerHWnd, IntPtr) Then 
                mNextClipBoardViewerHWnd = m.LParam 
            Else 
                SendMessage(mNextClipBoardViewerHWnd, m.Msg, m.WParam, m.LParam) 
            End If 
    End Select 

    MyBase.WndProc(m) 
End Sub 
问题回答

暂无回答




相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签