Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27212

Using FinText API from VB.Net

$
0
0
I would like some assistance with calling/setting up FindText from VB.Net. I am getting CDERR_STRUCTSIZE from the following code (it lives in a form with various controls/components namely a backgroundworker which I haven't removed from the code and a menu which can easily be removed, I have stripped everything else out):

Code:

Private Delegate Function GetHandleDelegate() As IntPtr
    <DllImport("comdlg32.dll", SetLastError:=True)> _


   

   
    Private Structure FINDREPLACE
        Public lStructSize As Integer
        Public hwndOwner As IntPtr
        Public hInstance As IntPtr
        Public Flags As Integer
        Public lpStrFindWhat As String
        Public lpstrReplaceWith As String
        Public wFindWhatLen As Integer
        Public wReplaceWithLen As Integer
        Public LPARAM As Integer
        Public lpfnHook As IntPtr
        Public lpTemplateName As String
    End Structure

    Private Declare Auto Function FindText Lib "comdlg32" (ByRef lpfr As FINDREPLACE) As IntPtr
    Private Shared Function CommDlgExtendedError() As Integer
    End Function

    Private Const FR_HIDEWHOLEWORD As Long = &H10000

   
    'Being called from a menu but could be in a button for testing
    Private Sub FindToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles FindToolStripMenuItem.Click
        If Not Me.BackgroundWorker.IsBusy Then
            Me.BackgroundWorker.RunWorkerAsync("Find")
        End If
    End Sub

    Private Sub ShowFindDialog()
        Dim fr As FINDREPLACE
        Dim GetHandledg As GetHandleDelegate
        GetHandledg = AddressOf GetHandle

        With fr
            .hwndOwner = Me.Invoke(GetHandledg)
            .Flags = .Flags Or FR_HIDEWHOLEWORD
            .lpfnHook = vbNull

        End With

        fr.lStructSize = Marshal.SizeOf(fr)
        MsgBox(fr.lStructSize)
        FindText(fr)
        MsgBox(CommDlgExtendedError)
    End Sub


    Private Sub BackgroundWorker_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker.DoWork
        'If e.Argument = "Find" Then

        ShowFindDialog()


        'End If
    End Sub

    Private Function GetHandle() As IntPtr
        GetHandle = Me.Handle
    End Function

Any help would be greatly apreciated.

Viewing all articles
Browse latest Browse all 27212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>