Added window procedure and fixed typecast errors
  Also added a message loop