Get the process handle value of the browser window that launches in a new tab
The problem is that I want to get the handle value of the new tab created here.
By default, when you get the handle value of pWebBrowser2, it gets caught as the main handle of the current window, not the new handle's unique handle.
There is one operating condition here. IE Tools -> Internet Options -> General -> Tab Settings -> Always open popup in new window should be enabled.
Always open popup in new window Because of the setting, the newly opened window runs as a separate process.
The problem is that you should not get the handle value after the window pops up, but I need to know the handle value before Navigate2.
If you provide a basic sample file to fix the problem, we will support $ 500 with PayPal.
CString strUrl = _T("http://www.google.com");
CoInitialize(NULL);
HINSTANCE hInst = ::LoadLibrary(_T("OLEACC.DLL"));
if (hInst != NULL)
{
if (hwnd)
{
CComPtr<IHTMLDocument2> spDoc;
LRESULT lRes;
UINT nMsg = ::RegisterWindowMessage(_T("WM_HTML_GETOBJECT"));
::SendMessageTimeout(hwnd, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes);
HRESULT hr = ::ObjectFromLresult(lRes, IID_IHTMLDocument2, 0, (void**)&spDoc);
if (SUCCEEDED(hr))
{
CComPtr<IHTMLWindow2> spWnd2;
hr = spDoc->get_parentWindow((IHTMLWindow2**)&spWnd2);
if (SUCCEEDED(hr))
{
CComPtr<IServiceProvider> spServiceProv;
hr = spWnd2->QueryInterface(IID_IServiceProvider, (void**)&spServiceProv);
if (SUCCEEDED(hr))
{
IWebBrowser2* pWebBrowser2 = 0;
hr = spServiceProv->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void**)&pWebBrowser2);
if (SUCCEEDED(hr))
{
// Here IWebBrowser2 makes navigate2 as a new tab.
VARIANT vtUrl;
VariantInit(&vtUrl);
vtUrl.vt = VT_BSTR;
vtUrl.bstrVal = strUrl.AllocSysString();
VARIANT vFlags;
V_VT(&vFlags) = VT_I4;
V_I4(&vFlags) = navOpenInNewWindow;
VARIANT vEmpty;
VariantInit(&vEmpty);
pWebBrowser2->Navigate2(&vtUrl, &vFlags, &vEmpty, &vEmpty, &vEmpty);
VariantClear(&vtUrl);
VariantClear(&vFlags);
VariantClear(&vEmpty);
pWebBrowser2->Release();
}
spServiceProv.Release();
}
spWnd2.Release();
}
spDoc.Release();
}
}
::FreeLibrary(hInst);
}
CoUninitialize();
Basically, when you get the handle value of pWebBrowser2, it gets caught as the main handle of the current window, not the new handle's unique handle.
c++ mfc iwebbrowser2
add a comment |
The problem is that I want to get the handle value of the new tab created here.
By default, when you get the handle value of pWebBrowser2, it gets caught as the main handle of the current window, not the new handle's unique handle.
There is one operating condition here. IE Tools -> Internet Options -> General -> Tab Settings -> Always open popup in new window should be enabled.
Always open popup in new window Because of the setting, the newly opened window runs as a separate process.
The problem is that you should not get the handle value after the window pops up, but I need to know the handle value before Navigate2.
If you provide a basic sample file to fix the problem, we will support $ 500 with PayPal.
CString strUrl = _T("http://www.google.com");
CoInitialize(NULL);
HINSTANCE hInst = ::LoadLibrary(_T("OLEACC.DLL"));
if (hInst != NULL)
{
if (hwnd)
{
CComPtr<IHTMLDocument2> spDoc;
LRESULT lRes;
UINT nMsg = ::RegisterWindowMessage(_T("WM_HTML_GETOBJECT"));
::SendMessageTimeout(hwnd, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes);
HRESULT hr = ::ObjectFromLresult(lRes, IID_IHTMLDocument2, 0, (void**)&spDoc);
if (SUCCEEDED(hr))
{
CComPtr<IHTMLWindow2> spWnd2;
hr = spDoc->get_parentWindow((IHTMLWindow2**)&spWnd2);
if (SUCCEEDED(hr))
{
CComPtr<IServiceProvider> spServiceProv;
hr = spWnd2->QueryInterface(IID_IServiceProvider, (void**)&spServiceProv);
if (SUCCEEDED(hr))
{
IWebBrowser2* pWebBrowser2 = 0;
hr = spServiceProv->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void**)&pWebBrowser2);
if (SUCCEEDED(hr))
{
// Here IWebBrowser2 makes navigate2 as a new tab.
VARIANT vtUrl;
VariantInit(&vtUrl);
vtUrl.vt = VT_BSTR;
vtUrl.bstrVal = strUrl.AllocSysString();
VARIANT vFlags;
V_VT(&vFlags) = VT_I4;
V_I4(&vFlags) = navOpenInNewWindow;
VARIANT vEmpty;
VariantInit(&vEmpty);
pWebBrowser2->Navigate2(&vtUrl, &vFlags, &vEmpty, &vEmpty, &vEmpty);
VariantClear(&vtUrl);
VariantClear(&vFlags);
VariantClear(&vEmpty);
pWebBrowser2->Release();
}
spServiceProv.Release();
}
spWnd2.Release();
}
spDoc.Release();
}
}
::FreeLibrary(hInst);
}
CoUninitialize();
Basically, when you get the handle value of pWebBrowser2, it gets caught as the main handle of the current window, not the new handle's unique handle.
c++ mfc iwebbrowser2
1
You should handle the NewWindow3 event fired then create your own window, or IE will create its own process.
– tunglt
2 days ago
add a comment |
The problem is that I want to get the handle value of the new tab created here.
By default, when you get the handle value of pWebBrowser2, it gets caught as the main handle of the current window, not the new handle's unique handle.
There is one operating condition here. IE Tools -> Internet Options -> General -> Tab Settings -> Always open popup in new window should be enabled.
Always open popup in new window Because of the setting, the newly opened window runs as a separate process.
The problem is that you should not get the handle value after the window pops up, but I need to know the handle value before Navigate2.
If you provide a basic sample file to fix the problem, we will support $ 500 with PayPal.
CString strUrl = _T("http://www.google.com");
CoInitialize(NULL);
HINSTANCE hInst = ::LoadLibrary(_T("OLEACC.DLL"));
if (hInst != NULL)
{
if (hwnd)
{
CComPtr<IHTMLDocument2> spDoc;
LRESULT lRes;
UINT nMsg = ::RegisterWindowMessage(_T("WM_HTML_GETOBJECT"));
::SendMessageTimeout(hwnd, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes);
HRESULT hr = ::ObjectFromLresult(lRes, IID_IHTMLDocument2, 0, (void**)&spDoc);
if (SUCCEEDED(hr))
{
CComPtr<IHTMLWindow2> spWnd2;
hr = spDoc->get_parentWindow((IHTMLWindow2**)&spWnd2);
if (SUCCEEDED(hr))
{
CComPtr<IServiceProvider> spServiceProv;
hr = spWnd2->QueryInterface(IID_IServiceProvider, (void**)&spServiceProv);
if (SUCCEEDED(hr))
{
IWebBrowser2* pWebBrowser2 = 0;
hr = spServiceProv->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void**)&pWebBrowser2);
if (SUCCEEDED(hr))
{
// Here IWebBrowser2 makes navigate2 as a new tab.
VARIANT vtUrl;
VariantInit(&vtUrl);
vtUrl.vt = VT_BSTR;
vtUrl.bstrVal = strUrl.AllocSysString();
VARIANT vFlags;
V_VT(&vFlags) = VT_I4;
V_I4(&vFlags) = navOpenInNewWindow;
VARIANT vEmpty;
VariantInit(&vEmpty);
pWebBrowser2->Navigate2(&vtUrl, &vFlags, &vEmpty, &vEmpty, &vEmpty);
VariantClear(&vtUrl);
VariantClear(&vFlags);
VariantClear(&vEmpty);
pWebBrowser2->Release();
}
spServiceProv.Release();
}
spWnd2.Release();
}
spDoc.Release();
}
}
::FreeLibrary(hInst);
}
CoUninitialize();
Basically, when you get the handle value of pWebBrowser2, it gets caught as the main handle of the current window, not the new handle's unique handle.
c++ mfc iwebbrowser2
The problem is that I want to get the handle value of the new tab created here.
By default, when you get the handle value of pWebBrowser2, it gets caught as the main handle of the current window, not the new handle's unique handle.
There is one operating condition here. IE Tools -> Internet Options -> General -> Tab Settings -> Always open popup in new window should be enabled.
Always open popup in new window Because of the setting, the newly opened window runs as a separate process.
The problem is that you should not get the handle value after the window pops up, but I need to know the handle value before Navigate2.
If you provide a basic sample file to fix the problem, we will support $ 500 with PayPal.
CString strUrl = _T("http://www.google.com");
CoInitialize(NULL);
HINSTANCE hInst = ::LoadLibrary(_T("OLEACC.DLL"));
if (hInst != NULL)
{
if (hwnd)
{
CComPtr<IHTMLDocument2> spDoc;
LRESULT lRes;
UINT nMsg = ::RegisterWindowMessage(_T("WM_HTML_GETOBJECT"));
::SendMessageTimeout(hwnd, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes);
HRESULT hr = ::ObjectFromLresult(lRes, IID_IHTMLDocument2, 0, (void**)&spDoc);
if (SUCCEEDED(hr))
{
CComPtr<IHTMLWindow2> spWnd2;
hr = spDoc->get_parentWindow((IHTMLWindow2**)&spWnd2);
if (SUCCEEDED(hr))
{
CComPtr<IServiceProvider> spServiceProv;
hr = spWnd2->QueryInterface(IID_IServiceProvider, (void**)&spServiceProv);
if (SUCCEEDED(hr))
{
IWebBrowser2* pWebBrowser2 = 0;
hr = spServiceProv->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void**)&pWebBrowser2);
if (SUCCEEDED(hr))
{
// Here IWebBrowser2 makes navigate2 as a new tab.
VARIANT vtUrl;
VariantInit(&vtUrl);
vtUrl.vt = VT_BSTR;
vtUrl.bstrVal = strUrl.AllocSysString();
VARIANT vFlags;
V_VT(&vFlags) = VT_I4;
V_I4(&vFlags) = navOpenInNewWindow;
VARIANT vEmpty;
VariantInit(&vEmpty);
pWebBrowser2->Navigate2(&vtUrl, &vFlags, &vEmpty, &vEmpty, &vEmpty);
VariantClear(&vtUrl);
VariantClear(&vFlags);
VariantClear(&vEmpty);
pWebBrowser2->Release();
}
spServiceProv.Release();
}
spWnd2.Release();
}
spDoc.Release();
}
}
::FreeLibrary(hInst);
}
CoUninitialize();
Basically, when you get the handle value of pWebBrowser2, it gets caught as the main handle of the current window, not the new handle's unique handle.
c++ mfc iwebbrowser2
c++ mfc iwebbrowser2
edited 2 days ago
asked 2 days ago
yyms
64
64
1
You should handle the NewWindow3 event fired then create your own window, or IE will create its own process.
– tunglt
2 days ago
add a comment |
1
You should handle the NewWindow3 event fired then create your own window, or IE will create its own process.
– tunglt
2 days ago
1
1
You should handle the NewWindow3 event fired then create your own window, or IE will create its own process.
– tunglt
2 days ago
You should handle the NewWindow3 event fired then create your own window, or IE will create its own process.
– tunglt
2 days ago
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945624%2fget-the-process-handle-value-of-the-browser-window-that-launches-in-a-new-tab%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945624%2fget-the-process-handle-value-of-the-browser-window-that-launches-in-a-new-tab%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You should handle the NewWindow3 event fired then create your own window, or IE will create its own process.
– tunglt
2 days ago