When I hit ESC in a grid that is embedded in a dialog, the dialog exits. What I want is that the grid handles the ESC key. How can I do that?

You should override OnGetDlgCode (add a message map entry for WM_GETDLGCODE) for the CGXGridWnd and return DLGC_WANTALLKEYS.