Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function GetFocus Lib "user32" () As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Sub test()
Dim k As Integer
For k = 1 To 6
AppActivate "无标题 - 记事本"
Sleep 1000
SendKeys Chr(64 + k)
SendKeys "{Enter}"
Next
wp.showCmd = 3 '3是最大化状态
Window = SetWindowPlacement(vbNullString, "无标题 - 记事本")
Status = SetWindowPlacement(Window, wp)
Window = SetForegroundWindow(Window)End Sub
程序在这里出了问题
Status = SetWindowPlacement(Window, wp)
Window = SetForegroundWindow(Window)
也就是Private Declare Function 这两个程序如何写.谢谢.
Private Declare Function GetFocus Lib "user32" () As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Sub test()
Dim k As Integer
For k = 1 To 6
AppActivate "无标题 - 记事本"
Sleep 1000
SendKeys Chr(64 + k)
SendKeys "{Enter}"
Next
wp.showCmd = 3 '3是最大化状态
Window = SetWindowPlacement(vbNullString, "无标题 - 记事本")
Status = SetWindowPlacement(Window, wp)
Window = SetForegroundWindow(Window)End Sub
程序在这里出了问题
Status = SetWindowPlacement(Window, wp)
Window = SetForegroundWindow(Window)
也就是Private Declare Function 这两个程序如何写.谢谢.
2 Google下Private Declare Function SetWindowPlacement Lib "user32" Alias "SetWindowPlacement" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long private Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End TypePrivate Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Long
看看下面API定义:
Private Declare Function SetWindowPlacement Lib "user32.dll" (ByVal hwnd As Long, ByRef lpwndpl As WINDOWPLACEMENT) As Long
http://topic.csdn.net/u/20090701/20/9cf5607f-b41d-49c0-b401-742c92dd7e3d.html
目的:
激活另一个程序,控制键盘向其做输出。在以下的代码示例中,用记事本来做例子。 代码:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub test()
Dim k As Integer
For k = 1 To 6
AppActivate "无标题 - 记事本"
Sleep 1000
SendKeys Chr(64 + k)
SendKeys "{Enter}"
Next End Sub 以下代码的问题:
在WIN7(VISTA) + Office 2007中,如果记事本窗口是最小化的,则循环体中的第一个字母输不进去,其它可以进去。如果记事本窗口不是最小化的,则所有的字母都可以正常进去。
在XP Professional + Office 2003中,所有的字母都会输在VB编辑器里,而不是记事本里。 请问如何能让代码把所有的字符都输进记事本呢?实际使用中,会通过这种方式操作一个比较复杂的专业软件。
另:我尝试过调用操作系统API,获取记事本窗口的句柄,将其最大化(事实上,记事本窗口并没有被最大化),将其设为当前窗口,再进行输入,效果和上面的方法是一样的。
wp.showCmd = 3 '3是最大化状态
window = FindWindow(vbNullString, "无标题 - 记事本")
status = SetWindowPlacement(window, wp)
window = SetForegroundWindow(window)
红色部分不理解.