CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 1999
    Location
    Florianopolis, SC, Brazil
    Posts
    5

    ReplaceText or FindText

    Does anyone knows how to implement this two API functions? The problem is setting the variable. It's a FINDREPLACE type with lots of settings


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: ReplaceText or FindText

    here is a sample

    option Explicit
    private Type FINDREPLACE
    lStructSize as Long ' size of this struct 0x20
    hwndOwner as Long ' handle to owner's window
    hInstance as Long ' instance handle of.EXE that
    ' contains cust. dlg. template
    flags as Long ' one or more of the FR_??
    lpstrFindWhat as string ' ptr. to search string
    lpstrReplaceWith as string ' ptr. to replace string
    wFindWhatLen as Integer ' size of find buffer
    wReplaceWithLen as Integer ' size of replace buffer
    lCustData as Long ' data passed to hook fn.
    lpfnHook as Long ' ptr. to hook fn. or null
    lpTemplateName as string ' custom template name
    End Type
    private Declare Function FindText Lib "comdlg32.dll" Alias "FindTextA" (pFindreplace as FINDREPLACE) as Long
    private Const FR_DIALOGTERM = &H40

    private Sub Command1_Click()
    Dim fr as FINDREPLACE
    fr.lStructSize = len(fr)
    fr.hwndOwner = me.hWnd
    fr.hInstance = 0
    fr.flags = 0
    fr.lpstrFindWhat = "test"
    fr.lpstrReplaceWith = ""
    fr.wFindWhatLen = 4
    fr.wReplaceWithLen = 0
    fr.lCustData = 0
    fr.lpfnHook = 0
    fr.lpTemplateName = 0
    Call FindText(fr)
    End Sub



    be carefull when copying from the API Viewer.
    The Declaration for FindText is wrong!


  3. #3
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: ReplaceText or FindText

    I've tried playing around with this call in the past and just get a whole tonne of GPF's - same with your example unfortunately. It crashes both in the IDE and when compiled (mind you, my machine is a bit sick at the moment).


    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  4. #4
    Join Date
    May 1999
    Posts
    3,332

    Re: ReplaceText or FindText

    well, all I can say is that I tested this example in NT 4 SP5 and VB 6 SP 3 and it DID work, in the IDE as well as an EXE.


  5. #5
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: ReplaceText or FindText

    I'll give it another try when my PC's feeling better (ie. Re-installed, again).


    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  6. #6
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: ReplaceText or FindText

    The same code, copied directly, Crashes on my machine also.
    Nt 4, Sp3, and Vb 5.0.

    When the "Find" window shows up, if i click find, it invariable crashes.
    If i click "Cancel", apparantly first time it goes thru, and the 'Find' dlg vanishes.
    Then on second try, (bring up the find dlg again), "cancel" click also crashes VB IDE


    RK

  7. #7
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: ReplaceText or FindText

    Crashes on my machine too.

    RK

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

Featured