Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[How to] Auto Refresh IE Window from a script


  • Please log in to reply
7 replies to this topic
SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
How to Auto Refresh IE Window from a script ?
http://www.autohotke...pic.php?t=86411

I have this need to keep a stock quote window refreshed (atleast 6 times a minute) and I found a solution with
PostMessage (using SPY++)

Msg = 0x111 and wParam = 41504


You may test it on Internet Explorer with following code:
#F2::
AhkID:=WinExist("A")
WinGetClass,AHKClass, ahk_id %AhkID%
If AHKClass = IEFrame
   PostMessage, 0x111, 41504, 0 , , ahk_id %AhkID%
Return


BeetleTX330
  • Members
  • 32 posts
  • Last active: Aug 23 2010 05:20 AM
  • Joined: 09 Jun 2005
Hi all. This has been driving me crazy. I've recently upgraded to Internet Explorer 7 (in order to support my users who also upgraded). Now I find that the PostMessage function doesn't work anymore! I've driven myself even further crazy by trying to determine the IE7 "Control ID" (the wParam) value for refreshing it's window. It looks to me like IE7 is doing/using something completely different from IE6.

I've been using Winspector Spy (which is how I found the Control ID wparam in IE6 before I found this tip) but instead of finding the WM_COMMAND messages, all I see are WM_USER. I've followed (over and over again) Rajat's SendMessage/PostMessage tutorial to the letter and yet I still can't find a WM_COMMAND message.

What's weird is that I can't find a WM_USER in the list of filters at all. I have tested the detection process with MSPAINT.EXE and NOTEPAD.EXE -- they work perfectly and I'm able to filter and see the WM_COMMANDs. However, IE7 and other apps show WM_USER where I would expect to see WM_COMMAND (and the WM_USER does NOT have the Control ID, etc... info) that I can tell.

I use this code to refresh a lot of IE pages (local weather radar, webmail that normally times me out after 10 minutes, etc...) and now I'm forced to do a simple WinActivate & SendInput {F5} combination -- definitely cave-dweller-type coding. I've tried to understand the COM stuff but it explodes my head.

Does anyone know if (and how) I can work a PostMessage REFRESH command against IE7 like I did with IE6? ...or maybe y'all can help me figure out how to use Winspector Spy correctly to determine this info?
-- Thanks, BeetleTX330

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
Non cave dweller exploding head stuff 8)
COM_Initialize()

pwb:=newIe() 

nav(pwb,"[color=red]http:\\Subsstitute your url here[/color]")

complete(pwb)

loop

{

COM_Invoke(pwb , "Refresh2") ; refresh page and do not use cache

complete(pwb) wait for page load to complete

}





newIe() 

{ 

   pwb := COM_CreateObject("InternetExplorer.Application") 

   COM_Invoke(pwb , "Visible=", "True") ;"False" ;"True" ;uncomment to show 

   Return   pwb   ?   pwb   :   "Error" 

} 

nav(pwb,url)                  ; returns bool 

{ 

   If not pwb is Integer         ;   test to see if we have a valid interface pointer 

      ExitApp                  ;   ExitApp if we dont 

;~    http://msdn.microsoft.com/en-us/library/aa752133(VS.85).aspx 

   navTrustedForActiveX   =   0x0400 

   COM_Invoke(pwb,   "Navigate",   url,   0x0400,   "_self") 

   Return                     ;   return the result(bool) of the complete function 

}    



complete(pwb)                  ;   returns bool for success or failure 

{    

   If not pwb is Integer         ;   test to see if we have a valid interface pointer 

      ExitApp                  ;   ExitApp if we dont 

   loop 80                     ;   sets limit if itenerations to 40 seconds 80*500=40000=40 secs 

   {    

      If (rdy:=COM_Invoke(pwb,"readyState") = 4) 

         Return    1            ;   return success 

      Sleep,500               ;   sleep half second between cycles 

   } 

   Return 0                  ;   lets face it if it got this far it failed 

}
alternatively you can substitute
pwb:=newIe() 

nav(pwb,"[color=red]http:\\Subsstitute your url here[/color]")

complete(pwb)
with
pwb:=getwin("[color=red]title of page already open[/color]")

Never lose.
WIN or LEARN.

BeetleTX330
  • Members
  • 32 posts
  • Last active: Aug 23 2010 05:20 AM
  • Joined: 09 Jun 2005
Aaah Tank, you're a real sweetheart for posting the COM stuff -- I swear that I'll try to figger it out and incorporate it.

However, I'd still very much like to know why I couldn't use Winspector Spy on IE7 like I did on IE6. Anyone wanna chime in on this aspect of my original issue?

I'm pretty irritated at MS for changing stuff just for the 'eff' of it (like: IE6's title bar used to say, "Microsoft Internet Explorer" and now in IE7 it says, "Windows Internet Explorer") -- this torques me off 'cuz some of my older, compiled code that I've already passed out to folks had the old title which now causes the windows to not be recognized. Oh well. :(

So, any ideas on how to figure out a PostMessage WM_Command on IE7 and the other apps that I can't find a WM_Command on? Thanks to all who are so helpful -- it's appreciated by more than just myself. :)
-- Thanks, BeetleTX330

BeetleTX330
  • Members
  • 32 posts
  • Last active: Aug 23 2010 05:20 AM
  • Joined: 09 Jun 2005
Tank, do I need any special files or librarys for this to work?

I've gone through the code you gave me and I'm Not Sure if it's going to work for me (please understand that I'm not a programmer besides BATch programming -- this stuff is very confusing to me). Here's a sample of my code that doesn't work in IE7 but does in IE6:

; ---Auto-Execute------------------------------
#SingleInstance force
#KeyHistory 500
#Persistent
DetectHiddenWindows, On
DetectHiddenText, On
SetTitleMatchMode, 2
SetTitleMatchMode, Slow
SetKeyDelay, 50

; --- SetTimer --------------------------------
SetTimer, 900000TIMER, 900000 ; 15 minutes

; ---------------------------------------------
900000TIMER: ; 15 minutes
; --- RefreshRadar ----------------------------
  IfWinExist, NWS Enhanced Radar Mosaic: South Plains Sector Loop
  {
    PostMessage, 0x111, 41504,,,NWS Enhanced Radar Mosaic: South Plains Sector Loop
  }
Return

I know, it's pretty simple stuff. So, looking at your code, I'm thinking that it MUST have a URL in it -- but I was wanting to refresh webpages by their window text, etc... AFTER I browse to them and I can't figure out how to adjust your code to do that.

Man, this would be SO SIMPLE if I could just figure out how to determine the PostMessage command for refreshing IE7 like I did for IE6. I have a hard time believing that I'm the only one who's struggling with the differences between IE6 and IE7.

Tank, if there's anything you can do for me, I'll appreciate it. I'll also appreciate anyone who can answer my original and still-in-effect question of how to work Winspector Spy to determine the WM_COMMAND for refreshing IE7's webpages. I think I might re-post this as it's own topic instead of at the end of another topic's 25 pages -- I don't think many folks are seeing this.

Thanks to all in advance!
-- Thanks, BeetleTX330

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
Beatle I am sorry i almost never use post message and am really quite ignorant on what command will make it work
I can offer you COM based alternative My examples require you to have downloaded Seans COM library found in my sig. and have it stored in the lib folder within your autohotkey instalation for example c:\program files\autohotkey\lib\COM.ahk
to use COM to refresh a page
COM_Initialize()
pwb:=newIe()
nav(pwb,"http:\\Subsstitute your url here") 
complete(pwb) 
;then to refresh
nav(pwb,"[color=red]refresh[/color]")
complete(pwb)
loop
{
COM_Invoke(pwb , "Refresh2") ; refresh page and do not use cache
complete(pwb) wait for page load to complete
}


newIe()
{
   pwb := COM_CreateObject("InternetExplorer.Application")
   COM_Invoke(pwb , "Visible=", "True") ;"False" ;"True" ;uncomment to show
   Return   pwb   ?   pwb   :   "Error"
}
nav(pwb,url)                  ; returns bool
{
   If not pwb is Integer         ;   test to see if we have a valid interface pointer
      ExitApp                  ;   ExitApp if we dont
;~    http://msdn.microsoft.com/en-us/library/aa752133(VS.85).aspx
   navTrustedForActiveX   =   0x0400
   COM_Invoke(pwb,   "Navigate",   url,   0x0400,   "_self")
   Return                     ;   return the result(bool) of the complete function
}   

complete(pwb)                  ;   returns bool for success or failure
{   
   If not pwb is Integer         ;   test to see if we have a valid interface pointer
      ExitApp                  ;   ExitApp if we dont
   loop 80                     ;   sets limit if itenerations to 40 seconds 80*500=40000=40 secs
   {   
      If (rdy:=COM_Invoke(pwb,"readyState") = 4)
         Return    1            ;   return success
      Sleep,500               ;   sleep half second between cycles
   }
   Return 0                  ;   lets face it if it got this far it failed
}

Never lose.
WIN or LEARN.

BeetleTX330
  • Members
  • 32 posts
  • Last active: Aug 23 2010 05:20 AM
  • Joined: 09 Jun 2005
Wow, you are so cool to keep working with me on this. Hey, no problem that you don't "know-it-all" regarding PostMessage -- at least you're knocking yourself out to COM me out of this mess. I do appreciate it (and I would LOVE to get a handle on COM -- your code, although extremely confusing to me, will help in some way ramp me up in COM, I'm sure).

I won't be able to play with this until at least tomorrow or the weekend but as soon as I do, I'll reply with my progress. Thanks again!

-- Beetle Bailey (TX330)

J
  • Members
  • 1 posts
  • Last active: Jul 28 2009 09:35 PM
  • Joined: 28 Jul 2009
Found this helpful. wparam 28931 was required to make this work correctly under XP, but using a windows spy, wparam 41504 is posted when the user initiates the process not 28931. Is there a reason for this?