ShowWindowAsync is not working
Posted on 2010-09-14
I have a VB.net application. This app has one user triggered action which is to open a web site on IE browser. The app will search for all the IE tabs to see if the same web site has been opened. If such a tab is found then refresh that tab with an updated URL (so that it won't create a new tab or window every time). Also if the IE window is minimized, it should restore or maximize the window. I was able to use "Microsoft Internet Control" to find the tab, update the tab with new URL and get the window handle of the tab. For restoring window, I did some search, many people recommend using ShowWindowAsync. I tried that, it did not seem to work. The window would remain minimize. Following is the code snippet.
'openIE is SHDocVw.InternetExplorer
If (Not openIE Is Nothing) Then
openIE.Navigate(url) 'update with new URL
Dim ret As Long
ret = ShowWindowAsync(openIE.HWND, 1) '1 is SW_NORMAL,
ret = ShowWindowAsync(openIE.HWND, 9) '3 is SW_SHOWMAX, 9 is SW_RESTORE
ret = BringWindowToTop(openIE.HWND)
ret = SetForegroundWindow(openIE.HWND)
Catch e As Exception
MsgBox("Exception: " & e.Message)
When I ran this program, there was no error or exception. However, IE would stay minimized. I don't know why this is not working and if there is any way to debug it; or if there is other way to accomplish the same thing; Any help will be appreciated.