窗体和模块代码如下,直接copy到VB6环境下即可,我用VB6环境在xp和2000下调试时均没有问题,但是生成EXE可执行文件在2000下运行报错是怎么回事?
窗体代码:
Private Sub Command1_Click()
Dim hThread, lpThreadID As Long
Dim a As String
g_bDone = False
g_strTitle = "Set Option"
hThread = CreateThread(ByVal 0&, ByVal 0&, AddressOf HookInputBoxThread, ByVal 0&, 0, lpThreadID)
a = Trim(InputBox("Please input the correct Password!" + vbCrLf + "Operator can not close it!", g_strTitle))
If a <> "" Then
If a = "bmpadmin" Then
'***************************
isSetting = True
cmdSend.Visible = False
CmdClr.Visible = False frmnetSend.Height = FrmSettingHeight
SettingFrame.Top = 480
SettingFrame.Visible = True
BgBottom.Top = 2280
back.Visible = True
'***************************
Else
MsgBox "The Password isn't correct!", 0 + 16, "Warning"
'Cancel = 1
End If
Else
' Cancel = 1
End If
End Sub
模块代码如下:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetDlgItem Lib "user32" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long
Public Declare Function CreateThread Lib "kernel32" (ByVal lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Public Declare Function SetFocus Lib "user32.dll" (ByVal hwnd As Long) As Long Public Const EM_SETPASSWORDCHAR = &HCC
Public Const HWND_TOPMOST& = -1
Public Const SWP_NOSIZE& = &H1
Public Const SWP_NOMOVE& = &H2 Public g_bDone As Boolean
Public g_strTitle As String Public Sub HookInputBoxThread()
Do Until g_bDone
Dim h As Long, hText As Long
h = FindWindow("#32770", g_strTitle)
If h <> 0 Then
hText = GetDlgItem(h, &H1324)
If hText <> 0 Then
SendMessage hText, EM_SETPASSWORDCHAR, Asc("*"), 0
g_bDone = True
End If
End If
Loop
End Sub
补充:
1,在其它2000系统一样有问题,不知道是不是API的问题?
2,没有提示任何ocx和dll文件缺少,有提示的话早就解决了.
3,我没有打包操作,我想知道问题的根本
4,提示信息:"工程1.exe has generated errors and will be closed by Windows.You will need to restart the program.
An error log is being created."
窗体代码:
Private Sub Command1_Click()
Dim hThread, lpThreadID As Long
Dim a As String
g_bDone = False
g_strTitle = "Set Option"
hThread = CreateThread(ByVal 0&, ByVal 0&, AddressOf HookInputBoxThread, ByVal 0&, 0, lpThreadID)
a = Trim(InputBox("Please input the correct Password!" + vbCrLf + "Operator can not close it!", g_strTitle))
If a <> "" Then
If a = "bmpadmin" Then
'***************************
isSetting = True
cmdSend.Visible = False
CmdClr.Visible = False frmnetSend.Height = FrmSettingHeight
SettingFrame.Top = 480
SettingFrame.Visible = True
BgBottom.Top = 2280
back.Visible = True
'***************************
Else
MsgBox "The Password isn't correct!", 0 + 16, "Warning"
'Cancel = 1
End If
Else
' Cancel = 1
End If
End Sub
模块代码如下:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetDlgItem Lib "user32" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long
Public Declare Function CreateThread Lib "kernel32" (ByVal lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Public Declare Function SetFocus Lib "user32.dll" (ByVal hwnd As Long) As Long Public Const EM_SETPASSWORDCHAR = &HCC
Public Const HWND_TOPMOST& = -1
Public Const SWP_NOSIZE& = &H1
Public Const SWP_NOMOVE& = &H2 Public g_bDone As Boolean
Public g_strTitle As String Public Sub HookInputBoxThread()
Do Until g_bDone
Dim h As Long, hText As Long
h = FindWindow("#32770", g_strTitle)
If h <> 0 Then
hText = GetDlgItem(h, &H1324)
If hText <> 0 Then
SendMessage hText, EM_SETPASSWORDCHAR, Asc("*"), 0
g_bDone = True
End If
End If
Loop
End Sub
补充:
1,在其它2000系统一样有问题,不知道是不是API的问题?
2,没有提示任何ocx和dll文件缺少,有提示的话早就解决了.
3,我没有打包操作,我想知道问题的根本
4,提示信息:"工程1.exe has generated errors and will be closed by Windows.You will need to restart the program.
An error log is being created."
分给我吧,多线程就别想了
你这个代码,只要把vb运行库的 __vbaSetsystemerror 这个apihook 毁掉就能正常运行了i=getprocaddress(getmodulehandle("msvbvm60"),"__vbaSetSystemError")
writeprocessmemory -1,byval i,&hc3,1,0应该就可以了
工程1.exe发生错误,将被Windows关闭,你需要重新启动程序,一个错误日志正在建立.
在工程所在目录下查找错误日志,看错误日志怎么说.
i = GetProcAddress(GetModuleHandle("msvbvm60"), "__vbaSetSystemError") '<> 0
WriteProcessMemory -1, ByVal i, &HC3, 1, 0 '这个忘了...
hThread = CreateThread(ByVal 0&, ByVal 0&, AddressOf HookInputBoxThread, ByVal 0&, 0, lpThreadId)
If hThread Then MsgBox "线程创建成功,线程句柄: " & hThread & vbCrLf & vbCrLf & " 线程 ID: " & lpThreadId如果有错,检查一下api调用的返回值都对不对
注释的东西就是那个api应该返回的值,如果执行成功的话
还有 HookInputBoxThread() 不应该使用任何全局变量,要通过 lpParameter 传递参数。
控制对话框不需要多线程,CBT Hook 就可以了,参考:
http://vbworld.sxnw.gov.cn/articles/openfile.asp?kind=api&id=67&filename=htmapi67.htm
如果上面不是好的方法,那么有没有除了画个类似inputbox窗体以外的其他方法可以实现inputbox输入时显示“×”米字。请各位赐教?
以上两句都问题,哎
hThread = CreateThread(ByVal 0&, ByVal 0&, AddressOf HookInputBoxThread, ByVal 0&, 0, lpThreadID) 这在IDE里面是没有问题的,但成了PE文件后,执行就有问题,因为VB6.0的多线程是不安全的,很正常LZ建议楼主如果一定要用多线程,用VC++写一个,然后VB调