Hi, i've had experience making counting programs in the iostream and now i'd like to make something useful to me. I play a web browser-based game called Neopets, and i often refresh 500 times a day there to encounter random events. Eventually, my hand gets tired, so i'd rather make a c++ program that will refresh 500 times for me.

Some things i'm unsure of are...

What header would be required for this task? (i've been using iostream and windows.h)

Would this kind of program damage my computer?

And where could i find tutorials on making such an automated program? Google seems to be not helping.

My computer is windows xp, and i use internet explorer.

So basically, i want to learn how to make a program that will click the refresh button 500 times. Thanks for any help!

I've also had a years of experience programming in flash actionscript, so i'm ready to take on the challenge. I just dont know what codes are needed to do this.

7 Years
Discussion Span
Last Post by Tigran

You could do this using autoit, but you can also do it using C++ and WinApi (windows.h)

So, you start a source file, make the main func etc. Be sure to include windows.h (and maybe also iostream for easy io)

Get the HWND of the browser window using FindWindowEx() (function documentation: http://msdn.microsoft.com/en-us/library/ms633500%28VS.85%29.aspx)
Store that HWND

Start a loop (for or while)
Wait 2 seconds after every loop round so the page has time to reload
Use the function SendMessage() (function documentation: http://msdn.microsoft.com/en-us/library/ms644950%28VS.85%29.aspx) to simulate an F5 message and send that to the browser page.
I think this should make firefox refresh.

Good luck,



Thanks for the guidance Tigran, i managed to make the program. However, i couldnt get the "SendMessage()" to trigger the f5 command, so after hours of scurrying over the internet, i found another way...

PostMessage(hwnd, WM_KEYDOWN ,VK_F5,0);

But i'm still curious, how would you use the SendMessage() to activate f5?

SendMessage(hwnd, WM_KEYDOWN ,VK_F5,0); // this does not seem to work

SendMessage(hwnd, VK_F5 ,0,0); // nor this

I also tried everything else i could find that seems to be related to refreshing such as WM_MDIREFRESHMENU ,VK_BROWSER_REFRESH and APPCOMMAND_BROWSER_REFRESH . Those did not work in SendMessage() .


I think sendMessage doesn't work because sendmessage waits for some return. It waits till the wndproc function has finished handling the message before it returns controll to the application.

Firefox (or some other browser) probably doesn't return any value for that message.
PostMessage doesn't wait for the application to complete, it just adds it to its message queue.

So keep using PostMessage for applications which you don't know how they (exactly) work.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.