|
See what you want.
If it is IE, use the above,
If it is other IE kernel, it needs to be a modified method.
But there is a premise, you have to get the HWnd of that window, otherwise, don't say anything.
If you have already got hwnd, what is going on.
For example, after getting the HWnd of the form under the mouse, it is judged whether it is an HWnd of the IE kernel.
If so, proceed.
Below is a part of the code I am using in the Data Collection Library, you can see it.
[code = c / c ++]]
BOOL __FASTCALL TFORM :: FindHTMLParent (HWND HWND)
{
// Todo: Find a look at the HTML's father form is not docbook or the resource manager.
// Returns True. Otherwise, false
HWND HWNDPARENT = NULL;
/ / Find the parent window handle of Internet Explorer_Server
HWndParent = getParent (hwnd);
IF ((hwndparent! = hwnd)&&hwndparent! = null)
{
Char bufclassname [255], bufclasscaption [255];
GetClassName (HWndParent, BufcoSsName, 255);
IF (("" "" "SHELLDLL_DEFVIEW"> 0) // Explorer.
|| (BUFCLASSNAME) .POS ("Internet Explorer_tridentdlgFrame")> 0) // IE dialog
Return True;
ansistring (bufclassname) .POS ("shell docobject view"> 0)
{
// If it is an IE or other browser, it is necessary to determine if Docbook's browser.
Int textLength;
HWnd hmainwndparent = getParent (hwndparent);
GetClassName (HmainWndParent, BufclassName, 255);
IF (bufclassname) .pos ("shell embedding")> 0)
{
HWnd hpmainwndparent = getParent (hmainwndparent);
GetClassName (HPMainWndParent, BufclassName, 255);
TextLength = SendMessage (HPMainWndParent, WM_GettextLength, 0, 0);
IF (TextLength> 256) TextLength = 255;
IF (TextLength> 0)
{
SendMessage (HPMainWndParent, WM_Gettext, TextLength + 1, (LPARAM) 0uO0BufClassCAption [0]);
IF (BUFCLASSCAPTION) .POS ("DOCBOOK")) Return True;
}
} // end of shell embedding
} // end of shell docObject view
} // end of null.
Return False;
}
/ / -------------------------------------------------------------------------------------------- ---------------------------
Void __fastcall tform :: ONGETDOCINTERFACE (HWND HWND)
{
// Todo: A corresponding web_ie_doc
FindHTMLParent (HWND)) Return;
Coinitialize (NULL);
// oleinitialize (null);
// TODO: A content obtained by obtaining the obtained IE.
// Explicitly Load MSAA SO We know if it's installed
Wchar_t * sztitle = l "", * szurl = L "";
IHTMLDocument2 * WebDoc = NULL;
Hinstance hinst = :: loadLibrary (_t ("oleacc.dll"));
IF (hinst! = null)
{
IF (hwnd! = null)
{
// ccomptr <htmldocument2> spdoc;
System :: delphiinterface <htmldocument2> spdoc;
LRESULT LRES;
UINT NMSG = :: RegisterWindowMessage (_t ("wm_html_getobject")))
:: SendMessagetimeout (HWND, NMSG, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD *) 0u0lres;
LPFNObjectFromlResult PfObjectfromlresult = (lpfnobjectfromlresult) :: getProcaddress (Hinst, _t ("ObjectFromlResult");
IF (pfObjectfromlresult! = null)
{
HRESULT HR;
HR = (* pfObjectfromlResult) (Lres, IID_IHTMLDocument, 0, (void **) 0uO0Spdoc);
En (ac))
{
System :: DelphiInterface <iDispatch> SPDISP;
System :: DelphiInterface <htmlwindow2> spwin;
// ccomptr <iDispatch> spdisp;
// ccomqiptr <htmlwindow2> spwin;
SPDOC-> Get_Script (0uO0SPDISP);
SPWIN = SPDISP;
// spwin-> get_document (0uO0spdoc.p);
// WebDoc = (lpdispatch) SPDOC;
Spwin-> get_document (0uO0Webdoc);
// spdoc-> get_title (0uO0sztitle);
// SPDOC-> GET_URL (0uO0Szurl);
Webdoc-> get_title (0uO0sztitle);
WebDoc-> get_url (0uO0Szurl);
}
} // end of if (pfObjectFromlResult! = null)
} // if (hwnd! = null)
:: Freelibrary (HINST);
} // Else Active Accessibility Is Not Installed
IF (ANSISTRING (SZURL) == "" ")
{
Return;
}
Couninitialize ();
}
/ / -------------------------------------------------------------------------------------------- ---------------------------
// Turn off the code.
HDESTHWND is to close
// Turn off the specified window.
Char bufclassname [256];
MEMSET (BUFCLASSNAME, 0X00, SIZEOF (BUFCLASSNAME);
GetClassName (HDesthWnd, BufcoSsName, 255);
IF (strcmp (bufclassname, "hh child")! = 0) // hh child is not closed.
{
// Maxthon has a problem, and it doesn't work directly to PostMessage.
// Only the complete path of EXE is obtained by the form handle.
// First obtain the handle of the main form of the program
HWnd MaxthonRoothWnd = GetanceStor (HDESTHWND, GA_ROOT);
DWORD LPDWPROCESSID;
Handle ExeHandle;
HModule HMODS = NULL;
// A re-acquisition of the program's EXE path
GetWindowThreadProcessId (MaxthonRoothWnd, 0uO0Lpdwprocess);
ExeHandle = OpenProcess (Process_Query_information | Process_vm_Read,
True, LPDWPROCESSID;
IF (exehandle)
{
MEMSET (BUFCLASSNAME, 0X00, SIZEOF (BUFCLASSNAME);
GetModuleFileNameEx (ExeHandle, HMODS, BUFCLASSNAME, SIZEOF (BUFCLASSNAME);
IF (BUFCLASSNAME) .uppercase (). POS ("Maxthon.exe")))
{
// HDesthwnd is not a real window, it should be striking.
HDESTHWND = getParent (HDESTHWND);
}
} // end of if (exehandle)
Postmessage (HDesthWnd, WM_Close, Null, NULL);
} // end of if (bufflassname, "hh child")
[/ code] |
|