Cosmetic: Refactor CPolygon::GetLONG for clarity.

Fixes #966539.
Avoid possible null dereferences.

Fixes CID 965991, 965992.
Remove some useless null checks.

Fixes CID 966174.
Add asserts for normally unattainable default in switch.

Fixes CID 965933, 965939, 965947, 965948.
Cosmetics: Use CheckPointer.
Use UINT_MAX/DWORD_MAX/DWORD_ERROR when it makes sense to do so.
Use conversion constructors to work-around confusing AStyle styling.
Fix a crash when using the options dialog opened from the command-line.

347e8bb4919e5257897edc70ab29ef98563a0687 forgot to add the needed null-check to filter out the cases where the active window was returned.
MainFrm: Remove outdated UNREFERENCED_PARAMETER()
MainFrm: detect popup menu hiding more correctly

It generated false detection on ui preset change
MainFrm: reorder OnFilePostOpenmedia()

Fixes #3753