IE中文本框并不是真正意义上的窗口,不过可以从坐标点获得最小窗口 HWND CMyDlg::SmallestWindowFromPoint(const POINT point) { // Find the smallest "window" still containing the point // Doing this prevents us from stopping at the first window containing the point RECT rect, rectSearch; HWND hParentWnd, hWnd, hSearchWnd; hWnd = ::WindowFromPoint(point); if(hWnd != NULL) { // Get the size and parent for compare later ::GetWindowRect(hWnd, &rect); hParentWnd = ::GetParent(hWnd); // We only search further if the window has a parent if(hParentWnd != NULL) { // Search from the window down in the Z-Order hSearchWnd = hWnd; do{ hSearchWnd = ::GetWindow(hSearchWnd, GW_HWNDNEXT); // Does the search window also contain the point, have the same parent, and is visible? ::GetWindowRect(hSearchWnd, &rectSearch); if(::PtInRect(&rectSearch, point) && ::GetParent(hSearchWnd) == hParentWnd && ::IsWindowVisible(hSearchWnd)) { // It does, but is it smaller? if(((rectSearch.right - rectSearch.left) * (rectSearch.bottom - rectSearch.top)) < ((rect.right - rect.left) * (rect.bottom - rect.top))) { // Found new smaller window, update compare window hWnd = hSearchWnd; ::GetWindowRect(hWnd, &rect); } } }while(hSearchWnd != NULL); } } return hWnd; }
IHTMLDocument2::elementFromPoint Method--------------------------------------------------------------------------------Returns the element for the specified x and y coordinates. SyntaxHRESULT elementFromPoint( long x, long y, IHTMLElement **elementHit );
HWND CMyDlg::SmallestWindowFromPoint(const POINT point)
{
// Find the smallest "window" still containing the point
// Doing this prevents us from stopping at the first window containing the point
RECT rect, rectSearch;
HWND hParentWnd, hWnd, hSearchWnd; hWnd = ::WindowFromPoint(point);
if(hWnd != NULL)
{
// Get the size and parent for compare later
::GetWindowRect(hWnd, &rect);
hParentWnd = ::GetParent(hWnd); // We only search further if the window has a parent
if(hParentWnd != NULL)
{
// Search from the window down in the Z-Order
hSearchWnd = hWnd;
do{
hSearchWnd = ::GetWindow(hSearchWnd, GW_HWNDNEXT); // Does the search window also contain the point, have the same parent, and is visible?
::GetWindowRect(hSearchWnd, &rectSearch);
if(::PtInRect(&rectSearch, point) && ::GetParent(hSearchWnd) == hParentWnd && ::IsWindowVisible(hSearchWnd))
{
// It does, but is it smaller?
if(((rectSearch.right - rectSearch.left) * (rectSearch.bottom - rectSearch.top)) < ((rect.right - rect.left) * (rect.bottom - rect.top)))
{
// Found new smaller window, update compare window
hWnd = hSearchWnd;
::GetWindowRect(hWnd, &rect);
}
}
}while(hSearchWnd != NULL);
}
} return hWnd;
}
1。ie中的文本框如果不是窗口,究竟是什么?
2。用ChildWindowFromaPoint行不行?
3ks!!!
long x,
long y,
IHTMLElement **elementHit
);
使用COM的方法可以得到它里面的表单元素及句柄:
CString GetPassword(IHTMLDocument2 *pDoc2,POINT pt)
{
if(pDoc2==NULL)return "";
CComPtr<IHTMLElement> pElement;
HRESULT hr=pDoc2->elementFromPoint(pt.x,pt.y,&pElement);
if(SUCCEEDED(hr)){
CComPtr<IHTMLInputTextElement> pPwdElement;
hr=pElement->QueryInterface(IID_IHTMLInputTextElement,
(void**)&pPwdElement);
if(SUCCEEDED(hr)){
CComBSTR type;
hr=pPwdElement->get_type(&type);
if(SUCCEEDED(hr)){
if(type==_T("password")){
CComBSTR pwd;
hr=pPwdElement->get_value(&pwd);
if(SUCCEEDED(hr)){
if(pwd.Length()!=0){
CComBSTR msg;
msg=pwd;
CString str(msg);
return str;
}
else{
return "";
}
}
}
}
}
}
pDoc2->Release();
return "";
}
使用COM的方法可以得到它里面的表单元素及句柄:
CString GetPassword(IHTMLDocument2 *pDoc2,POINT pt)
{
if(pDoc2==NULL)return "";
CComPtr<IHTMLElement> pElement;
HRESULT hr=pDoc2->elementFromPoint(pt.x,pt.y,&pElement);
if(SUCCEEDED(hr)){
CComPtr<IHTMLInputTextElement> pPwdElement;
hr=pElement->QueryInterface(IID_IHTMLInputTextElement,
(void**)&pPwdElement);
if(SUCCEEDED(hr)){
CComBSTR type;
hr=pPwdElement->get_type(&type);
if(SUCCEEDED(hr)){
if(type==_T("password")){
CComBSTR pwd;
hr=pPwdElement->get_value(&pwd);
if(SUCCEEDED(hr)){
if(pwd.Length()!=0){
CComBSTR msg;
msg=pwd;
CString str(msg);
return str;
}
else{
return "";
}
}
}
}
}
}
pDoc2->Release();
return "";
}
使用COM的方法可以得到它里面的表单元素及句柄:
CString GetPassword(IHTMLDocument2 *pDoc2,POINT pt)
{
if(pDoc2==NULL)return "";
CComPtr<IHTMLElement> pElement;
HRESULT hr=pDoc2->elementFromPoint(pt.x,pt.y,&pElement);
if(SUCCEEDED(hr)){
CComPtr<IHTMLInputTextElement> pPwdElement;
hr=pElement->QueryInterface(IID_IHTMLInputTextElement,
(void**)&pPwdElement);
if(SUCCEEDED(hr)){
CComBSTR type;
hr=pPwdElement->get_type(&type);
if(SUCCEEDED(hr)){
if(type==_T("password")){
CComBSTR pwd;
hr=pPwdElement->get_value(&pwd);
if(SUCCEEDED(hr)){
if(pwd.Length()!=0){
CComBSTR msg;
msg=pwd;
CString str(msg);
return str;
}
else{
return "";
}
}
}
}
}
}
pDoc2->Release();
return "";
}
BCB_FANS:你要得到那个句柄干什么,其实输入框的属性及文本等都可以得到的。
BCB_FANS:你要得到那个句柄干什么,其实输入框的属性及文本等都可以得到的。