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.

Dani AI

Generated

Summary and practical follow-ups to the thread: wanted a small C++ tool on Windows XP + IE to refresh a page many times; correctly suggested WinAPI messaging and pointed out why posting a message can work where sending one doesn't. That diagnosis is useful, but there are more reliable, maintainable alternatives than trying to force a browser to accept synthetic window messages.

Why PostMessage often “wins” and why it can still fail: SendMessage blocks until the target processes the message, while posting just queues it — which explains timing differences. More important, real keyboard/refresh actions normally come through the OS input subsystem and include focus/context and scan-code information that browsers expect. Sending or posting plain window messages to a top-level handle can be ignored (or delivered to the wrong child control) and becomes fragile across browser versions or multi-process architectures.

Recommended approaches instead of message-hacking:

  • Use browser automation: Internet Explorer exposes a COM automation interface with a Refresh method; modern browsers are best driven via WebDriver/Selenium. Those talk to the browser in a supported way.
  • For simple, local automation, script tools like AutoHotkey/AutoIt reproduce keystrokes more reliably than posting messages.
  • If synthesizing input is required, use OS-level input injection (the documented input APIs) rather than queueing keyboard messages.

Practical cautions: include a conservative delay so pages can load, detect errors and stop if the browser hangs, and respect server rate limits — many games forbid automation and could suspend accounts. Repeated refresh loops will not physically damage hardware but can hog CPU, memory, or bandwidth and destabilize the browser. For learning C++, experiment with the automation APIs first; they are more robust than message-queue hacks and scale far better.

Recommended Answers

All 3 Replies

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,

Tigran

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.