API中,如何获的窗口的标题,只知道窗口的前几个字符串?
不知窗口的句柄,只知道窗口的标题的前几个字符串“ccan”,请问如何获得窗口名!!

解决方案 »

  1.   

    窗体:
    sub sub_sub 
     EnumWindows AddressOf EnumWindowsProc, 0
    end sub模块:Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongFunction EnumWindowsProc(ByVal hwnd As Long, ByVal parma As Long) As Long
        
        Dim astr As String * 256
        
        GetWindowText hwnd, astr, Len(astr)
        
        If InStr(1, astr, "Microsoft Excel") > 0 Then
            gblnFindExcel = True
            lngHwnd = hwnd
            MsgBox "Please close all EXCEL window and try again!", vbInformation
            Exit Function
        End If
        
        EnumWindowsProc = True
    End Function
      

  2.   

    请问楼上的,我运行了一下,一个窗口名也没得到。在astr中竟是一些不知哪里来的!
    这是怎么回事?????
      

  3.   

    不需要遍历窗口.只要找到要找的窗口就可以了.运行你要找的窗口的程序.用spy++可以找到要找的窗口的类和标题.然后再搞到句柄就随便操作窗口了.
      

  4.   

    纠正一下。rappercn(rapper) 你的程序很对,使我写错了。抱歉。
    谢谢你了。