Notepad Hijack Framework

A few people have asked about how I was able to make a game in a Notepad window, as seen in Notepad Weekend. I dug out the source code and cleaned it up into a framework of sorts, which I’m posting here in case any of you would find it interesting!

Download notepad_hijack_framework.cpp [3.3 kB]

The code is pretty simple, but will only work on Windows due to the extensive use of the Windows API. It uses FindWindowEx() to find an open Notepad window, SetWindowsHookEx() to set a keyboard hook so that we can catch keyboard events, and SendMessage(WM_SETTEXT) to set the text in the main text box in the Notepad window. If you wanted to launch an instance of Notepad instead of requiring the player to do it, you could presumably use ShellExecute().

2 Comments to Notepad Hijack Framework

  1. Pat's Gravatar Pat
    August 17, 2009 at 9:08 am | Permalink

    Setting keyboard hooks alerts many AV because that used to be the way keyloggers worked.

  2. August 17, 2009 at 4:25 pm | Permalink

    So get a proper AV then.
    Can you please compile this to a lib?