如何取得Windows任务栏上打开的窗口的类名及标题???

解决方案 »

  1.   

    试试
    int GetClassName(
      HWND hWnd,           // handle of window
      LPTSTR lpClassName,  // address of buffer for class name
      int nMaxCount        // size of buffer, in characters
    );
      

  2.   

    fzd999(花差花差)的回复不太对,得到的窗口数量多于我想得到的窗口数量。
    我要的功能与金山游侠2002中点击搜索,弹出的程序列表窗口相同,它只取得在任务栏中
    显示的窗口,不包括隐藏窗口。在有办法吗?
      

  3.   

    VC的代码我现在还没有写,下面是用VB写的:
    Public Sub ListWindow()
        
        Call EnumWindows(AddressOf EnumWindowsProc, 0&)
        
    End Sub
    //CALLBACK函数
    Private Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean    Dim strTemp As String    On Error GoTo Err
        
        If (IsWindowVisible(hwnd)) And (GetWindowLong(hwnd, GWL_HWNDPARENT) = 0) _
        And ((GetWindowLong(hwnd, GWL_EXSTYLE) And WS_EX_TOOLWINDOW) = 0) Then
             strTemp = "Handle:" & hwnd & ",Title:" & GetText(hwnd)
             frmTaskBar.cmbList.AddItem strTemp
        End If
        EnumWindowsProc = True
        Exit Function
    Err:
        MsgBox Err.Description
        Err.Clear
        EnumWindowsProc = TrueEnd Function
      

  4.   

    我用liaoxw81(liao)的方法,写了VC程序,如下:
    int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {
    int nRetCode = 0; // initialize MFC and print and error on failure
    if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
    {
    // TODO: change error code to suit your needs
    cerr << _T("Fatal Error: MFC initialization failed") << endl;
    nRetCode = 1;
    }
    else
    {
    // TODO: code your application's behavior here.
    EnumWindows(EnumWindowsProc, 0);
    } return nRetCode;
    }BOOL CALLBACK EnumWindowsProc(
      HWND hwnd,      // handle to parent window
      LPARAM lParam)   // application-defined value
    {
    char className[250] = "";
    char winTitle[250] = "";
    LONG exStyle = 0; if ( IsWindowVisible(hwnd) 
    && (GetParent(hwnd) == NULL) )
    {
    exStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
    if ( !(exStyle & WS_EX_TOOLWINDOW) )
    {
    GetWindowText(hwnd, winTitle, sizeof(winTitle));
    GetClassName(hwnd, className, sizeof(className));
    printf("Windows Class Name : %s\n", className);
    printf("Windows Title : %s\n\n", winTitle);
    }
    } return true;
    }但是在运行FoxMail程序时,再运行该程序,得到的窗口列表不正确,Foxmail有两个窗口。
    运行结果如下:
    Windows Class Name      : ConsoleWindowClass
    Windows Title           : C:\WINNT\system32\cmd.exe - testWindows Class Name      : TFoxmail_Main
    Windows Title           : FoxmailWindows Class Name      : TApplication
    Windows Title           : Foxmail
    .........截断............
      

  5.   

    我用来查询任务栏上可见窗口的方法(不可见的略过)
    int i,index;
    DWORD dwStyle;
    HWND hTempWnd; hTempWnd=::FindWindowEx(NULL,NULL,NULL,NULL); count=0;
    while(hTempWnd!=NULL)
    {
    if(IsWindow(hTempWnd)&&::IsWindowVisible(hTempWnd))
    {
    dwStyle=GetWindowLong(hTempWnd,GWL_EXSTYLE);
    if(!(dwStyle&WS_EX_TOOLWINDOW))
    {
    ::GetWindowText(hTempWnd,wininfo[count].Title,255);
    if(strlen(wininfo[count].Title)>0&&strcmp("AutoHide 1.01",wininfo[count].Title)!=0)
    {
    wininfo[count].hWndProc=hTempWnd;
    count++;
    if(count>=TOTALWINDOW)
    break;
    }
    }
    }
    hTempWnd=::FindWindowEx(NULL,hTempWnd,NULL,NULL);
    }