In this below code, hWnd
is the "URL Handle" in Spy++:
'WorkerW -> ReBarWindow32 -> Address Band Root -> Edit'
The URL is what I want to open.
I use the same method to open tabs in IE7 and send hWnd
appropriately. I see that this works fine for IE7 and not for IE8. In IE8, it only opens 4 tabs and then IE8 stops honoring the SendMessage request; however, I can still press CTRL+T
OR ALT+Enter
to open new tabs in IE8 (so IE8 is still responsive).
/**
* Open URL in IE (open new tab when newTab is true)
* hWnd is found at runtime
**/
private void LaunchURLinIE(IntPtr hWnd, String url, bool newTab = false)
{
StringBuilder ob = new StringBuilder(url);
// Type text in the URL window
SendMessage(hWnd, WM_SETTEXT, 0, ob);
if (!newTab)
{ // Press Enter
SendMessage(hWnd, WM_KEYDOWN, VK_RETURN, 1);
}
else
{ // Press ALT Enter to open new tab
SendMessage(hWnd, WM_SYSKEYDOWN, VK_RETURN, 1 << 29);
}
}
My environment is: Windows XP Service Pack 3 [32-bit OS] , IE8 version 8.0.6001.18702
So, is it IE8 or something I am missing?
UPDATE - 1 I have updated comments on the code so that its clear what code does. The above code works perfectly fine for IE7 (tested upto 15 tabs) but with IE8 it only opens upto 4 tabs.
Update - 2 I was able to sove this by using PostMessage instead of SendMessage.
private void LaunchURLinIE(IntPtr hWnd, String url, bool newTab = false) { StringBuilder ob = new StringBuilder(url); // Type text in the URL window SendMessage(hWnd, WM_SETTEXT, 0, ob); if (!newTab) { // Press Enter PostMessage(hWnd, WM_KEYDOWN, VK_RETURN, 1); } else { // Press ALT Enter to open new tab PostMessage(hWnd, WM_SYSKEYDOWN, VK_RETURN, 1
hWnd
is not a fixed value, right? You can't just get it one time using Spy++ and use it from then on. Every time the application is closed and re-opened (or the control's handle is re-created), the value will change. – Cody Gray