这个标题很复杂 总问大家有些不好意思,不过确实很无奈,我都愁死了手头还没有相关的书
G1 "A" "B" "C" SETUP PROGRAM 2010-03-12 08:06:31
时间和日期同步更新
用wnd = FindWindow(vbNullString, "****")好像不能实现吧。另外我从网上找到一个,控制“按键”的程序:
Private Sub Command1_Click()
hpwnd = FindWindow(vbNullString, "12345")
hcwnd = FindWindowEx(hpwnd, 0, vbNullString, "确定")
SetForegroundWindow hcwnd
iResult = SendMessage(hcwnd, WM_LBUTTONDOWN, 0, 0&)
iResult = SendMessage(hcwnd, WM_LBUTTONUP, 0, 0&)
End Sub
当我Command1_Click时,目标软件确实有反应,但不是按“确定”键操作的反应,只是窗体闪了闪,
正常按“确定”应该弹出msgbox的。
是SendMessage那错了吗?
G1 "A" "B" "C" SETUP PROGRAM 2010-03-12 08:06:31
时间和日期同步更新
用wnd = FindWindow(vbNullString, "****")好像不能实现吧。另外我从网上找到一个,控制“按键”的程序:
Private Sub Command1_Click()
hpwnd = FindWindow(vbNullString, "12345")
hcwnd = FindWindowEx(hpwnd, 0, vbNullString, "确定")
SetForegroundWindow hcwnd
iResult = SendMessage(hcwnd, WM_LBUTTONDOWN, 0, 0&)
iResult = SendMessage(hcwnd, WM_LBUTTONUP, 0, 0&)
End Sub
当我Command1_Click时,目标软件确实有反应,但不是按“确定”键操作的反应,只是窗体闪了闪,
正常按“确定”应该弹出msgbox的。
是SendMessage那错了吗?
http://support.microsoft.com/kb/147659如何获取窗口句柄不指定精确的标题
FindWindowLike 函数
在回调中捕获:
参考里面4楼
http://topic.csdn.net/u/20090316/18/29aa77dd-c789-4f89-a7db-b4e274e0fcab.html
Const MK_LBUTTON = 1
Private Sub Command1_Click()
Dim hpwnd As Long, hcwnd As Long, iresult As Long
hpwnd = FindWindow(vbNullString, "12345")
hcwnd = FindWindowEx(hpwnd, 0, vbNullString, "确定")
SetForegroundWindow hcwnd
iresult = PostMessage(hcwnd, WM_LBUTTONDOWN, ByVal MK_LBUTTON, ByVal 0&)
iresult = PostMessage(hcwnd, WM_LBUTTONUP, ByVal 0&, ByVal 0&)
End Sub
时间日期同步显示的,有简单的方法吗?
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 GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hWnd As Long, ByVal wFlag 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 Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const GW_CHILD = 5
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDLAST = 1
Private Const GW_HWNDNEXT = 2
Private Const GW_HWNDPREV = 3
Private Const GW_OWNER = 4'取GIS进程的hWnd
Private Function FindGis() As Long
Dim lRt As Long
Dim sTitle As String * 255
'窗口类名
lRt = FindWindow("ThunderRT6MDIForm", vbNullString)
Do Until lRt = 0
GetWindowText lRt, sTitle, 255
If sTitle Like "* GIS 地理信息系统*" Then
FindGis = GetRootParent(lRt)
Exit Do
End If
lRt = GetNextWindow(lRt, GW_HWNDNEXT)
Loop
End Function
Private Function GetRootParent(ByVal hChdWnd As Long) As Long
Dim lRt As Long
Dim lParent As Long
lRt = GetParent(hChdWnd)
If lRt = 0 Then
lRt = GetNextWindow(hChdWnd, GW_OWNER)
End If
lParent = lRt
Do Until lRt = 0
lRt = GetParent(lParent)
If lRt = 0 Then
lRt = GetNextWindow(lParent, GW_OWNER)
End If
If lRt = 0 Then
GetRootParent = lParent
Exit Do
Else
lParent = lRt
End If
Loop
If GetRootParent = 0 Then
GetRootParent = hChdWnd
End If
End Function
Option Explicit
'窗体上添加一个命令按钮Command1,一个列表框List1
Private Sub Command1_Click()
EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End SubPrivate Sub Form_Load()End Sub'标准模块
Option ExplicitPublic Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim windowCaption As String, LengthCaption As Long
LengthCaption = GetWindowTextLength(hwnd)
windowCaption = Space(LengthCaption)
Call GetWindowText(hwnd, windowCaption, LengthCaption + 1)
'查找窗口标题包含文字"SETUP PROGRAM"的窗口。这个地方可以自己改。
If InStr(1, windowCaption, "SETUP PROGRAM") > 0 Then
Debug.Print "这个句柄就是你要找的:"; hwnd
End If
Form1.List1.AddItem Str$(hwnd) + " " + windowCaption
EnumWindowsProc = True
End Function