怎么获得任一窗口的指针

你创建的IDD_Dialog1对话框,调用的实例如果是dlg
就用dlg.GetDlgItem(控件ID)
如果实例是指针,就用dlg->GetDlgItem(控件ID)
还有一个更加万能的方法,就是从桌面开始一层一层的找你要找的窗口句柄,提供一段代码供参考:
hWnd = ::GetWindow( ::GetDesktopWindow(), GW_CHILD );
while ( hWnd != NULL)
{
memset( szTittleInfo , NULL , 255 );
::GetWindowText( hWnd, szTittleInfo , 255 );
szInfo.Format( "%s" , szTittleInfo ) ;
if( szInfo.GetLength() > 0 )
{
if( szInfo.CompareNoCase( "YabooPanoramic - [四分镜头]") == 0 )
{
TarghWnd = hWnd ;
break ;
}
}
hWnd =::GetWindow( hWnd , GW_HWNDNEXT );
}

if( TarghWnd == NULL && m_CameraNo < 5 && m_nRunMode == 1 )
{
AfxMessageBox( "没有找到应用程序!" );

OnOK();
//return FALSE ;

return TRUE ;
}

m_AppHWnd = TarghWnd ;

//MdiClient ;
hWnd = ::GetWindow( TarghWnd , GW_CHILD );
//子框架句柄
hWnd = ::GetWindow( hWnd , GW_CHILD );
//视图句柄
TarghWnd = ::GetWindow( hWnd , GW_CHILD );

int nValue ;
hWnd = ::GetWindow( TarghWnd , GW_CHILD );
while( hWnd != NULL )
{
szInfo.Format( "%d" , hWnd ) ;
nValue = atoi( szInfo );
if( nValueA == nValue )
{
m_wndCameraA = hWnd ;
break ;
}
hWnd = ::GetWindow( hWnd , GW_HWNDNEXT );
}

hWnd = ::GetWindow( TarghWnd , GW_CHILD );
while( hWnd != NULL )
{
szInfo.Format( "%d" , hWnd ) ;
nValue = atoi( szInfo );
if( nValueB == nValue )
{
m_wndCameraB = hWnd ;
break ;
}

hWnd = ::GetWindow( hWnd , GW_HWNDNEXT );
}

hWnd = ::GetWindow( TarghWnd , GW_CHILD );
while( hWnd != NULL )
{
szInfo.Format( "%d" , hWnd ) ;
nValue = atoi( szInfo );
if( nValueA2 == nValue )
{
m_wndCameraA2 = hWnd ;
break ;
}
hWnd = ::GetWindow( hWnd , GW_HWNDNEXT );
}

hWnd = ::GetWindow( TarghWnd , GW_CHILD );
while( hWnd != NULL )
{
szInfo.Format( "%d" , hWnd ) ;
nValue = atoi( szInfo );
if( nValueB2 == nValue )
{
m_wndCameraB2 = hWnd ;
break ;
}

hWnd = ::GetWindow( hWnd , GW_HWNDNEXT );
}

转载于:https://www.cnblogs.com/ransn/p/8110852.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值