假如我用程序启动了一个word ,如何获得它的hWnd-窗口句柄
findwindow(vbnullstring,窗口标题名),成功返回句柄,失败返回0
theword = findwindow ( "OpusApp", vbnullstring )
用timer可以做到,中间那个分割条好像不好做
获得句柄后可以用timer 定时返回两个窗口的尺寸,使两个窗口的尺寸和等于指定的数值.
关注...
针对两个记事本
Option Explicit
Dim b As Boolean
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 100
n0 = 0
n1 = 0
End Sub
Private Sub Timer1_Timer()
If Not b Then
b = True
Else
If n0 <> 0 And n1 <> 0 Then
Dim r As RECT
GetWindowRect n0, r
SetWindowPos n1, 0, 0, r.Bottom, Screen.Width / 15, Screen.Height / 15 - r.Bottom, 0
Else
n0 = 0
n1 = 0
EnumWindows AddressOf myenum, ByVal 0&
End If
End If
End Sub
-----------------------------------------------
Option Explicit
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Public Type RECT
Left As Long
As Long
Right As Long
Bottom As Long
End Type
Public n0 As Long
Public n1 As Long
Public Function myenum(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim ss As String * 255
GetClassName hwnd, ss, 255
If remove0(ss) = "Notepad" And n0 = 0 Then
n0 = hwnd
End If
If remove0(ss) = "Notepad" And n1 = 0 And n0 <> 0 And hwnd <> n0 Then
n1 = hwnd
End If
myenum = 1
End Function
Public Function remove0(ByVal src As String) As String
Dim i As Integer
Dim s As String
For i = 1 To Len(src)
If Mid(src, i, 1) <> Chr(0) Then
s = s & Mid(src, i, 1)
Else
Exit For
End If
Next i
remove0 = s
End Function