Use dynamic cast for AfxGetMainFrame() macro

AfxGetMainWnd() returns the active window when no thread window is set