怎么获取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
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
我那个while算枚举吗?确定,取消都可以获取到,就是获取不到中间的文字!
先上图:
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句柄可以获取到,且为有效值,但是上文的两种方法得到的都是空值,求解!!
mscitch = ::GetNextWindow(mscitch,GW_HWNDNEXT);枚举和循环遍历窗口方法用错了 要用 ::GetNextWindow