Use dynamic cast for AfxGetMainFrame() macro

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