Disclaimer/Important notice: I sometimes go crazy with my favorite programming tools. I use my imagination to do things and try to forget all the rules that I normally would keep in mind when developing applications. This post is one of those moments when I got loose. So you don’t probably want to take any advices/ideas from this into your development. Consider it only as having fun with programming tools. Forget everything about security, scalability, sanity etc.
3,5 years ago I was bored and I created Minesweeper solver. It was just Windows forms application that launched minesweeper and then started playing it. End result of that was game solved in 1 second in Expert level (but you needed to change the priority to get to that). Okay… now I got crazy idea again. I wanted to test if I could create browser playable minesweeper… but I wanted to use the minesweeper that comes with windows to do that. I didn’t want to create minesweeper itself I just wanted to create “wrapper” that could make it possible to play it using browser. Sounds weird I know! Here’s what I did… I start by telling the plan that I had in my head before starting:
- Start Minesweeper.exe
- Grab picture of the UI
- Place picture in my web form (=imagebutton)
- When user clicks the image then those clicks will be transferred to the actual application
- Go back to phase 2. (and enjoy illusion of playing minesweeper in browser!)
And of course I needed some kind of automatic refresh too so that I could see the fancy explosion effects from minesweeper (since I used minesweeper from Windows Vista).
I started my journey by creating normal ASP.NET project and designed such a lovely user interface:
As you can probably see I used AJAX controls so that my whole web page wouldn’t refresh when I click the image.
Then I started creating logic to handle the minesweeper process, screen captures, clicks, keyboard presses etc. Since I have done few game solvers and other weird tools to play with processes… I was able to get minesweeper screen to my browser pretty easily:
But then I had some difficulties with passing the mouse clicks to the minesweeper. It seems that minesweeper has changed so much since from Windows XP that my old code turned out to be useless… but no worries… I just created a set of new code 🙂 Finally after a lot of tweaking I was able to pass user interface interactivity to the windows application as I wanted. I didn’t make it as good as in my previous solver… I just made it good enough to proof my point. And I did proof my point since I’m able to play minesweeper from browser. Here is the updated windows application that has taken my activity from through browser:
Of course this kind of method could be used with other applications too… consider running Internet Explorer inside your Internet Explorer (or something similar)! That could be fun thing to do… but I’ll leave that to you.
If you think that this story is now over… it’s not 🙂 But I’ll continue this one in another post later. It’s going to be fun too!
Anyways… Happy hacking!