none
(VB6 winform)FindWindow的问题? RRS feed

  • 问题

  • 程序停止在FindWindow处,提示编译错误,子程序或函数没定义。我没找到感觉。

    ------------------------------------------------------

    所有的控件:

    List1
    Command1
    Command2
    Command3
    程序代码:

    Module1

    Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Declare Function FindWindow Lib "user32″ Alias ″FindWindowA″(ByVal lpClassName As String, ByVal lpWindowName As String) As Long" ()
    Private Declare Function PostMessage Lib "user32″ Alias″PostMessageA″ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long" ()


    Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long


    Public Function EnumWindowsProc2(ByVal hwnd As Long, ByVal lParam As Long) As Boolean

    Dim S As String

    S = String(80, Chr(0))
    Call GetWindowText(hwnd, S, 80)
    S = Left(S, InStr(S, Chr(0)) - 1)

    If Len(S) > 0 Then
    Form1.List1.AddItem S
    End If

    EnumWindowsProc2 = True


    End Function

    Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
    Dim sSave As String, Ret As Long
    Ret = GetWindowTextLength(hwnd)
    sSave = Space(Ret)
    GetWindowText hwnd, sSave, Ret + 1
    Form1.List1.AddItem Str$(hwnd) + " " + sSave
    'continue enumeration
    EnumWindowsProc = True
    End Function



    form1

    Private Sub Command1_Click()

    List1.Clear
    EnumWindows AddressOf EnumWindowsProc2, 0&
    End Sub

    Private Sub Command2_Click()


    List1.Clear
    EnumWindows AddressOf EnumWindowsProc, 0&

    End Sub

    Private Sub Command3_Click()
    ConstWM_CLOSE = &H10
    Dim hwnd, result As Long
    hwnd = FindWindow(vbNullString, "NULL") '查找窗体标题

    If hwnd = 0 Then
        MsgBox "未找到窗口"
    Else
        result = PostMessage(hwnd, WM_CLOSE, 0&, 0&)
    If result = 0 Then
        MsgBox "关闭窗口失败"
    Else
        MsgBox "关闭OK"
    End If
    End If


    End Sub

    2009年3月27日 6:58

答案

  • 定义错误

    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long


    http://feiyun0112.cnblogs.com/
    2009年3月29日 13:32
    版主