Fixed 16-bit MDI support (based on a patch by Dmitry Timoshkov).