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
);

解决方案 »

  1.   

    Lib "user32" 是不是应该改一改?
      

  2.   

    比如你找一个叫Explorer的,就传个"Explorer"过去就行了。
      

  3.   

    我知道了,是用me.hWnd就可以了那么,VB的窗体怎么响应dll来的消息呢?
      

  4.   

    vb 好像不能响应自定义消息(使用某些控件可以),
    FindWindow 只是一个简单的 Api 根本不涉及消息。
      

  5.   

    <<vb 好像不能响应自定义消息(使用某些控件可以),真的吗?! 什么控件?
     
      

  6.   

    To:gboy(boy) 
    >>vb 好像不能响应自定义消息(使用某些控件可以),试试:
    Public Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
      

  7.   

    楼上的仁兄大错了.那是设置systray的函数.和自定义消息无关
    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中,否则....
      

  8.   

    to :pgfun() 
    这样也行,高!实在是高!
      

  9.   

    btw 这种技术在 vc 中被称作“子类化”,我真么没想到用在 vb 里。
      

  10.   

    当然行得通的啦.这可是小弟我仔细研究了msdn后再经过n次死机后才搞定的.
    在使用此方法时强烈建议先保存再运行,否则又是"..."
      

  11.   

    自定义消息?RegisterMessage不算自定义的吗?
      

  12.   

    To pgfun()兄:这个贴子暂不打算结束。 请到 --答谢pgfun兄对于“VB如何响应自定义消息”的回答!--中点击一下。
      

  13.   

    SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WWndProc)
    CallWindowProc(preWndProc, hw, Msg, wParam, lParam)
    在VB里应该怎么声明呀,我怎么老是找不到dll的入口?
      

  14.   

    老是报错:"找不到dll的入口"
      

  15.   

    我是这么声明的:Declare Function SetWindowLong Lib "user32" (ByVal hwnd As Long, ByVal nIndex As Integer, ByVal dwNewLong As Long) As Long
      

  16.   

    '下面代码是找到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);
      

  17.   

    To pgfun()兄 :我在模块中定义:
    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根本就执行不到,最大化,最小化总是消息吧?
    这是怎么回事?
      

  18.   

    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long 在lpClassName中填入vbNullString,传到系统中是长整形的0.
      

  19.   

    lpClassName中填入vbNullString或lpWindowName填入vbNullString都可以!你只要知道其中的一个就行了!SO EASY!
      

  20.   

    窗体句柄已可以知道,问题是VB窗体怎么接收dll传来的自定义的消息?
      

  21.   

    Private Sub Form_Load()
    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. 
    /*------------------------------------------*/
      

  22.   

    那你能告诉我为什么
    preWndProc = SetWindowLong(Me.hWnd, GWL_WNDPROC, AddressOf WWndProc)
    操作失败吗?
      

  23.   

    通常来说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 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