MSDN里的说明FindWindow
The FindWindow function retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. This function does not perform a case-sensitive search. HWND FindWindow(
LPCTSTR lpClassName, // pointer to class name
LPCTSTR lpWindowName // pointer to window name
);
The FindWindow function retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. This function does not perform a case-sensitive search. HWND FindWindow(
LPCTSTR lpClassName, // pointer to class name
LPCTSTR lpWindowName // pointer to window name
);
解决方案 »
- WM_GETDLGCODE 死循环
- 为什么我关闭不了MessageBox()对话框?
- 为什么:结构体指针 对应的结构体中的CString变量赋值会提示错误?
- 大侠们请进!
- 请问有关Listen和Connect的问题…… 在线急!
- USB盘如果用在自己程序里安全扒出?(Eject)
- 在线等待,求教一个画图的问题
- 问一个很简单的问题,(300分)(有关TELNET的)。。。。。。
- 如果在form中嵌入activex控件?
- 请问关于ActiveMovie控件的问题
- windows编程的几个模糊概念
- 我用vc连接sql server,在配置了odbc后连接是还要在串中设置uid和pwd才行,能不能不用这样?
FindWindow 只是一个简单的 Api 根本不涉及消息。
>>vb 好像不能响应自定义消息(使用某些控件可以),试试:
Public Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
vb可以处理自定义消息的,非常麻烦.
1建立一个全局函数Public Function WWndProc(ByVal hw As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long `函数名随意
2使用 preWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WWndProc)函数将消息处理挂钩设到wwndproc()上
3在wwndproc()中检查消息,如果是普通消息则使用 CallWindowProc(preWndProc, hw, Msg, wParam, lParam)处理之.如是自定义消息...哈哈!!搞定.
4别忘了再用 SetWindowLong(hwnd, GWL_WNDPROC, preWndProc)将挂钩设回.
其中的hwnd是窗口句柄.
此程序不能在vb5(还是cb4?记不清了)中运行,因为不支持addressof运算.
注意!!调试时千万不可trace到wwndproc中,否则....
这样也行,高!实在是高!
在使用此方法时强烈建议先保存再运行,否则又是"..."
CallWindowProc(preWndProc, hw, Msg, wParam, lParam)
在VB里应该怎么声明呀,我怎么老是找不到dll的入口?
'声明函数:
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);
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可是,WWndProc根本就执行不到,最大化,最小化总是消息吧?
这是怎么回事?
preWndProc = SetWindowLong(Me.hWnd, GWL_WNDPROC, AddressOf WWndProc)
End SubSetWindowLong的返回值为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.
/*------------------------------------------*/
preWndProc = SetWindowLong(Me.hWnd, GWL_WNDPROC, AddressOf WWndProc)
操作失败吗?
至于得到当前窗口的句柄用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 LongExample:
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: [email protected]
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