Re-design the cleanup functionality of the tray icon

Instead of the tray icon thread trying to clean itself up, call the
destructor externally and wait until it closed itself.
This ensures all resources are free'ed and no race conditions can cause
invalid access later on.

Suggested by Lord.
Close the thread handle of the tray icon thread.
Cleanup and don't deadlock when the tray icon creation failed.
Add VS2013 support
fix to compile from vs2010.