CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Apr 2005
    Posts
    20

    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

  2. #2
    Join Date
    May 2005
    Posts
    4,954

    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
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  3. #3
    Join Date
    May 2004
    Location
    Michigan, United States
    Posts
    457

    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.
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

  4. #4
    Join Date
    Jul 2005
    Location
    Germany
    Posts
    1,194

    Re: Forcing internet explorer to refresh

    keybd_event() also does the job.
    Please don't forget to rate users who helped you!

  5. #5
    Join Date
    May 2005
    Posts
    4,954

    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
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  6. #6
    Join Date
    Apr 2005
    Posts
    20

    Re: Forcing internet explorer to refresh

    Thanx for the info.

  7. #7
    Join Date
    Apr 2005
    Posts
    20

    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.

  8. #8
    Join Date
    May 2005
    Posts
    4,954

    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
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  9. #9
    Join Date
    Apr 2005
    Posts
    20

    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

  10. #10
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    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.
    Last edited by SuperKoko; July 26th, 2005 at 01:09 PM.

  11. #11
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    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.

  12. #12
    Join Date
    Apr 2005
    Posts
    20

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured