怎么获取messagebox中的文本?这个消息框是其他程序弹出来的,准确来说是网页的alert弹出来的。现在我可以获取整个窗口的句柄,和里面按钮的句柄和值,也可以点击按钮。但是就是获取不到里面的内容。求大神帮助!!!我的代码如下:
HWND mhWind =::FindWindow(NULL,L"来自网页的消息");//IE8
if(!mhWind)
{
mhWind =::FindWindow(NULL,L"Microsoft Internet Explorer");//IE6
if(!mhWind)
{
mhWind =::FindWindow(NULL,L"Windows Internet Explorer");//IE7
}
}
if(mhWind)//弹出对话框
{
HWND mhwStatic = ::FindWindowEx(mhWind,NULL,NULL,NULL);
while(mhwStatic)
{
CWnd* p = CWnd::FromHandle(mhwStatic);
CString strValue = L"";
p->GetWindowText(strValue);
MessageBox(strValue);
mhwStatic = ::FindWindowEx(mhWind,mhwStatic,NULL,NULL);
}
       }Visual C++Internet ExplorerFindWindowEx

解决方案 »

  1.   

    枚举窗口,找到类型是 STATIC 的然后 GetWindowText
      

  2.   


    我那个while算枚举吗?确定,取消都可以获取到,就是获取不到中间的文字!
      

  3.   

    原来一直没用过这个工具。刚试了一下找到了需要的东西,但是为什么我那样子获取不到Static 的值。
    先上图:
     HWND mhwStatic = ::FindWindowEx(mhWind,NULL,L"Static",NULL);
    这种方式我也试过,获取不到哦···
      

  4.   

    HWND mhwStatic = ::FindWindowEx(mhWind,NULL,L"Static",NULL);
    if(mhwStatic)
    {
    //CWnd* p = CWnd::FromHandle(mhwStatic);
    CString strValue = L"";
    //p->GetWindowText(strValue);

    //mhwStatic = ::FindWindowEx(mhWind,mhwStatic,NULL,NULL); TCHAR tchar1[200];
    ::SendMessage(mhwStatic, WM_GETTEXT, (sizeof(tchar1)/sizeof(TCHAR)), (LPARAM)(tchar1));
    MessageBox(CString(tchar1));
    ::GetWindowText(mhwStatic, (LPWSTR)tchar1, sizeof(tchar1)/sizeof(TCHAR));
    MessageBox(CString(tchar1));
    }
    感觉快出来了。Static句柄可以获取到,且为有效值,但是上文的两种方法得到的都是空值,求解!!
      

  5.   

    HWND mscitch = ::FindWindowEx(mhWind,NULL,L"Static",NULL);
    mscitch = ::GetNextWindow(mscitch,GW_HWNDNEXT);枚举和循环遍历窗口方法用错了 要用 ::GetNextWindow