AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Memory not being released,
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
DataLife



Joined: 27 Apr 2008
Posts: 369

PostPosted: Wed Apr 29, 2009 12:54 pm    Post subject: Memory not being released, Reply with quote

When running my script iexplore.exe continually increases the amount of memory it is using. It appears not to be releasing any memory.

Eventually IE becomes unresponsive. I have seen iexlore.exe use as much as 780 MB with only one tab open.

I suspect the issue is with one of the sections of code below.

My script waits for the web page to load, gets the html source code, looks for strings in the code, does something based on what strings it finds then does it all over again many times.

Also, I have tried it on Vista, Winxp and Windows 2000 with different versions of IE.

Can someone take a look?

thanks
DataLife
Code:
;Gets html source code of current web page
ControlGet, hIESvr, Hwnd,, Internet Explorer_Server1,ahk_class    IEFrame
WinGetClass, class, ahk_id %hIESvr%
if (!hIESvr or class != "Internet Explorer_Server")
 return
COM_CoInitialize()
COM_Error(0)
WM_HTML_GETOBJECT := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
SendMessage, WM_HTML_GETOBJECT,,,, ahk_id %hIESvr%
lResult := ErrorLevel
DllCall("oleacc\ObjectFromLresult", "uint", lResult, "uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "uint*", pDoc)
DocEle:=COM_Invoke(pDoc, "documentElement")
htmlcode:=COM_Invoke(DocEle,"innerHTML")
COM_Release(DocEle)
COM_Release(pDoc)
com_couninitialize()
return


or

Code:
;Waits for the web page to completely load
IEReady(hIESvr = 0)
{
   If Not   hIESvr
   {
      Loop,   50
      {
         ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame
         If   hIESvr
            Break
         Else   Sleep 100
      }
      If Not   hIESvr
         Return   """Internet Explorer_Server"" Not Found."
   }
   Else
   {
      WinGetClass, sClass, ahk_id %hIESvr%
      If Not   sClass == "Internet Explorer_Server"
         Return   "The specified control is not ""Internet Explorer_Server""."
   }

   COM_Init()
   If   DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 1000, "UintP", lResult)
   &&   DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "UintP", pdoc)=0
   &&   pdoc && pweb:=COM_QueryService(pdoc,IID_IWebBrowserApp:="{0002DF05-0000-0000-C000-000000000046}")
      Loop,20
         If   COM_Invoke(pweb, "ReadyState") <> 4
            Break
         Else   Sleep 500
         
         
         
      Loop
       {
        If   COM_Invoke(pweb, "ReadyState") = 4
         Break
                 
        Else
         {
          CountNumberOfSleeps++
          Sleep 500
          If CountNumberOfSleeps > 360 ;360 x 500 = 180 seconds
           {
            TrayTip,Taking to long to load webpage,Will abort waiting,5,17
            CountNumberOfSleeps = 0
            Break
           }
         }
       }
   COM_Release(pdoc)
   COM_Release(pweb)
   COM_Term()
   Return   pweb ? "DONE!" : False
}


_________________
Unless otherwise stated, all code is untested

Check out my scripts.
http://www.autohotkey.net/~DataLife/MyIpChanger/MyIpChanger.ahk
http://www.autohotkey.net/~DataLife/XPSnap.ahk
http://www.autohotkey.net/~DataLife/SavePictureAs.ahk
Back to top
View user's profile Send private message Send e-mail
tank



Joined: 21 Dec 2007
Posts: 3700
Location: Louisville KY USA

PostPosted: Wed Apr 29, 2009 1:47 pm    Post subject: Reply with quote

firstly if i recall correctly from your other post your loading a web page first then using this to get the content
why you are doing this I wont pretend to understand it simply makes no sense
but a couple things seem to come to mind
first you dont need to use run and then aquire the page
there is no need to quite your ie window is there?
i recommend you go with one of the following
OBVIOUSLY you will need to change the feild i have as URL
Code:
COM_CoInitialize()
OnExit,unInit
Loop{
   pweb := COM_CreateObject("InternetExplorer.Application") )
   COM_Invoke(pweb,Visible=1)
   COM_Invoke(pweb,   "Navigate",   URL)
   loop
         If (rdy:=COM_Invoke(pweb,"readyState") = 4)
            break
   MsgBox  % COM_Invoke(pweb,"document.documentElement.outerHTML")
   COM_Invoke(pweb,"quite")
}
unInit:
COM_CoUninitialize()
ExitApp
Return
Code:
COM_CoInitialize()
OnExit,unInit
pweb := COM_CreateObject("InternetExplorer.Application") )
COM_Invoke(pweb,Visible=1)
Loop{
   COM_Invoke(pweb,   "Navigate",   URL)
   loop
         If (rdy:=COM_Invoke(pweb,"readyState") = 4)
            break
   MsgBox  % COM_Invoke(pweb,"document.documentElement.outerHTML")
}
unInit:
COM_CoUninitialize()
ExitApp
Return

_________________

We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Back to top
View user's profile Send private message
DataLife



Joined: 27 Apr 2008
Posts: 369

PostPosted: Wed Apr 29, 2009 2:07 pm    Post subject: Reply with quote

Okay, I will explain how my script works.

My actions
1. I open a webpage, example google news
2. I start my script

My script actions
1. It gets the html source code
2. It looks for strings in the source code
3. If it finds a match it does 1 of 2 things. It clicks on a link or if the link is not there then it refreshes the page. Either way it goes to step 4.
4. Waits for the status bar to say done
5. Starts all over again with step 1 via a loop

It is possible for my script to do those 5 steps 60 times an hour. It appears that something is not releasing the memory.

I don't want my script to exit. Your example has exitapp.
I will continually have different URL's,
I do not want a new tab or IE window to open the web pages.

So in a nut shell here is what is happening.
I let my program get the html source code, base on what is in the source code I let my program click on links, I let my program wait for the statusbar to say done. I let my program do it all over again.

thanks for your help Tank.
DataLife
_________________
Unless otherwise stated, all code is untested

Check out my scripts.
http://www.autohotkey.net/~DataLife/MyIpChanger/MyIpChanger.ahk
http://www.autohotkey.net/~DataLife/XPSnap.ahk
http://www.autohotkey.net/~DataLife/SavePictureAs.ahk
Back to top
View user's profile Send private message Send e-mail
NimArkard



Joined: 22 Apr 2009
Posts: 19

PostPosted: Wed Apr 29, 2009 4:14 pm    Post subject: Reply with quote

I'm still pretty new and haven't had much experience programming is most anything.. but.. just thinking of different things..
When it calls the dll, is there any sort of injection into the iexplore.exe?
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 3700
Location: Louisville KY USA

PostPosted: Wed Apr 29, 2009 4:42 pm    Post subject: Reply with quote

post the entirety of your existing code
or pm it to me
_________________

We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Back to top
View user's profile Send private message
DataLife



Joined: 27 Apr 2008
Posts: 369

PostPosted: Wed Apr 29, 2009 7:07 pm    Post subject: Reply with quote

Here is a very good example.

I run this code and within 5 minutes the memory usage of IE is doubled.

It will find the first link, display a traytip, fileappend something and start over.

The introduction msgbox explains more.

thanks alot

Code:
SetTitleMatchMode,2

MsgBox This script will move the cursor across the screen looking for two links. news.google.com and maps.google.com`nWhen it finds the link, it will click on it, display a traytip, fileappend links.txt then start over again until the program is paused or exited.`n`nPress`nF6 to Start`nF7 to ExitApp`nF8 to Pause`nF9 to Reload`nF10 to view Links.txt`n`nHow to Use-->`n1.  Open Google.com`n2.  Check how much memory IE is using, then press F6.`n3.  Watch the cursor find links.  Wait a minute or two, pause the script with F8 and check how much memory IE is using. For me the memory doubles in less then 5 mintues.`nThe longer I let the program run the more memory IE uses until IE becomes unresponsive due to low memory.`n`n`nNOTE: You may need to adjust StartingXpos, StartingYpos, EndingXpos and EndingYpos so the cursor can find the links.

EndingXpos = 400
EndingYpos = 150
StartingXpos = 10
StartingYpos = 120
MyGoogleUserID = UserID@gmail.com


F6::
Loop
 {
  WinWaitActive,Google
  MouseMove,%StartingXpos%,%StartingYpos%
  Startingxpos := Startingxpos+15
  ControlGetText,var,msctls_statusbar321, a

  if Startingxpos > %EndingXpos%
   {
    StartingXpos = 10
    StartingYpos := Startingypos+7
   }
  if Startingypos > %EndingYpos%
   {
    Send {F5}
    GoSub StatusBarDone
   }
 
  IfInString,Var,http://news.google.com ;example of link found by gettings the text from the statusbar
   {                                                       ;as the cursor hovers over the link
    TrayTip,Found Google News,%A_Space%,5,17
   sleep 2000
   click
   Gosub StatusBarDone
   }
 
  IfInString,Var,http://maps.google.com ;example of link found by gettings the text from the statusbar
   {                                                      ;as the cursor hovers over the link
   TrayTip,Found Google Maps,%A_Space%,5,17
   sleep 2000
   click
   Gosub StatusBarDone
   }
 } 


F7::
ExitApp

F8::
Pause
Return

F9::
Reload

F10::
run notepad.exe Links.txt
Return

StatusBarDone:
StartingXpos = 10
StartingYpos = 120
TrayTip,Waiting for page to load,%a_space%,30,17
TrayTip, % IEReady(),%a_space%,5,17

WinGetText,text,A
IfInString,text,news.google.com                        ;StatusBarDone gets the window text
 FileAppend,Found news.google.com`n,Links.txt

IfInString,text,maps.google.com
 FileAppend,Found maps.google.com`n,Links.txt

Gosub GetHtmlSourceCode
IfInString,HtmlCode,%MyGoogleUserID%                   ;StatusBarDone gets the html source code
 FileAppend,I am signed in to Google`n`n,Links.txt
Else
 FileAppend, I am NOT signed in to Google`n`n,Links.txt
Return


IEReady(hIESvr = 0)
{
   If Not   hIESvr
   {
      Loop,   50
      {
         ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame
         If   hIESvr
            Break
         Else   Sleep 100
      }
      If Not   hIESvr
         Return   """Internet Explorer_Server"" Not Found."
   }
   Else
   {
      WinGetClass, sClass, ahk_id %hIESvr%
      If Not   sClass == "Internet Explorer_Server"
         Return   "The specified control is not ""Internet Explorer_Server""."
   }

   COM_Init()
   If   DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 1000, "UintP", lResult)
   &&   DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "UintP", pdoc)=0
   &&   pdoc && pweb:=COM_QueryService(pdoc,IID_IWebBrowserApp:="{0002DF05-0000-0000-C000-000000000046}")
      Loop,20
         If   COM_Invoke(pweb, "ReadyState") <> 4
            Break
         Else   Sleep 500
      Loop
       {
        If   COM_Invoke(pweb, "ReadyState") = 4
         Break
                 
        Else
         {
          CountNumberOfSleeps++
          Sleep 500
          If CountNumberOfSleeps > 360 ;360 x 500 = 180 seconds
           {
            TrayTip,Taking to long to load webpage,Will abort waiting,5,17
            CountNumberOfSleeps = 0
            Break
           }
         }
       }
   COM_Release(pdoc)
   COM_Release(pweb)
   COM_Term()
   Return   pweb ? "DONE!" : False
}

GetHtmlSourceCode:
ControlGet, hIESvr, Hwnd,, Internet Explorer_Server1,ahk_class    IEFrame
WinGetClass, class, ahk_id %hIESvr%
if (!hIESvr or class != "Internet Explorer_Server")
 return
COM_CoInitialize()
COM_Error(0)
WM_HTML_GETOBJECT := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
SendMessage, WM_HTML_GETOBJECT,,,, ahk_id %hIESvr%
lResult := ErrorLevel
DllCall("oleacc\ObjectFromLresult", "uint", lResult, "uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "uint*", pDoc)
DocEle:=COM_Invoke(pDoc, "documentElement")
htmlcode:=COM_Invoke(DocEle,"innerHTML")
COM_Release(DocEle)
COM_Release(pDoc)
com_couninitialize()
return




_________________
Unless otherwise stated, all code is untested

Check out my scripts.
http://www.autohotkey.net/~DataLife/MyIpChanger/MyIpChanger.ahk
http://www.autohotkey.net/~DataLife/XPSnap.ahk
http://www.autohotkey.net/~DataLife/SavePictureAs.ahk
Back to top
View user's profile Send private message Send e-mail
n-l-i-d
Guest





PostPosted: Wed Apr 29, 2009 8:50 pm    Post subject: Reply with quote

Woah! You have duplicate code all over the place, and init/uninit like a madman, no wonder the memory use Rolling Eyes .
Back to top
DataLife



Joined: 27 Apr 2008
Posts: 369

PostPosted: Wed Apr 29, 2009 9:42 pm    Post subject: Reply with quote

n-l-i-d wrote:
Woah! You have duplicate code all over the place, and init/uninit like a madman, no wonder the memory use Rolling Eyes .
Not sure what your talking about. If you are talking about the functions, I have two functions, one for determining when the web page has finished loading and one to retrieve the Html source code.

Are the functions the duplicate code you are talking about? ?

I pulled these two functions from this forum. I do not know how to combine them to initialize and uninitialize only once.

Can I initialize at the top of my script and uninitialize when the script exits?

DataLife
_________________
Unless otherwise stated, all code is untested

Check out my scripts.
http://www.autohotkey.net/~DataLife/MyIpChanger/MyIpChanger.ahk
http://www.autohotkey.net/~DataLife/XPSnap.ahk
http://www.autohotkey.net/~DataLife/SavePictureAs.ahk
Back to top
View user's profile Send private message Send e-mail
n-l-i-d
Guest





PostPosted: Wed Apr 29, 2009 9:55 pm    Post subject: Reply with quote

You are mixing COM with a very primitive way of detecting links (hover over the browser and read the statusbar?). You already are taking control over the webpage with COM, so all you need to do is use the links collection in COM to get the links of the page and scan for those you are looking for. Clicking on the found links can be done with, you guessed it: click(), or you could simply navigate to the url. Please, please, please take a closer look at the IE and COM tutorials by tank, you can access all elements of the webpage that way.
Back to top
DataLife



Joined: 27 Apr 2008
Posts: 369

PostPosted: Fri May 08, 2009 4:43 am    Post subject: Reply with quote

n-l-i-d wrote:
so all you need to do is use the links collection in COM to get the links of the page and scan for those you are looking for. Clicking on the found links can be done with, you guessed it: click(), or you could simply navigate to the url. Please, please, please take a closer look at the IE and COM tutorials by tank, you can access all elements of the webpage that way.


I have been studying Tanks IE and Com tutorials since your reply. It looks like it is going to take me awhile to figure it out. Obviously, I will have to rewrite most of my script which is much larger then the one I posted here.

In the mean time is there a way to fix the "Out of Memory" error?

I did a google search on IE not releasing memory and came up with tons of results.

Here is one article talking about Java, Dom and releasing dom elements.
http://www.dotvoid.com/2004/09/internet-explorer-eating-memory/
Here is a section from that page
"As I started investigating how IE handles memory when manipulating the DOM using javascript I found out that IE has a garbage collector which does not release memory just because you say so. So what looks like a memory leak might not be one. However, there are other memory problems using DOM in IE."

Here is another section
"What you can do as programmer is to keep track of all your dom references and before leaving for another page, catching the unload event, release all references to dom elements on the page as IE does not release dom nodes referenced by javascript variables when loading another page."

I realize that article is 4 years old, but here is another URL with tons of people with the same problem starting 2007 to May 1, 2009.

Can this be the problem? I know that I am releasing objects right away but do not know if they are Dom elements.

I know nothing about DOM, Com, Java but an trying to learn starting with Tanks tutorial on IE and Com functions.

thanks
DataLife
_________________
Unless otherwise stated, all code is untested

Check out my scripts.
http://www.autohotkey.net/~DataLife/MyIpChanger/MyIpChanger.ahk
http://www.autohotkey.net/~DataLife/XPSnap.ahk
http://www.autohotkey.net/~DataLife/SavePictureAs.ahk
Back to top
View user's profile Send private message Send e-mail
Lexikos



Joined: 17 Oct 2006
Posts: 7295
Location: Australia

PostPosted: Fri May 08, 2009 9:47 am    Post subject: Reply with quote

DataLife wrote:
Can I initialize at the top of my script and uninitialize when the script exits?
Not only can you do so, it is recommended.
Code:
COM_Init()
OnExit, Exiting
return

Exiting:
COM_Term()
ExitApp
It may or may not be necessary to explicitly call COM_Term() when exiting the program, but better safe than sorry.
Back to top
View user's profile Send private message Visit poster's website
tank



Joined: 21 Dec 2007
Posts: 3700
Location: Louisville KY USA

PostPosted: Fri May 08, 2009 1:24 pm    Post subject: Reply with quote

DataLife wrote:
http://www.dotvoid.com/2004/09/internet-explorer-eating-memory/
Here is a section from that page
"As I started investigating how IE handles memory when manipulating the DOM using javascript I found out that IE has a garbage collector which does not release memory just because you say so. So what looks like a memory leak might not be one. However, there are other memory problems using DOM in IE."
One really important point here. Please if you get nothing else i say get this
JAVA is a full featured programing language by Sun Microsystems that can be embeded in a html document
Javascript is a scripting language used in html documents and has absolutely no similarity in how it works with JAVA except for its name
this article has nothing to do with JAVA applets and while it seems mostly accurate about javascript nothing in it talks about JAVA which objects created in a java applet are managed by the JRE(Java Runtime Environment) not IE

Please make sure you know the difference before doing more reserch or you are likely to end up in a black hole of misinformation



EDIT: Sorry its early i had this post confused with another user who is having trouble with a JAVA Applet. your link is perfectly relavent to your post.

Code:
links:=com_invoke(pwb,"document.links")
returns an integer a memory reference that returns a collection and for purposes of working with it is functionally equivilent to the following javascript
Code:
var links=document.links;
both of these return objects
you would call
Code:
com_release(links)
in ahk to clean up the memory for each time you call it
Code:
links:=com_invoke(pwb,"document.links")
however something that returns a property value such as value or inner html does not get released as it is not an object pointer
_________________

We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Back to top
View user's profile Send private message
DataLife



Joined: 27 Apr 2008
Posts: 369

PostPosted: Fri May 08, 2009 11:40 pm    Post subject: Reply with quote

tank wrote:
both of these return objects
you would call
Code:
com_release(links)
in ahk to clean up the memory for each time you call it
Code:
links:=com_invoke(pwb,"document.links")
however something that returns a property value such as value or inner html does not get released as it is not an object pointer


Here is the section of code I am dealing with
Code:
ControlGet, hIESvr, Hwnd,, Internet Explorer_Server1,ahk_class    IEFrame
WinGetClass, class, ahk_id %hIESvr%
if (!hIESvr or class != "Internet Explorer_Server")
 return
COM_Error(0)
WM_HTML_GETOBJECT := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
SendMessage, WM_HTML_GETOBJECT,,,, ahk_id %hIESvr%
lResult := ErrorLevel
DllCall("oleacc\ObjectFromLresult", "uint", lResult, "uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "uint*", pDoc)
DocEle:=COM_Invoke(pDoc, "documentElement")
htmlcode:=COM_Invoke(DocEle,"innerHTML")
COM_Release(DocEle)
COM_Release(pDoc)

return


I am calling COM_Invoke two times.

Code:

DocEle:=COM_Invoke(pDoc, "documentElement")
htmlcode:=COM_Invoke(DocEle,"innerHTML")


If I understood your reply then I do not need to release the second one because it is "innerHTML"
I have 2 COM_Release
COM_Release(DocEle)
and
COM_Release(pDoc)

I have 2 questions.
1. Which release is releasing which one?
2. Am I releasing what I am supposed to be releasing?

thanks sooo much.
I am really trying hard to understand this.

DataLife
_________________
Unless otherwise stated, all code is untested

Check out my scripts.
http://www.autohotkey.net/~DataLife/MyIpChanger/MyIpChanger.ahk
http://www.autohotkey.net/~DataLife/XPSnap.ahk
http://www.autohotkey.net/~DataLife/SavePictureAs.ahk
Back to top
View user's profile Send private message Send e-mail
tank



Joined: 21 Dec 2007
Posts: 3700
Location: Louisville KY USA

PostPosted: Sat May 09, 2009 2:00 pm    Post subject: Reply with quote

DataLife wrote:
If I understood your reply then I do not need to release the second one because it is "innerHTML"
Yes exactly
At this point showing your entire code is about the only way we can drill down further on your issue
_________________

We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Back to top
View user's profile Send private message
DataLife



Joined: 27 Apr 2008
Posts: 369

PostPosted: Sat May 09, 2009 4:44 pm    Post subject: Reply with quote

Here is my entire code, this code causes Out of Memory error and virtual memory is low with Winxp. With Vista I don't get the error but IE becomes unresponsive and I look at IE's memory usage and it has taken up all available memory, as high at 800 mb.

Vista IE memory 27mb start
Vista IE memory 264mb stop in about 10 minutes

Winxp IE memory 57mb start
WinXP IE memory 339mb stop in about 10 minutes

This is only a sample code that demonstrates the issue.

I realize my approach at finding IE links is primitive so I am attempting to learn com functions using your IE and Browser Com Tutorial, but it is going to take me quite awhile. So in the mean time I would like to fix this issue.

Code:

COM_CoInitialize()
SetTitleMatchMode,2
OnExit,ReleaseAll

MsgBox This script will move the cursor across the screen looking for two links. news.google.com and maps.google.com`nWhen it finds the link, it will click on it, display a traytip, fileappend links.txt then start over again until the program is paused or exited.`n`nPress`nF6 to Start`nF7 to ExitApp`nF8 to Pause`nF9 to Reload`nF10 to view Links.txt`n`nHow to Use-->`n1.  Open Google.com`n2.  Check how much memory IE is using, then press F6.`n3.  Watch the cursor find links.  Wait a minute or two, pause the script with F8 and check how much memory IE is using. For me the memory doubles in less then 5 mintues.`nThe longer I let the program run the more memory IE uses until IE becomes unresponsive due to low memory.`n`n`nNOTE: You may need to adjust StartingXpos, StartingYpos, EndingXpos and EndingYpos so the cursor can find the links.

EndingXpos = 400
EndingYpos = 150
StartingXpos = 10
StartingYpos = 120
MyGoogleUserID = UserID@gmail.com


F6::
Loop
 {
  WinWaitActive,Google
  MouseMove,%StartingXpos%,%StartingYpos%
  Startingxpos := Startingxpos+15
  ControlGetText,var,msctls_statusbar321, a

  if Startingxpos > %EndingXpos%
   {
    StartingXpos = 10
    StartingYpos := Startingypos+7
   }
  if Startingypos > %EndingYpos%
   {
    Send {F5}
    GoSub StatusBarDone
   }
 
  IfInString,Var,http://news.google.com ;example of link found by gettings the text from the statusbar
   {                                                       ;as the cursor hovers over the link
    TrayTip,Found Google News,%A_Space%,5,17
   sleep 2000
   click
   Gosub StatusBarDone
   }
 
  IfInString,Var,http://maps.google.com ;example of link found by gettings the text from the statusbar
   {                                                      ;as the cursor hovers over the link
   TrayTip,Found Google Maps,%A_Space%,5,17
   sleep 2000
   click
   Gosub StatusBarDone
   }
 }


F7::
ExitApp

F8::
Pause
Return

F9::
Reload

F10::
run notepad.exe Links.txt
Return

StatusBarDone:
StartingXpos = 10
StartingYpos = 120
TrayTip,Waiting for page to load,%a_space%,30,17
TrayTip, % IEReady(),%a_space%,5,17

WinGetText,text,A
IfInString,text,news.google.com                        ;StatusBarDone gets the window text
 FileAppend,Found news.google.com`n,Links.txt

IfInString,text,maps.google.com
 FileAppend,Found maps.google.com`n,Links.txt

Gosub GetHtmlSourceCode
IfInString,HtmlCode,%MyGoogleUserID%                   ;StatusBarDone gets the html source code
 FileAppend,I am signed in to Google`n`n,Links.txt
Else
 FileAppend, I am NOT signed in to Google`n`n,Links.txt
Return


IEReady(hIESvr = 0)
{
   If Not   hIESvr
   {
      Loop,   50
      {
         ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame
         If   hIESvr
            Break
         Else   Sleep 100
      }
      If Not   hIESvr
         Return   """Internet Explorer_Server"" Not Found."
   }
   Else
   {
      WinGetClass, sClass, ahk_id %hIESvr%
      If Not   sClass == "Internet Explorer_Server"
         Return   "The specified control is not ""Internet Explorer_Server""."
   }


   If   DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 1000, "UintP", lResult)
   &&   DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "UintP", pdoc)=0
   &&   pdoc && pweb:=COM_QueryService(pdoc,IID_IWebBrowserApp:="{0002DF05-0000-0000-C000-000000000046}")
      Loop,20
         If   COM_Invoke(pweb, "ReadyState") <> 4
            Break
         Else   Sleep 500
      Loop
       {
        If   COM_Invoke(pweb, "ReadyState") = 4
         Break
                 
        Else
         {
          CountNumberOfSleeps++
          Sleep 500
          If CountNumberOfSleeps > 360 ;360 x 500 = 180 seconds
           {
            TrayTip,Taking to long to load webpage,Will abort waiting,5,17
            CountNumberOfSleeps = 0
            Break
           }
         }
       }
   COM_Release(pdoc)
   COM_Release(pweb)
   Return   pweb ? "DONE!" : False
}

GetHtmlSourceCode:
ControlGet, hIESvr, Hwnd,, Internet Explorer_Server1,ahk_class    IEFrame
WinGetClass, class, ahk_id %hIESvr%
if (!hIESvr or class != "Internet Explorer_Server")
 return
COM_Error(0)
WM_HTML_GETOBJECT := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
SendMessage, WM_HTML_GETOBJECT,,,, ahk_id %hIESvr%
lResult := ErrorLevel
DllCall("oleacc\ObjectFromLresult", "uint", lResult, "uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "uint*", pDoc)
DocEle:=COM_Invoke(pDoc, "documentElement")
htmlcode:=COM_Invoke(DocEle,"innerHTML")
COM_Release(DocEle)
COM_Release(pDoc)
return

ReleaseAll:
com_couninitialize()
exitapp

thanks alot
DataLife
_________________
Unless otherwise stated, all code is untested

Check out my scripts.
http://www.autohotkey.net/~DataLife/MyIpChanger/MyIpChanger.ahk
http://www.autohotkey.net/~DataLife/XPSnap.ahk
http://www.autohotkey.net/~DataLife/SavePictureAs.ahk
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group