VB2005怎么用API
谁拿FindWindow这个API举个例子。。从VB6.0转到2005不太适应。。。帮忙举个例子...
谁拿FindWindow这个API举个例子。。从VB6.0转到2005不太适应。。。帮忙举个例子
展开
2个回答
展开全部
1.Windows的API有两个版本的,比如ANSI的FindWindowA(),Unicode的FindWindowW()
2.两种声明的方式
<DllImport("user32.dll", CharSet:=CharSet.Auto, EntryPoint:="FindWindow")> _
Shared Function FindWindow(ByVal className As String, ByVal windowName As String) As IntPtr
End Function
Declare Auto Function FindWindow Lib "user32.dll" Alias "FindWindow" (ByVal className As String, ByVal windowName As String) As IntPtr
.net 和vb不一样。 窗口句柄之类的要声明成interger 32位的才行 如果在.net中 声明成long 那就执行不成功
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
声明完后
Me.Timer1.Enabled = True
Me.Timer1.Interval = 10000
MessageBox.Show("xinjing", "haha")
Timer1.Enabled = False
在timer的tick中
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim hWnd As Integer
hWnd = FindWindow(vbNullString, "haha")
If hWnd Then
'查找到窗口则关闭
PostMessage(hWnd, &H10, 0&, 0&)
End If
End Sub
就可解决问题。
2.两种声明的方式
<DllImport("user32.dll", CharSet:=CharSet.Auto, EntryPoint:="FindWindow")> _
Shared Function FindWindow(ByVal className As String, ByVal windowName As String) As IntPtr
End Function
Declare Auto Function FindWindow Lib "user32.dll" Alias "FindWindow" (ByVal className As String, ByVal windowName As String) As IntPtr
.net 和vb不一样。 窗口句柄之类的要声明成interger 32位的才行 如果在.net中 声明成long 那就执行不成功
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
声明完后
Me.Timer1.Enabled = True
Me.Timer1.Interval = 10000
MessageBox.Show("xinjing", "haha")
Timer1.Enabled = False
在timer的tick中
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim hWnd As Integer
hWnd = FindWindow(vbNullString, "haha")
If hWnd Then
'查找到窗口则关闭
PostMessage(hWnd, &H10, 0&, 0&)
End If
End Sub
就可解决问题。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询