Solving #2923057 and #2786440 (cmd.exe cannot be minimized to tray)
After some short debugging I found the reason. Some windows are minimized instead of hidden because SW_MINIMIZE needs more time than SW_HIDE and therefore in some cases SW_MINIMIZE is finished after SW_HIDE in the next line.
One solution would be to check the state and do a Sleep(5) until it's minimized (or five seconds are over), but there is a much better solution:
Simply use SW_FORCEMINIMIZE instead of SW_MINIMIZE. If I'm right this also removes the minimize animation, therefore we can remove the SW_HIDE before this line, too.