Forcing internet explorer to refresh
Hi.
I've got the following problem.
I need to force internet explorer window to refresh.
Now I have the hwnd of the window.
What I tried is SendMessage(hwnd,WK_KEYDOWN,116,0)
116=VK code of F5
This didn't help though, sending WM_KEYUP didn't help also.
So what can i do to force IE to refresh?
Thanx in advance
Re: Forcing internet explorer to refresh
if you want to accomplish that using F5 key, simply use the ::SendInput(..) api to send F5 key to IE.
Cheers
Re: Forcing internet explorer to refresh
WM_KEYDOWN, WM_KEYUP, and WM_CHAR are notifications. They are sent to your window AFTER a keystroke occurs. They should not be used to simulate one.
Re: Forcing internet explorer to refresh
keybd_event() also does the job.
Re: Forcing internet explorer to refresh
Quote:
Originally Posted by philkr
keybd_event() also does the job.
true, however if you will read in the MSDN you would see that:
Quote:
Originally Posted by MSDN
Windows NT/2000/XP: This function has been superseded. Use SendInput instead.
;)
Cheers
Re: Forcing internet explorer to refresh
Re: Forcing internet explorer to refresh
There are still some problems.
SendInput doesn't recieve any hwnd parameter, which means it sends keyboard event to active window. What i need to do is send an event to IE from my application. What i tried is to use SetActiveWindow() and SetFocus() with hwnd of IE and then using SendInput. Now this works quite wierdly, it only works when IE is on top of z-order, if it is overlaped by some other window it just won't work.
Re: Forcing internet explorer to refresh
using SentInput(..) force you that the Window will be in focus and active.
if some other window is in focus then the input will be send to that window.
maybe you should consider using the ::SetForegroundWindow(..) api before sending the input.
Cheers
Re: Forcing internet explorer to refresh
Yepp, just did that before reading your post :)
Pops up the IE window to the top of z-order and refreshes it.
Perfect, thanx for help
Re: Forcing internet explorer to refresh
If your program launched this session of internet explorer, you can use the OLE interface to refresh the window, just call IWebBrowser2::Refresh.
And, to create the IE window, you just need to create a COM object with a ProgID="InternetExplorer.Application". It returns an object which accepts the IWebBrowser2 interface.
It it is an explorer's window, you can use the ShellWindows object to get an IWebBrowser2 interface based on the HWND you have.
With that method you don't need to put the window on the foreground.
::SetForegroundWindow don't work always (for example, if the user is currently inputing in a window of another process which is not a child process of your process), and if it don't work, it is very, very bad to send input to the current foreground window.
So, even if you use ::SetForegroundWindow, you must verify that the window is on the foreground, comparing the HWND to GetForegroundWindow.
If this refreshing action can only occur in consequence of a user input into your program, don't assume that the foreground window is owned by your process, because between the user input, and the code execution, since Windows is a preemptive multitasking OS, the user can have selected another window in another process.
In fact, even if you verify that the IE window is the foreground window (using GetForegroundWindow), it is not perfectly safe, because after the call to GetForegroundWindow, the foreground window may change.
So, it is generally better to avoid using SendInput, when possible.
Re: Forcing internet explorer to refresh
Quote:
Originally Posted by golanshahar
true, however if you will read in the MSDN you would see that:
Quote:
Originally Posted by MSDN
Windows NT/2000/XP: This function has been superseded. Use SendInput instead.
;)
Cheers
I don't think it is a good idea to use SendInput, because if you use SendInput, your application will need a different version on Windows 95/98/Me.
And you can't assume that everybody has Windows XP.
In a few years, maybe, but for now compatibility is important.
Just use SendInput if you need features that keybd_event don't provide.
And since keybd_event can be easily implemented using SendInput, i don't think that microsoft will remove this function from the API before a long time.
Re: Forcing internet explorer to refresh
Quote:
Originally Posted by SuperKoko
With that method you don't need to put the window on the foreground.
Well that's what I have to do anyway. My process uploads some files to server waits for respond and then needs to pop up the IE window user has worked with and refersh it, so I need to bring it to foreground anyway.
Quote:
Originally Posted by SuperKoko
So, even if you use ::SetForegroundWindow, you must verify that the window is on the foreground, comparing the HWND to GetForegroundWindow
While uploading there's a "please wait" message window on the top, so I always know It's gonna be topmost, so that kinda solves this one :)
Quote:
Originally Posted by SuperKoko
If your program launched this session of internet explorer, you can use the OLE interface to refresh the window, just call IWebBrowser2::Refresh.
That's a usefull tip, thanx, will try it :)