Sendkeys 和 Sendmessage 使用技巧一例
2007-02-02 16:41
357 查看
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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
Function sqrx(ByVal x As Double) As String '计算平方根(比VB DOUBLE 类型精度高)
Dim temp As String, i As Long, j As Long
Shell "Calc.EXE", vbMinimizedNoFocus '运行计算器
temp = x & "y0.5="
For i = 1 To Len(temp)
SendKeys Mid(temp, i, 1), True '向计算器顺序发送按键消息X (X^Y) 0.5=
Next
temp = String(64, Chr(0))
i = FindWindow(vbNullString, "计算器") '窗口句柄
j = FindWindowEx(i, ByVal 0&, "Edit", vbNullString) '编辑框句柄
SendMessage j, &HD, Len(temp), ByVal temp '发送编辑框文本至temp
SendKeys "%{F4}", True '调用ALT+F4关闭计算器窗口
sqrx = temp
End Function
Private Sub Command1_Click()
Dim i As Integer
For i = 17 To 24
Debug.Print "sqrx(" & i & ")=" & sqrx(i)
Next
End Sub
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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
Function sqrx(ByVal x As Double) As String '计算平方根(比VB DOUBLE 类型精度高)
Dim temp As String, i As Long, j As Long
Shell "Calc.EXE", vbMinimizedNoFocus '运行计算器
temp = x & "y0.5="
For i = 1 To Len(temp)
SendKeys Mid(temp, i, 1), True '向计算器顺序发送按键消息X (X^Y) 0.5=
Next
temp = String(64, Chr(0))
i = FindWindow(vbNullString, "计算器") '窗口句柄
j = FindWindowEx(i, ByVal 0&, "Edit", vbNullString) '编辑框句柄
SendMessage j, &HD, Len(temp), ByVal temp '发送编辑框文本至temp
SendKeys "%{F4}", True '调用ALT+F4关闭计算器窗口
sqrx = temp
End Function
Private Sub Command1_Click()
Dim i As Integer
For i = 17 To 24
Debug.Print "sqrx(" & i & ")=" & sqrx(i)
Next
End Sub
相关文章推荐
- Sendkeys 和 Sendmessage 使用技巧一例
- Sendkeys 和 Sendmessage 使用技巧一例 选择自 northwolves 的 Blog
- Sendkeys 和 Sendmessage 使用技巧一例
- SendMessage使用技巧
- Delphi中SendMessage使用技巧
- MSFlexGrid使用技巧一例
- INSERT语法使用技巧一例
- Delphi中SendMessage使用技巧
- 【Linux使用技巧】重定向不成功一例的解决
- Delphi中SendMessage使用技巧
- MSFlexGrid使用技巧一例
- INSERT语法使用技巧一例
- Delphi中SendMessage使用技巧
- linux 技巧:使用 screen 管理你的远程会话
- Google 使用技巧
- eclipse快捷键以及使用技巧大全
- Office2007系列~Outlook使用技巧(转)
- 《DB 查询分析器》使用技巧之(六)
- HttpWatch工具简介及使用技巧
- eclipse快捷键以及使用技巧大全