为什么调用系統的【查找】、【替换】的对话框会出错?

konglord 2003-05-12 01:49:48
FindText函数到底该怎么用? 在查找内容里写了东西然后点击查找下一个就会报内存错误
代码如下:
在表单的声明区中加入以下声明:

'Find/Replace Type Structure
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

'Common Dialog DLL Calls
Private Declare Function FindText Lib "comdlg32.dll" Alias "FindTextA" _
(pFindreplace As FINDREPLACE) As Long

Private Declare Function ReplaceText Lib "comdlg32.dll" Alias "ReplaceTextA" _
(pFindreplace As FINDREPLACE) As Long

'Delcaration of the type structure
Dim frText As FINDREPLACE
在菜单中加入两个选项 查找和替换 分别的对应函数为:

Private Sub cmdFind_Click()
'Call the find text function
FindText frText
End Sub

Private Sub cmdReplace_Click()
'Call the replace text function
ReplaceText frText
End Sub

Private Sub Form_Load()
'Set the Find/Replace Type properties
With frText
.lpstrReplaceWith = "Replace Text"
.lpstrFindWhat = "Find Text"
.wFindWhatLen = 9
.wReplaceWithLen = 12
.hInstance = App.hInstance
.hwndOwner = Me.hWnd
.lStructSize = LenB(frText)
End With
End Sub
...全文
7 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
online 2003-05-12
你看看这是在程序中调用查找的功能的
没问题
Option Explicit
'Find/Replace Type Structure
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

'Common Dialog DLL Calls
Private Declare Function FindText Lib "comdlg32.dll" Alias "FindTextA" _
(pFindreplace As FINDREPLACE) As Long

Private Declare Function ReplaceText Lib "comdlg32.dll" Alias "ReplaceTextA" _
(pFindreplace As FINDREPLACE) As Long

'Delcaration of the type structure
Dim frText As FINDREPLACE

Private Sub cmdFind_Click()
'Call the find text function
FindText frText
End Sub

Private Sub cmdReplace_Click()
'Call the replace text function
ReplaceText frText
End Sub

Private Sub Form_Load()
'Set the Find/Replace Type properties
With frText
.lpstrReplaceWith = "Replace Text"
.lpstrFindWhat = "Find Text"
.wFindWhatLen = 9
.wReplaceWithLen = 12
.hInstance = App.hInstance
.hwndOwner = Me.hWnd
.lStructSize = LenB(frText)
End With
End Sub
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7491

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2003-05-12 01:49
社区公告
暂无公告