' 下面的代码就可以解决你的问题
dim sta,i%,st$,a$,b$,c$
st = “ax^2+bx+c=0” ' 这里你可以改成从文本框获取方程
sta = split(st,"+")
for i = 0 to ubound(sta)
if instr(sta(i) , "x^2")>0 then
a = trim( left(sta(i),instr(sta(i) , "x^2") -1))
elseif instr(sta(i) , "x")>0 then
b = trim( left(sta(i),instr(sta(i) , "x") -1))
elseif instr(sta(i) , "=")>0 then
c = trim( left(sta(i),instr(sta(i) , "=") -1))
end if
next i
可以实现的
相当于做一个简单的按键精灵,
先通过窗口名字找到这个窗口获取窗口的句柄,然后设置该全窗口的区域,向该窗口发送鼠标信息和键盘信息,就可以模拟点击按钮,选着下拉菜单,以及输入文本的功能。
以下是一个示例:
Private Declare Function FindWindow Lib "user32 " Alias "FindWindowA " (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindow Lib "user32 " (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowText Lib "user32 " Alias "GetWindowTextA " (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Const GW_HWNDNEXT = 2
Private Const GW_HWNDFIRST = 0
Private Declare Function SetWindowText Lib "user32 " Alias "SetWindowTextA " (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Const GW_CHILD = 5
Private 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
Private Declare Function SendMessage Lib "user32 " Alias "SendMessageA " (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SETTEXT = &HC
Private Const BN_CLICKED = 0
Private Const bm_click = &HF5
Private Const WM_SETFOCUS = &H7
Private Sub Command1_Click()
Dim h As Long, hChild As Long, i As Long
Dim str As String
’根据程序窗体的标题名字查找程序的句柄
h = FindWindow(vbNullString, "Test ") '得到程序
SendMessage hChild, WM_SETTEXT, 0, ByVal str ’设置文本
SendMessage h, WM_SETFOCUS, 0, 0 ‘设置焦点
SendMessage hChild, bm_click, 0, 0 '点击按钮
end sub
’获取指定的屏幕坐标上的控件的句柄
Private Sub PriCMouseHook_MouseMove(ByVal Button As Long, ByVal mX As Long, ByVal mY As Long)
'鼠标事件通知
Dim tmpStr As String 255, tmpI As Long, tmpJ As Long
Dim tmpStr2 As String
MeCaption = mX & ":" & mY '显示坐标
tmpI = WindowFromPoint(mX, mY)
labHwndCaption = tmpI '取得句柄
tmpJ = GetClassName(tmpI, tmpStr, Len(tmpStr) + 1) '获取类名
If tmpJ > 0 Then
labClassNameCaption = Mid(tmpStr, 1, tmpJ)
End If
If (Button And vbLeftButton) = 1 And InStr(1, labClassNameCaption, "listview", vbTextCompare) > 0 Then
'在这里判断下类名就不会有那个问题了,呵呵果然是注入的问题对别的类也去注入了:)
txtLVItemText = GetLVItemm(tmpI) '获取选中项内容
End If
End Sub
以上就是关于用VB编写程序全部的内容,包括:用VB编写程序、求用VB编程控制外部程序的可行性和详细思路步骤、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)