是不是这么声明:
Private Declare Function FindWindow Lib "user32" Alias
"FindWindow"(ByVal lpClassName As String,ByVal lpWindowName As String) As Long
我不知道VB下第一个参数lpClassName该怎么添。
...全文
181630打赏收藏
谁知道在VB下怎么通过调用FindWindow()获得当前窗口的句柄。
是不是这么声明: Private Declare Function FindWindow Lib "user32" Alias "FindWindow"(ByVal lpClassName As String,ByVal lpWindowName As String) As Long 我不知道VB下第一个参数lpClassName该怎么添。
通常来说FindWindow的第一个参数填入vbNullString就可以了,第二个参数是窗口的Caption;
至于得到当前窗口的句柄用GetForegroundWindow就行了
把一个窗口设为当前窗口用SetForegroundWindow
Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Long
Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Example:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Form_Load()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim lHandle As Long
'First we're going to retrieve the handle of this window
' "ThunderRT5Form" is the classname of a VB-window
lHandle = FindWindow("ThunderRT5Form", Me.Caption)
'Set this window to the foreground
lHandle = SetForegroundWindow(lHandle)
End Sub
我在模块中定义:
Public Function WWndProc(ByVal hw As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
MsgBox "hehe..."
preWndProc = CallWindowProc(preWndProc, hw, Msg, wParam, lParam)
End Function
在窗体文件中定义:
Private Sub Form_Load()
preWndProc = SetWindowLong(Me.hWnd, GWL_WNDPROC, AddressOf WWndProc)
End Sub
'下面代码是找到IE窗口句柄
'声明函数:
Option Explicit Private Declare Function FindWindow Lib"user32" Alias "FindWindowA"(ByVal lpClassname As String,ByVal lpWindowName As String) As Long
'应用
Dim sClassname As long
Dim lhwnd As long
sClassname=("IEFrame")
lhwnd=FindWindow(sClassname,NULL);
Private Sub Form_Load()
preWndProc = SetWindowLong(Me.hWnd, GWL_WNDPROC, AddressOf WWndProc)
End Sub
SetWindowLong的返回值为0,说明操作失败。
/*------------------------------------------*/
If the function succeeds, the return value is the previous value of the specified 32-bit integer.
If the function fails, the return value is zero.
/*------------------------------------------*/