Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) 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 SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Dim myCursor As POINTAPI
'再点击按钮后,将鼠标移到你想要改的窗体上
'看看标题栏里的变化吧!!
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim myhWnd As Long
Dim strName As String * 100
Dim myCh As Long
GetCursorPos myCursor
myhWnd = WindowFromPoint(myCursor.x, myCursor.y)
myCh = GetWindowText(myhWnd, strName, 100)
'Print Left(strName, myCh)
SetWindowText myhWnd, "改!!!!!!!!!!!"
End Sub
一百分 可要算数呀
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
Dim winHwnd As Long
winHwnd = FindWindow(vbNullString, Text1.Text)
If winHwnd <> 0 Then
SetWindowText winHwnd, Text2.Text
Else
MsgBox "并未开启" & Text1.Text
End If
End Sub
Private Sub Form_Load()
Text1.Text = "Form1"
Text2.Text = "改了!"
End Sub
VB声明
Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Long
说明
获得前台窗口的句柄。这里的“前台窗口”是指前台应用程序的活动窗口
返回值
Long,前台窗口的句柄
注解
windows nt支持多个桌面,它们相互间是独立的。每个桌面都有自己的前台窗口
VB声明
Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
说明
设置窗口的标题文字或控件的内容(在vb里使用:针对vb窗体,应使用caption或text属性)
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
hwnd Long,要设置文字的窗口的句柄
lpString String,要设到hwnd窗口中的文字
呵呵,你可以用api函数的
The SetWindowText function changes the text of the specified window抯 title bar (if it has one). If the specified window is a control, the text of the control is changed.
The GetFocus function retrieves the handle of the window that has the keyboard focus, if the window is associated with the calling thread抯 message queue.
The GetFocus function retrieves the handle of the window that has the keyboard focus, if the window is associated with the calling thread抯 message queue.