changed getWindowPtr to dynamic_cast