得到桌面上所有打开窗口的标题(方法二)

来源:互联网 发布:c语言怎么定义一个数组 编辑:程序博客网 时间:2024/05/22 09:41
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lparam)
{
    // 方法一:

    //BOOL     bRval            ;
    CString  text            ;
    CString  m_strTitle        ;
    LPWSTR  lpwstr = NULL    ;

    lpwstr = new WCHAR[256];
    //memset( lpwstr , 0 , 256 ); //用这个不对

    //bRval = FALSE;

    GetWindowText( hwnd ,lpwstr , 256 );

    m_strTitle = (LPCTSTR)lpwstr;
    lparam = (LPARAM)lpwstr;

    if(  -1 != m_strTitle.Find( TEXT("Microsoft Word"))  ){
    
        text.Format( TEXT( "word的标题为/"%s/"" ) ,m_strTitle);
        
        AfxMessageBox(text) ;
        //return TRUE ;
        //bRval = TRUE;

    }
    
    return TRUE ; // 必须返回真,否则只检查一个窗口就停止
    //return bRval;

/*
// 方法二
    CString text;
    char lpWinTitle[256];

    ::GetWindowText(hwnd,(LPWSTR)lpWinTitle ,256-1);

    CString m_strTitle;

    m_strTitle.Format( TEXT("%s") ,lpWinTitle);

    if( m_strTitle.Find( TEXT("Microsoft Word")) != -1 ){
        
        text.Format( TEXT( "word的标题为/"%s/"" ),lpWinTitle);

        AfxMessageBox(text) ;
    }
    return TRUE ;
*/
    
}


void CshareFileDlg::OnBnClickedButtonShare()
{
    LPARAM lparam ;
    LPCTSTR lpctstr;
    lparam = NULL;
    lpctstr = NULL;
    lpctstr = new TCHAR[256];

    if( EnumWindows( EnumWindowsProc, NULL) ){

        lpctstr = (LPCTSTR)lparam;

        AfxMessageBox( lpctstr );

    } else{

        AfxMessageBox( TEXT( " no word had been opened" ) );
    }
}
原创粉丝点击