我的命令行控制台由于使用可交互的方法实现,没有使用数据管道的方法,我是通过顶层菜单的复制与粘贴的办法获取的。
int CToolAdb::SetScnCopyInfo()
{
CWnd* pDesktopWnd ;
CWnd* pWnd ;
CString strClassName , strWindowText, strMenuText ;
CMenu* pMenu ;
CMenu* pMenuSub ;
int nRtn = 0 ;
int nCount ,subCount, id;
int isFindSelect = 0 ;
int isFindCopy = 0 ;
pDesktopWnd = CWnd::GetDesktopWindow();
pWnd = pDesktopWnd->GetWindow( GW_CHILD );
while( pWnd != NULL )
{
//获得窗口类名
::GetClassName(pWnd->GetSafeHwnd(),strClassName.GetBuffer(256),256);
//获得窗口标题
::GetWindowText(pWnd->GetSafeHwnd(),strWindowText.GetBuffer(256),256);
if( strWindowText.Find( m_strTilte ) >= 0 )
{
nRtn = 1 ;
pMenu = pWnd->GetSystemMenu(FALSE);
nCount = pMenu->GetMenuItemCount();
for(int i = 0 ; i < nCount;i++)
{
id = pMenu->GetMenuItemID( i );
nRtn = pMenu->GetMenuString( i , strMenuText , MF_BYPOSITION );
//遍历子菜单
if ( id== -1 )
{
pMenuSub = pMenu->GetSubMenu( i ) ;
subCount = pMenuSub->GetMenuItemCount();
for( int j = 0 ;j < subCount ;j ++ )
{
id = pMenuSub->GetMenuItemID( j );
nRtn = pMenuSub->GetMenuString( j , strMenuText , MF_BYPOSITION );
if( strMenuText.Find( "全选") >= 0 )
{
isFindSelect = 1 ;
::PostMessage( pWnd->GetSafeHwnd() , WM_COMMAND, id , 0);
break ;
}
}
Sleep( 300 ) ;
if( isFindSelect == 1 )
for( int j = 0 ;j < subCount ;j ++ )
{
id = pMenuSub->GetMenuItemID( j );
nRtn = pMenuSub->GetMenuString( j , strMenuText , MF_BYPOSITION );
if( strMenuText.Find( "复制") >= 0 )
{
isFindCopy = 1 ;
::PostMessage( pWnd->GetSafeHwnd() , WM_COMMAND, id , 0);
break ;
}
}
if( isFindSelect ==1 && isFindCopy == 1 )
break ;
}//if ( id== -1 )
}//for(int i = 0 ; i < nCount;i++)
break ;
}
//继续下一个子窗口
pWnd = pWnd->GetWindow(GW_HWNDNEXT);
}
if( isFindSelect ==1 && isFindCopy == 1 )
nRtn = 1 ;
Sleep( 300 ) ;
return nRtn ;
}