There is fundamently big problem when you see
this[
^] scattered all over the intertubes.
Do yourself a favor. Step back and grad a decent MFC book. Learn the internals of the framework and then come back.
I'd give you the code, but then I am not sure if I am helping you or hurting you. But by reading a book, I am sure you will get a benefit from it.
What you want to do is done through what is called Keyboard Hook.